Version: 2020.1

Selection.GetTransforms

切换到手册
public static Transform[] GetTransforms (SelectionMode mode);

参数

mode 用于调整选择的选项。

描述

允许使用 SelectionMode 位掩码对选择类型进行精细控制。

using UnityEngine;
using UnityEditor;

class CreateParentForTransforms : ScriptableObject { [MenuItem("Example/Create Parent For Selection _p")] static void MenuInsertParent() { Transform[] selection = Selection.GetTransforms( SelectionMode.TopLevel | SelectionMode.Editable); 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; } }