首页 > 编程语言 > 详细

unity编辑器Hierarchy添加图标

时间:2019-07-30 18:16:50      阅读:217      评论:0      收藏:0      [点我收藏+]

效果

技术分享图片

 

素材

技术分享图片

 

 

using UnityEditor;
using UnityEngine;
using System.Collections.Generic;

[InitializeOnLoad]
class MyHierarchyIcon
{
    static Texture2D texture;
    static List<int> markedObjects;

    //静态构造
    static MyHierarchyIcon()
    {
        //需要自己准备一张图放到如下路径  Assets/Images/Testicon.png
        texture = AssetDatabase.LoadAssetAtPath("Assets/Images/Testicon.png", typeof(Texture2D)) as Texture2D;
        EditorApplication.update += UpdateCB;
        EditorApplication.hierarchyWindowItemOnGUI += HierarchyItemCB;
    }

    static void UpdateCB()
    {
        // Check here
        GameObject[] go = Object.FindObjectsOfType(typeof(GameObject)) as GameObject[];

        markedObjects = new List<int>();
        foreach (GameObject g in go)
        {
            // Example: mark all lights  判断放图标的条件,比如有灯关组件
            if (g.GetComponent<Light>() != null)
                markedObjects.Add(g.GetInstanceID());
        }

    }

    static void HierarchyItemCB(int instanceID, Rect selectionRect)
    {
        // place the icoon to the right of the list:
        Rect r = new Rect(selectionRect);
        r.x = r.width - 10;//图片位置
        r.width = 16;//图片宽度

        if (markedObjects.Contains(instanceID))
        {
            // Draw the texture if it‘s a light (e.g.)
            GUI.Label(r, texture);
        }
    }

}

 

unity编辑器Hierarchy添加图标

原文:https://www.cnblogs.com/sanyejun/p/11271783.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!