Editor——(AddChild、AddParent)

using UnityEngine;
using System.Collections;
using UnityEditor;

public class EditorApplication : ScriptableObject
{
	[MenuItem("GameObject/Add Child")]
	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;
			newChild.transform.localPosition=Vector3.zero;
		}
	}

	[MenuItem("GameObject/AddParent")]
	static void MenuAddParent()
	{
		Transform[] transforms=Selection.GetTransforms(SelectionMode.TopLevel | SelectionMode.OnlyUserModifiable);

		GameObject newParent = new GameObject ("_Parent");
		Transform newParentTransform = newParent.transform;

		if (transforms.Length==1) 
		{
			Transform originalParent=transforms[0].parent;
			transforms[0].parent=newParentTransform;
			if (originalParent)
			{
				newParentTransform.parent=originalParent;
			}
			else
			{
				foreach (Transform transform in transforms)
				{
					transform.parent=newParentTransform;
				}
			}
		}
	}
}

你可能感兴趣的:(Unity,Editor)