布局的扩展分为Game场景文件下 和 Project文件下的两种扩展:
Hierachy下:
代码:
/// <summary>
/// 扩展布局 --Hierachy视图下
/// </summary>
[InitializeOnLoadMethod] //编辑器模式下初始化执行标签
static void InitializeOnLoadMethod2()
{
EditorApplication.hierarchyWindowItemOnGUI = delegate (int instanceID,
Rect selectionRect)
{
//在Hierarchy视图中选择一个资源
if (Selection.activeObject &&
instanceID == Selection.activeObject.GetInstanceID())
{
//设置拓展按钮区域
float width = 50f;
selectionRect.x += (selectionRect.width - width);
selectionRect.width = width;
GUI.color = Color.green;
//点击事件
if (GUI.Button(selectionRect, AssetDatabase.LoadAssetAtPath<Texture>("Assets/Resources/unityLogo.jpg")))
{
Debug.LogFormat("click : {0}", Selection.activeObject.name);
}
GUI.color = Color.white;
}
};
}
效果:
Project下:
代码:
/// <summary>
/// 扩展布局 --project视图下
/// </summary>
[InitializeOnLoadMethod] //编辑器模式下初始化执行标签
static void InitializeOnLoadMethod1()
{
EditorApplication.projectWindowItemOnGUI = delegate (string guid, Rect selectionRect)
{
//在Project视图中选择一个资源
if (Selection.activeObject &&
guid == AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath
(Selection.activeObject)))
{
//设置拓展按钮区域
float width = 50f;
selectionRect.x += (selectionRect.width - width);
selectionRect.width = width;
GUI.color = Color.red;
//点击事件
if (GUI.Button(selectionRect, "click"))
{
Debug.LogFormat("click : {0}", Selection.activeObject.name);
}
GUI.color = Color.white;
}
};
}
效果: