GetTransforms(SelectionMode)
Retrieves the transforms of selected objects.
Read time 1 minuteLast updated 7 days ago
Definition
- Type: Method
- Namespace: UnityEditor
- Assembly: UnityEditor
public static Transform[] GetTransforms(SelectionMode mode)
Parameters
Options for refining the selection. Refer to SelectionMode for the available modes.
Returns
Type | Description |
|---|---|
| Transform[] | The transforms of the selected objects determined by the |
Remarks
Retrieves the transform of the current Editor selection after applying the provided SelectionMode flags. You can use this to iterate through relevant scene objects (such as editable transforms) and perform batch operations on them.
Examples
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; }}