Selection.GetTransforms

Unity · Версия 2020.3 LTS · Scripting · Selection

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;
    }
}

Обновлено 17 ноября 2026 г.