• Unity3D研究院编辑器之自定义默认资源的Inspector面板


    比如编辑模式下对场景或者特定文件夹有一些操作可以在这个面板里来完成。

    代码如下:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEditor;
    
    [CustomEditor(typeof(UnityEditor.DefaultAsset))]
    //[CustomEditor(typeof(UnityEditor.SceneAsset))]
    public class CustomInspector : Editor {
        public override void OnInspectorGUI()
        {
            string path = AssetDatabase.GetAssetPath(target);
            GUI.enabled = true;
            Debug.Log(path);
            if (path.EndsWith(".txt"))
            {
                GUILayout.Button("我是文档");
            }
            else if (path.EndsWith(".abc"))
            {
                GUILayout.Button("我是abc");
            }
            else if (path.EndsWith(".unity"))
            {
                GUILayout.Button("我是场景");
            }
            else if(path.EndsWith(""))//文件夹要放到最后,因为所有的结尾均为空
            {
                GUILayout.Button("我是文件夹");
            }
        }
    }

    识别场景:[CustomEditor(typeof(UnityEditor.SceneAsset))]

    识别文件夹和一些unity不支持的文件类型:[CustomEditor(typeof(UnityEditor.DefaultAsset))]

    识别图片,txt暂时无方法

  • 相关阅读:
    C++(封装一)
    数据结构之链式栈(二)
    C++(函数重载二)
    不计算阶乘获得结果末尾0的个数
    附加产品
    刘子闻讲的高精度【太强了】
    字符串相关函数
    回文素数
    蛇形填数
    筛法模版
  • 原文地址:https://www.cnblogs.com/luxishi/p/6398769.html
Copyright © 2020-2023  润新知