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.

适用于一个具有多重的类型组件的游戏物体,结果只有第一个将会被包括。
如果类型是Component和GameObject的子级,全选择模式是被支持的。
如果类型不是Component和GameObject(例如:Mesh或者ScriptableObject)的子级,只有SelectionMode.ExcludePrefab和SelectionMode.Editable是被支持的。

// C# Example
// Menu Item that lets you mark a selection of Objects enabled or
// disabled recursively.
// 菜单项目可以让你递归地标记一个激活的或者非激活物体的选择

using UnityEngine;
using UnityEditor;

public class ToggleActiveRecursively : ScriptableObject {
	[MenuItem ("Example/Toggle Active Recursively of Selected %i")]
	static void DoToggle() {
		Object[] activeGOs =
			Selection.GetFiltered(
				typeof(GameObject),
				SelectionMode.Editable | SelectionMode.TopLevel);

		foreach (GameObject activeGO in activeGOs)
			activeGO.SetActiveRecursively(!activeGO.active);
	}
}
Page last updated: 2011-4-11