第一种
InitializeOnLoadMethod??//初始化加载方法
EditorApplication.hierarchyWindowItemOnGUI 当绘制层次窗口里面Item项时候
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class Script
{
[InitializeOnLoadMethod]//初始化加载方法
//EditorApplication.hierarchyWindowItemOnGUI 当绘制层次窗口里面Item项时候
static void InitializeOnLoadMethod()
{
EditorApplication.hierarchyWindowItemOnGUI = delegate (int intstanceID, Rect selectionRect)
{
if(Selection.activeObject&&intstanceID==Selection.activeObject.GetInstanceID())
{
float width = 50f;
float height = 20f;
selectionRect.x += (selectionRect.width - width);
selectionRect.width = width;
selectionRect.height = height;
//GUIStyle style = new GUIStyle();
//style.normal.textColor = Color.red;
//GUI.Label(selectionRect, "你好",style);
GUI.Label(selectionRect, AssetDatabase.LoadAssetAtPath<Texture>("Assets/unity.png"));
}
};
}
}
?
第二种
?InitializeOnLoad ?//仅对类有作用 ?unity 会在用户之前去初始化这个编辑器类 ?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEditor;
// unity 会在用户之前去初始化这个编辑器类
[InitializeOnLoad]//仅对类有作用
public class NewBehaviourScript1
{
static NewBehaviourScript1()
{
EditorApplication.hierarchyWindowItemOnGUI += fun;
}
static void fun(int count,Rect selectionRect)
{
var a = EditorUtility.InstanceIDToObject(count) as GameObject;
if(a!=null)
{
Rect rectCheck = new Rect(selectionRect);
rectCheck.x = rectCheck.width;
rectCheck.width = 30;
rectCheck.height = 18;
GUIStyle gUI = new GUIStyle();
gUI.normal.textColor = Color.red;
Object c=null;
if (a.name.Contains("boss"))
{
c = AssetDatabase.LoadAssetAtPath<Object>("Assets/9.png");
}
if(a.name.Contains("Canvas"))
{
c = AssetDatabase.LoadAssetAtPath<Object>("Assets/10.png");
}
if(c!=null)
{
var c1 = EditorGUIUtility.ObjectContent(c, typeof(Image)).image;
GUI.Label(rectCheck, c1);
}
}
}
}
?
?
|