Selection
Selection是编辑器类,需要放在在Assets/Editor目录下。
SelectionMode
(摘自:https://docs.unity3d.com/412/Documentation/ScriptReference/SelectionMode.html)
[MenuItem("Assets/SelectionMode/SelectionMode.Unfiltered")]
public static void SelectUnfiltered()
{
UnityEngine.Object[] arr = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.Unfiltered);
for (int index = 0; index < arr.Length; index++)
{
string filePath = AssetDatabase.GetAssetPath(arr[index]);
Debug.Log("filePath=" + filePath);
}
}
对该目录做操作:
- SelectionMode.Unfiltered
执行后打印:
获得整个选中的对象的路径。但是不遍历。
当选中多个物体(文件夹或者预制件)的时候,打印如下:
- SelectionMode.TopLevel
当选中一个:跟SelectionMode.Unfiltered结果一致
当一次选中多个:跟SelectionMode.Unfiltered结果一致 - SelectionMode.Deep
-能返回所有包括文件夹和预制件的集合 - SelectionMode.ExcludePrefab
选中文件夹和预制件
打印结果是:
忽略了预制件项! - SelectionMode.Editable
This will filter generated prefabs from an imported fbx file but not user created prefabs. - SelectionMode.Assets
- SelectionMode.DeepAssets
收集所有包括文件夹,Assets,子文件夹。
Selection.GetFiltered
static function GetFiltered (type : Type, mode : SelectionMode) : Object[]
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.
如果Type是Component或者GameObject的子类,全部selectionMode都可以支持;
否则SelectionMode.ExcludePrefab and SelectionMode.Editable 类型才支持;
默认是:SelectionMode.TopLevel | SelectionMode.ExcludePrefab | SelectionMode.Editable.