Created
January 25, 2019 09:57
-
-
Save Wanderer13/0a83fb1f97bde2956e5b8e98de9f3814 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
using UnityEditor.SceneManagement; | |
using System.Collections.Generic; | |
using IsoTools; | |
namespace Assets.Editor | |
{ | |
[InitializeOnLoad] | |
public static class ClearIsoObjectTransformsAction | |
{ | |
static ClearIsoObjectTransformsAction() | |
{ | |
EditorSceneManager.sceneSaving += OnSceneSaving; | |
EditorSceneManager.sceneSaved += OnSceneSaved; | |
} | |
private static List<IsoObjWithPos> _isoObjectsWithPos; | |
static void OnSceneSaving(UnityEngine.SceneManagement.Scene scene, string path) | |
{ | |
var isoObjects = Object.FindObjectsOfType<IsoObject>(); | |
_isoObjectsWithPos = new List<IsoObjWithPos>(); | |
foreach (var isoObj in isoObjects) | |
{ | |
var localPos = isoObj.transform.localPosition; | |
_isoObjectsWithPos.Add(new IsoObjWithPos { Transform = isoObj.transform, LocalPos = localPos }); | |
isoObj.transform.localPosition = new Vector3(localPos.x, localPos.y, 0f); | |
} | |
} | |
static void OnSceneSaved(UnityEngine.SceneManagement.Scene scene) | |
{ | |
if (_isoObjectsWithPos == null) | |
{ | |
return; | |
} | |
foreach (var objWithPos in _isoObjectsWithPos) | |
{ | |
objWithPos.Transform.localPosition = objWithPos.LocalPos; | |
} | |
} | |
private class IsoObjWithPos | |
{ | |
public Transform Transform; | |
public Vector3 LocalPos; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment