Manual     Reference     Scripting  
  
Scripting > Editor Classes > Selection   
  • Menu
  • Overview
  • Runtime Classes
  • Attributes
  • Enumerations
  • Editor Classes
  • Enumerations
  • History
  • Index
  • Selection
  • All Members
  • Class Variables
  • activeGameObject
  • activeInstanceID
  • activeObject
  • activeTransform
  • gameObjects
  • instanceIDs
  • objects
  • transforms
  • Class Functions
  • Contains
  • GetFiltered
  • GetTransforms

Selection.GetFiltered  

static function GetFiltered (type : Type, mode : SelectionMode) : Object[]

Description

Returns the current selection filtered by type and mode.

For a selected GameObject that has multiple Components of type, only the first one will be included in the results.
if type is a subclass of Component or GameObject the full SelectionMode is supported.
if type does not subclass from Component or GameObject (eg. Mesh or ScriptableObject) only SelectionMode.ExcludePrefab and SelectionMode.Editable are supported.

// MenuItem adds a menu item in the GameObject menu
// and executes the following function when clicked
@MenuItem ("GameObject/Apply values")
static function ApplyHardcodedValues ()
{
// Get all selected game objects that we are allowed to modify!
var gos = Selection.GetFiltered(GameObject, SelectionMode.Editable);
// Change the values of all
for (var go in gos)
{
// Change the layer of the game object to 2
go.layer = 2;
}


// Get all selected rigid bodies that we are allowed to modify!
var bodies = Selection.GetFiltered(Rigidbody, SelectionMode.Editable);
// Change the values of all
for (var body in bodies)
{
// Change the layer of the game object to 2
body.mass = 5;
}
}