I’ve adapted an example Editor script to create an empty game object childed under the currently selected object. It works great but every time I use it I have to manually select the new object to rename it. It seems like there should be an automatic way to do this - so I can just start typing the name after I hit the hotkey to run the script.
// JavaScript example:
// Add menu named "Do Something" to the main menu
@MenuItem ("GameObject/Empty Child")
static function DoSomething ()
{
//Debug.Log ("Perform operation");
var empty = GameObject();
empty.transform.parent = Selection.activeTransform;
empty.transform.localPosition = Vector3.zero;
empty.transform.localRotation = Quaternion.identity;
empty.name = "_";
Selection.activeTransform = empty.transform;
}
// Validate the menu item.
// The item will be disabled if no transform is selected.
@MenuItem ("GameObject/Empty Child", true)
static function ValidateDoSomething () {
return Selection.activeTransform != null;
}