Unity中实现Hierarchy面板中显示Component的图标——Hierponent插件
发布日期:2021-06-30 19:57:05
浏览次数:3
分类:技术文章
本文共 3694 字,大约阅读时间需要 12 分钟。
这个插件可以在Hierarchy面板中显示此物体身上的所有组件图标(美观+清晰)
Window—AssetStore—Hierponent
插件的源码:
namespace Hierponent{ using UnityEngine; using UnityEditor; using System.Collections.Generic; public class Hierponent { #region --- VAR --- private const int MAX_ICON_NUM = 4; private static ListHideTypes = new List () {typeof(Transform), typeof(ParticleSystemRenderer), typeof(CanvasRenderer),}; private static Transform OffsetObject = null; private static int Offset = 0; #endregion #region --- MSG --- [InitializeOnLoadMethod] public static void Init() { EditorApplication.hierarchyWindowItemOnGUI += HieGUI; } public static void HieGUI(int instanceID, Rect rect) { // Check Object tempObj = EditorUtility.InstanceIDToObject(instanceID); if (!tempObj) { return; } // fix rect rect.width += rect.x; rect.x = 0; // Logic GameObject obj = tempObj as GameObject; List coms = new List (obj.GetComponents ()); for (int i = 0; i < coms.Count; i++) { if (!coms[i]) { continue; } if (TypeCheck(coms[i].GetType())) { coms.RemoveAt(i); i--; } } int iconSize = 16; int y = 1; int offset = obj.transform == OffsetObject ? Offset : 0; // Main for (int i = 0; i + offset < coms.Count && i < MAX_ICON_NUM; i++) { Component com = coms[i + offset]; // Logic Texture2D texture = AssetPreview.GetMiniThumbnail(com); if (texture) { GUI.DrawTexture(new Rect(rect.width - (iconSize + 1) * (i + 1), rect.y + y, iconSize, iconSize), texture); } } // More Button if (coms.Count == MAX_ICON_NUM + 1) { Texture2D texture = AssetPreview.GetMiniThumbnail(coms[coms.Count - 1]); if (texture) { GUI.DrawTexture(new Rect(rect.width - (iconSize + 1) * (coms.Count - 1 + 1), rect.y + y, iconSize, iconSize), texture); } } else if (coms.Count > MAX_ICON_NUM) { GUIStyle style = new GUIStyle(GUI.skin.label); style.fontSize = 9; style.alignment = TextAnchor.MiddleCenter; if (GUI.Button(new Rect(rect.width - (iconSize + 2) * (MAX_ICON_NUM + 1), rect.y + y, 22, iconSize), "•••", style)) { if (OffsetObject != obj.transform) { OffsetObject = obj.transform; Offset = 0; } Offset += MAX_ICON_NUM; if (Offset >= coms.Count) { Offset = 0; } } } } #endregion #region --- LGC --- private static bool TypeCheck(System.Type type) { for (int i = 0; i < HideTypes.Count; i++) { if (type == HideTypes[i] || type.IsSubclassOf(HideTypes[i])) { return true; } } return false; } #endregion }}
转载地址:https://liuhaowen.blog.csdn.net/article/details/103920321 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
不错!
[***.144.177.141]2024年04月16日 03时21分12秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
论DEV-C++怎样才能做窗口
2019-04-30
Failed to connect to github.com port 443: Operation timed out和弹出无法打开"GoogleSoftwareUpdate.bundle"
2019-04-30
2021.5.19 JS高级第二天
2019-04-30
2021.5.20 JS高级第三天
2019-04-30
2021.5.21 Jquery
2019-04-30
2021.5.22 Jquery
2019-04-30
2021.5.25 JSON
2019-04-30
2021.5.25 Flex
2019-04-30
2021.5.28 AJAX
2019-04-30
正则表达式
2019-04-30
过滤器Filter
2019-04-30
2021.6.1 Array补充
2019-04-30
【收藏】Markdown笔记
2019-04-30
离散数学-图论
2019-04-30
啊沙发沙发
2019-04-30
2021-07-02
2019-04-30
「收藏」HTML笔记-持续更新中
2019-04-30
数据结构期末复习------排序汇总
2019-04-30
数据结构期末复习------查找汇总
2019-04-30
Vue学习(10)————————编程式导航,地址栏的#号去掉,路由的嵌套
2019-04-30