Unity Hierarchy 视图图标绘制

using UnityEditor;
using UnityEngine;

[InitializeOnLoad]
class UGUIOpenedPanelEditor
{
    static readonly Texture2D TexturePanel;
    static UGUIOpenedPanelEditor()
    {
        TexturePanel =
            AssetDatabase.LoadAssetAtPath("Assets/Editor/UIEditorHelp/open.png", typeof(Texture2D)) as Texture2D;
        EditorApplication.hierarchyWindowItemOnGUI += CurrentOpenUIPanel;
    }

    static void CurrentOpenUIPanel(int instanceID, Rect selectionRect)
    {
        Rect r = new Rect(selectionRect);
        r.x = 0;
        r.width = 20;
        GameObject go = EditorUtility.InstanceIDToObject(instanceID) as GameObject;
        if (go != null)
        {
            //满足条件绘制Icon
            var canvasGroup = go.GetComponent<CanvasGroup>();
            if (canvasGroup != null && canvasGroup.alpha >= 1)
            {
                GUI.Label(r, TexturePanel);
            }
        }
    }
}

 

posted @ 2022-07-30 12:02  三页菌  阅读(106)  评论(0编辑  收藏  举报