Last active
July 5, 2018 09:59
-
-
Save mminer/3759189 to your computer and use it in GitHub Desktop.
Unity editor script that provides a shortcut to move the selected game object to the origin (0, 0, 0).
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; | |
| class MoveToOrigin | |
| { | |
| /// <summary> | |
| /// Moves selected game object(s) to (0, 0, 0). | |
| /// <summary> | |
| /// <remarks>Keyboard shortcut: shift-cmd-0 (Mac), shift-ctrl-0 (Windows).</remarks> | |
| [MenuItem ("GameObject/Move To Origin #%0")] | |
| static void MenuMoveToOrigin () | |
| { | |
| foreach (var t in Selection.transforms) { | |
| Undo.RecordObject(t, "Move " + t.name); | |
| t.position = Vector3.zero; | |
| Debug.Log("Moving " + t.name + " to origin."); | |
| } | |
| } | |
| /// <summary> | |
| /// Validates "Move To Origin" menu item. | |
| /// </summary> | |
| /// <remarks>The menu item will be disabled if no transform is selected.</remarks> | |
| [MenuItem ("GameObject/Move To Origin %0", true)] | |
| static bool ValidateMoveToOrigin () | |
| { | |
| return Selection.activeTransform != null; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment