Unity Selection编辑器类

2021-01-19  本文已影响0人  _灯下影子

Selection

Selection是编辑器类,需要放在在Assets/Editor目录下。

SelectionMode

SelectionMode

//编辑器方法

[MenuItem("Assets/SelectionMode/SelectionMode.TopLevel")]
        public static void SelectUnfiltered()
        {
            UnityEngine.Object[] arr = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.TopLevel);
            for (int index = 0; index < arr.Length; index++)
            {
                string filePath = AssetDatabase.GetAssetPath(arr[index]);
                Debug.Log("FilePath" + filePath);
            }
        }

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.

上一篇下一篇

猜你喜欢

热点阅读