孙广东 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;
}
// 2
else 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]);
}
}
}
}
}结果:
版权声明:本文为博主原创文章,未经博主允许不得转载。出自 游戏开发实验室_孙广东
定制 Project 内的特定资源 的 Inspector面板显示
原文:http://blog.csdn.net/u010019717/article/details/49721849