Skip to content

Instantly share code, notes, and snippets.

@randalfien
Last active October 1, 2020 17:08
Show Gist options
  • Save randalfien/4666f3dc3c3701449c23e823b99cf534 to your computer and use it in GitHub Desktop.
Save randalfien/4666f3dc3c3701449c23e823b99cf534 to your computer and use it in GitHub Desktop.
Unity MegaSnap
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