定制 Project 内的特定资源 的 Inspector面板显示

来源:互联网 发布:java acl访问控制列表 编辑:程序博客网 时间:2024/06/05 20:07

孙广东  2015.11.8

之前 定制过 Project面板 和 Hierarchy 面板了。   都是为了更好的标记 和查找对象。


现在 想定制一下  Inspector,  这个定制 不是说对脚本组件的字段等的定制。  而是对Project 内的特定资源的 定制。


using UnityEngine;using System.Collections;using System.IO;using UnityEditor;// 注: 音频、贴图、材质、预制体、模型、脚本、特殊不识别的资源等都不是 DefaultAsset[CustomEditor(typeof(UnityEditor.DefaultAsset))]public class CustomInspector : Editor{    private static string prePath = string.Empty;// 1、如果是场景就显示  场景的所有引用。// 2、如果是文件夹,就显示 文件夹下的所有文件和子目录public override void OnInspectorGUI (){string path = AssetDatabase.GetAssetPath(target);        // 1        GUI.enabled = true;if(path.EndsWith(".unity")){GUILayout.Label("场景的所有引用:");            var depends = AssetDatabase.GetDependencies(new[] { path });    for (int i = 0; i < depends.Length; i++)    {                GUILayout.Label(i + "、" + depends[i]);            }            prePath = path;        }// 2else if(path.EndsWith("")){; GUILayout.Label("文件夹下的所有内容:");    var filePaths = Directory.GetFiles(path, "*", SearchOption.AllDirectories);    for (int j = 0; j < filePaths.Length; j++)    {        if (!filePaths[j].EndsWith(".meta"))        {                    GUILayout.Label(j + "、" + filePaths[j]);                }            }}}}


结果:







2 0