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暂时无方法

posted @ 2017-02-14 18:01  露夕逝  阅读(880)  评论(0编辑  收藏  举报