Last active
October 1, 2020 17:08
-
-
Save randalfien/4666f3dc3c3701449c23e823b99cf534 to your computer and use it in GitHub Desktop.
Unity MegaSnap
This file contains hidden or 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 UnityEditor; | |
using UnityEngine; | |
using UnityEngine.SceneManagement; | |
public class SnapUtils | |
{ | |
[MenuItem("Tools/Megasnap")] | |
private static void Snap() | |
{ | |
GameObject[] rootObjects = SceneManager.GetSceneAt(0).GetRootGameObjects(); | |
foreach (GameObject rootObject in rootObjects) | |
{ | |
Snap(rootObject.transform); | |
} | |
} | |
private static void Snap(Transform t) | |
{ | |
t.localPosition = new Vector3( | |
Mathf.Round(t.localPosition.x), | |
Mathf.Round(t.localPosition.y), | |
Mathf.Round(t.localPosition.z) | |
); | |
for(int i = 0; i < t.childCount; i++) | |
{ | |
Snap(t.GetChild(i)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment