GetFiltered
Returns the current selection filtered by type and mode.
Read time 1 minuteLast updated 7 days ago
Definition
- Type: Method
- Namespace: UnityEditor
- Assembly: UnityEditor.CoreModule
GetFiltered<T>(SelectionMode)
Returns the current selection filtered by type and mode.
public static T[] GetFiltered<T>(SelectionMode mode)
Parameters
Further options to refine the selection.
Returns
Type | Description |
|---|---|
| <T>[] |
Remarks
For a selected GameObject that has multiple Components of , only the first one will be included in the results.
typeIf does not subclass from Component or GameObject (eg. Mesh or ScriptableObject) only SelectionMode.ExcludePrefab and SelectionMode.Editable are supported.
typeExamples
using UnityEngine;using UnityEditor;class ToggleActive : ScriptableObject{ [MenuItem("Example/Toggle Active of Selected %i")] static void DoToggle() { Object[] activeGOs = Selection.GetFiltered( typeof(GameObject), SelectionMode.Editable | SelectionMode.TopLevel); foreach (GameObject obj in activeGOs) { obj.SetActive(!obj.activeSelf); } }}
GetFiltered(Type, SelectionMode)
Returns the current selection filtered by type and mode.
public static Object[] GetFiltered(Type type, SelectionMode mode)
Parameters
Only objects of this type will be retrieved.
Further options to refine the selection.
Returns
Type | Description |
|---|---|
| Object[] |
Remarks
For a selected GameObject that has multiple Components of , only the first one will be included in the results.
typeIf does not subclass from Component or GameObject (eg. Mesh or ScriptableObject) only SelectionMode.ExcludePrefab and SelectionMode.Editable are supported.
typeExamples
using UnityEngine;using UnityEditor;class ToggleActive : ScriptableObject{ [MenuItem("Example/Toggle Active of Selected %i")] static void DoToggle() { Object[] activeGOs = Selection.GetFiltered( typeof(GameObject), SelectionMode.Editable | SelectionMode.TopLevel); foreach (GameObject obj in activeGOs) { obj.SetActive(!obj.activeSelf); } }}