Selection.GetTransforms 获取变换列表

static function GetTransforms (mode : SelectionMode) : Transform[]


Allows for fine grained control of the selection type using the SelectionMode bitmask.


// C# Example
// Creates a new parent for the selected transforms
// 为选择的变换创建一个新的父级

using UnityEngine;
using UnityEditor;

public class CreateParentForTransforms : ScriptableObject {
	[MenuItem ("Example/Create Parent For Selection _p")]
	static void MenuInsertParent() {
		Transform[] selection = Selection.GetTransforms(
		SelectionMode.TopLevel | SelectionMode.OnlyUserModifiable);
		GameObject newParent = new GameObject("Parent");

		foreach(Transform t in selection)
			t.parent = newParent.transform;
	// Disable the menu if there is nothing selected
	// 如果什么都没有选择将禁用菜单功能
	[MenuItem ("Example/Create Parent For Selection _p", true)]
	static bool ValidateSelection() {
		return Selection.activeGameObject != null;
Page last updated: 2011-4-11