首页 > 编程语言 > 详细

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

时间:2017-02-14 19:03:17      阅读:495      评论:0      收藏:0      [点我收藏+]

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

技术分享

代码如下:

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

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

原文:http://www.cnblogs.com/luxishi/p/6398769.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!