0
点赞
收藏
分享

微信扫一扫

Unity Selection编辑器类

Gaaidou 2021-10-15 阅读 133
Unity

Selection

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

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);
            }
        }
  • SelectionMode.Unfiltered
    选中一个:返回选中的一个路径;
    选中多个:返回选中的多个路径。
  • SelectionMode.TopLevel
    当选中一个:跟SelectionMode.Unfiltered结果一致;
    当一次选中多个:返回第一个选中的一个路径。
  • SelectionMode.Deep
    返回所有包括文件夹和预制件的集合
  • SelectionMode.ExcludePrefab
    返回忽略预制件项
  • SelectionMode.Editable
    将从导入的fbx文件中过滤生成的预制件,而不是用户创建的预制件
  • 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.

举报

相关推荐

0 条评论