AddChild

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(Removing all content from page)
m (Reverted edits by Joseph05408 (Talk); changed back to last version by NCarter)
Line 1: Line 1:
 +
Author: Neil Carter ([[:User:NCarter|NCarter]])
  
 +
== Description ==
 +
 +
Adds an empty GameObject as a child of each selected object.  This may sometimes be preferable to the built-in '''GameObject→Create Empty''' command, as it saves you from having to hunt in the hierarchy for the newly created object.
 +
 +
== Usage ==
 +
 +
You must place the script in a folder named '''Editor''' in your project's Assets folder for it to work properly.
 +
 +
Select some objects in the Scene view or Hierarchy window, then choose '''GameObject→Add Child''' from the menu (or press control N).  Each selected object will have a new child object added to it.
 +
 +
The newly created child objects are named '''_Child''' to make them sort towards the top of the Hierarchy list.
 +
 +
== C# - AddChild.cs ==
 +
 +
<csharp>using UnityEngine;
 +
using UnityEditor;
 +
using System.Collections;
 +
 +
public class AddChild : ScriptableObject
 +
{
 +
    [MenuItem ("GameObject/Add Child ^n")]
 +
    static void MenuAddChild()
 +
    {
 +
        Transform[] transforms = Selection.GetTransforms(SelectionMode.TopLevel | SelectionMode.OnlyUserModifiable);
 +
 +
        foreach(Transform transform in transforms)
 +
        {
 +
            GameObject newChild = new GameObject("_Child");
 +
            newChild.transform.parent = transform;
 +
        }
 +
    }
 +
}
 +
</csharp>
 +
 +
[[Category:Editor Scripts]]
 +
[[Category:ScriptableObject]]
 +
[[Category:C Sharp]]

Revision as of 19:29, 19 October 2009

Author: Neil Carter (NCarter)

Description

Adds an empty GameObject as a child of each selected object. This may sometimes be preferable to the built-in GameObject→Create Empty command, as it saves you from having to hunt in the hierarchy for the newly created object.

Usage

You must place the script in a folder named Editor in your project's Assets folder for it to work properly.

Select some objects in the Scene view or Hierarchy window, then choose GameObject→Add Child from the menu (or press control N). Each selected object will have a new child object added to it.

The newly created child objects are named _Child to make them sort towards the top of the Hierarchy list.

C# - AddChild.cs

<csharp>using UnityEngine; using UnityEditor; using System.Collections;

public class AddChild : ScriptableObject {

   [MenuItem ("GameObject/Add Child ^n")]
   static void MenuAddChild()
   {
       Transform[] transforms = Selection.GetTransforms(SelectionMode.TopLevel | SelectionMode.OnlyUserModifiable);
       foreach(Transform transform in transforms)
       {
           GameObject newChild = new GameObject("_Child");
           newChild.transform.parent = transform;
       }
   }

} </csharp>

Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox