Unity中实现Hierarchy面板中显示Component的图标——Hierponent插件
发布日期:2021-06-30 19:57:05
浏览次数:2
分类:技术文章
本文共 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 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
能坚持,总会有不一样的收获!
[***.219.124.196]2024年04月20日 23时40分04秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Camera-ready ddl
2019-04-30
CUB-200鸟类数据集
2019-04-30
Python反射机制
2019-04-30
YAPF —— Python代码格式化工具
2019-04-30
UGC 用户产生内容
2019-04-30
ranger
2019-04-30
slurm
2019-04-30
xfce4
2019-04-30
xrdp
2019-04-30
Raft算法
2019-04-30
Python计算文本BLEU分数
2019-04-30
swap内存(linux)
2019-04-30
torch.distributed 分布式
2019-04-30
PyPy
2019-04-30
MATLAB与CUDA
2019-04-30
Linux png转jpg (convert命令)
2019-04-30
NAS (Network Attached Storage 网络附属存储)
2019-04-30
Ubuntu更新后终端中字体的颜色全是白色
2019-04-30
vscode git
2019-04-30
基于MATLAB的二进制数字调制与解调信号的仿真——2FSK
2019-04-30