MoveToOrigin

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
m (Added email address beside author.)
(C# - MoveToOrigin.cs)
 
(2 intermediate revisions by one user not shown)
Line 11: Line 11:
 
== C# - MoveToOrigin.cs ==
 
== C# - MoveToOrigin.cs ==
  
<csharp>
+
<syntaxhighlight lang="csharp">
 
using UnityEditor;
 
using UnityEditor;
 
using UnityEngine;
 
using UnityEngine;
Line 24: Line 24:
 
// Move each selected transform to (0, 0, 0)
 
// Move each selected transform to (0, 0, 0)
 
foreach (Transform t in Selection.transforms) {
 
foreach (Transform t in Selection.transforms) {
Undo.RegisterUndo(t, "Move " + t.name);
+
Undo.RecordObject(t, "Move " + t.name);
 
t.position = Vector3.zero;
 
t.position = Vector3.zero;
 
Debug.Log("Moving " + t.name + " to origin");
 
Debug.Log("Moving " + t.name + " to origin");
Line 39: Line 39:
 
}
 
}
 
}
 
}
</csharp>
+
</syntaxhighlight>
  
 
[[Category:Editor Scripts]]
 
[[Category:Editor Scripts]]
 
[[Category:ScriptableObject]]
 
[[Category:ScriptableObject]]
 
[[Category:C Sharp]]
 
[[Category:C Sharp]]

Latest revision as of 23:55, 18 January 2014

Author: Matthew Miner (matthew@matthewminer.com)

[edit] Description

Moves the selected GameObject(s) to (0, 0, 0).

[edit] Usage

Place the script inside the Editor folder. Select one or more GameObjects and choose GameObject > Move To Origin or press cmd-0 (Mac) / ctrl-0 (Windows). This is functionally equivalent to invoking Reset on a GameObject's transform.

[edit] C# - MoveToOrigin.cs

using UnityEditor;
using UnityEngine;
 
class MoveToOrigin {
	/// <summary>
	/// Moves the selected game object(s) to (0, 0, 0).
	/// <summary>
	/// <remarks>Keyboard shortcut: cmd-0 (Mac), ctrl-0 (Windows).</remarks>
	[MenuItem ("GameObject/Move To Origin %0")]
	static void MenuMoveToOrigin () {
		// Move each selected transform to (0, 0, 0)
		foreach (Transform t in Selection.transforms) {
			Undo.RecordObject(t, "Move " + t.name);
			t.position = Vector3.zero;
			Debug.Log("Moving " + t.name + " to origin");
		}
    }
 
	/// <summary>
	/// Validates the "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;
	}
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox