美文网首页
Unity Selection编辑器类

Unity Selection编辑器类

作者: _灯下影子 | 来源:发表于2021-01-19 22:53 被阅读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);
            }
        }
  • 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.

相关文章

网友评论

      本文标题:Unity Selection编辑器类

      本文链接:https://www.haomeiwen.com/subject/hoiczktx.html