Unity - EditorWindow 折叠树显示(IMGUI)
仅适用于2018之前的版本,有UIElements或者UIWidgets的最好用新的
基本实现
树节点
public interface ITreeNode
{
ITreeNode Parent { get; set; }
List<ITreeNode> Children { get; }
bool IsOpen { get; set; }
string DisplayString { get; }
void AddChild(ITreeNode node);
void Dispose();
}
public class TreeNode : ITreeNode
{
private string m_Message;
public ITreeNode Parent { get; set; }
List<ITreeNode> Children { get; private set; }
bool IsOpen { get; set; }
string DisplayString { get { return m_Message; } }
public TreeNode(string message)
{
m_Message = message;
}
public void AddChild(ITreeNode node)
{
if (Children == null)
{
Children = new List<ITreeNode>();
}
node.Parent = this;
Children.Add(node);
}
public void Dispose()
{
if (Children = null)
{
return;
}
foreach (ITreeNode node in Children)
{
node.Dispose();
}
Children.Clear();
Children = null;
}
}
窗口
public class TestWindow : EditorWindow
{
[MenuItem("Tools/Test")]
public static void OpenWindow()
{
GetWindow<TestWindow>();
}
private static float s_LineHeight = 20;
private static float s_Indentation = 20;
private static float s_CharacterWidth = 20;
private TreeNode m_Root;
private void OnEnable()
{
m_Root = new TreeNode("Root");
m_Root.AddChild(new TreeNode("Child1"));
m_Root.AddChild(new TreeNode("Child2"));
var child3 = new TreeNode("Child3");
m_Root.AddChild(child3);
child3.AddChild(new TreeNode("Child3-1"));
}
private void OnGUI()
{
if (m_Root == null)
{
return;
}
int depth = 0;
int index = 0;
DrawNode(m_Root, ref depth, ref index);
}
private void DrawNode(ITreeNode node, ref int depth, ref int index)
{
string content = node.DisplayString;
Rect rect = new Rect(s_Indentation * depth, s_LineHeight * index, content.Length * s_CharacterWidth, s_LineHeight);
node.IsOpen = EditorGUI.Foldout(rect, node.IsOpen, content, true);
index++;
if (node.IsOpen && node.Children != null)
{
depth++;
foreach(ITreeNode child in node.Children)
{
DrawNode(child, ref depth, ref index);
}
depth--;
}
}
}
不显示多余的折叠箭头
最简单的方法是改用Button
public class TestWindow : EditorWindow
{
// ...
private GUIStyle m_NormalStyle;
private GUIStyle m_FoldoutStyle;
private void OnEnable()
{
//...
m_FoldoutStyle = new GUIStyle("Foldout");
m_NormalStyle = new GUIStyle();
m_NormalStyle.normal.background = null;
m_NormalStyle.normal.textColor = m_FoldoutStyle.normal.textColor;
}
private void DrawNode(ITreeNode node, ref int depth, ref int index)
{
//...
// node.IsOpen = EditorGUI.Foldout(rect, node.IsOpen, content, true);
bool isOpen = node.IsOpen;
GUIStyle style = node.Children == null ? m_NormalStyle : m_FoldoutStyle;
if (GUI.Button(rect, content, style))
{
node.IsOpen = !isOpen;
node.OnClick();
}
//...
}
}
Unity - EditorWindow 折叠树显示(IMGUI)的更多相关文章
- unity editor 折叠树
https://blog.csdn.net/e295166319/article/details/52370575 需要两个类:树节点类和界面实现类 1:树节点类(TreeNode) using Un ...
- 帆软报表(finereport) 折叠树
在进行展现数据时,希望模板的数据是可以动态折叠的,即点击数据前面的加号才展开对应下面的数据,可通过树节点按钮实现折叠树效果 实现思路: 1.这里建立一个内置数据集 添加数据 设置模板样式,添加颜色和对 ...
- vue 仿zTree折叠树
需求: vue实现仿zTree折叠树,此文章仅作为记录文档. 实现: <template> <div class="line-tree"> <div ...
- layout折叠后显示标题
Easyui的layout折叠后显示怎样可以显示标题 //在layout的panle全局配置中,增加一个onCollapse处理title$.extend($.fn.layout.paneldefau ...
- web页面显示折叠树菜单笔记
zTree -- jQuery 树插件 http://pan.baidu.com/s/1skwh94h
- Unity编辑器的扩展:IMGUI
IMGUI 介绍 所有关于 Editor 的相关 UI,包括 Inspector.Hierarchy.Window.Game 视图上动态创建的那些半透明 UI.还有 Scene 视图上可添加的辅助显示 ...
- Unity EditorWindow知识记录
1.创建EditorWindow using UnityEditor; using UnityEngine; public class ZZEditorWindow : EditorWindow { ...
- d3.js之树形折叠树
1.效果 children和_children 2.技术分解 2.1折叠函数 // (1) 递归调用,有子孙的就把children(显示)给_children(不显示)暂存,便于折叠, functio ...
- jquery easyui菜单树显示
目前做了一个easyui项目需要显示多级菜单,菜单配置到数据库中,因此每级菜单都需要到数据库中取,用了jQuery EasyUI方便多了. 效果体验:http://hovertree.com/texi ...
- Unity光照图UV显示
美术的同学觉得 Unity 光照图烘焙的不够美丽,需要在 ps 里修一修,但是不知道每个物体对应的光照图在哪个区域,UV 是如何分布的,于是要求写一个工具显示,于是有了下面这个: 打开场景自动读取当前 ...
随机推荐
- RabbitMQ 多消费者 使用单信道和多信道区别
RabbitMQ 多个消费者共用一个信道实例 与 每个消费者使用不同的信道实例 区别: 1. 多个消费者共用一个信道实例:这种方式下,多个消费者共享同一个信道实例来进行消息的消费. 优点:这样可以减少 ...
- python学习笔记:继承与超类
与java类似,继承的出现是为了提高代码的重复利用率,避免多次输入同样的代码.而超类就是java中的父类. 1.继承 要指定超类,可在定义类时,在class语句中的类名后加上超类名 基类就是超类,派生 ...
- 【Springboot】项目启动后执行特定方法
Springboot项目启动后执行特定方法 Springboot给我们提供了两种"开机启动"方式:ApplicationRunner和CommandLineRunner. 这两种方 ...
- 【Redis】基础命令
声明:本篇文章参考于该作者的# Redis从入门到精通:中级篇,大家有兴趣,去关注一下. 1.字符串(String) String(字符串)是Redis中最简单的一种数据结构,和MemCache数据结 ...
- Set_HashSet_TreeSet_小记
Set接口:Set集合继承自Collection集合 Set:底层数据结构是一个哈希表,能保证元素是唯一的,元素不重复!它通过它的子实现了HashSet集合去实例化,HashSet集合底层是HashM ...
- Kubernetes安全框架
Kubernetes安全框架 K8S安全控制框架主要由下面3个阶段进行控制,每一个阶段都 支持插件方式,通过API Server配置来启用插件. Authentication(鉴权):身份鉴别,只有正 ...
- Redis核心技术与实践 03 | 高性能IO模型:为什么单线程Redis能那么快?
原文地址:https://time.geekbang.org/column/article/268262 个人博客地址:http://njpkhuan.cn/archives/redis-he-xin ...
- KVM VM 添加 usb 设备
制作xml文件 参考链接:https://libvirt.org/formatdomain.html#usb-pci-scsi-devices <hostdev mode='subsystem' ...
- VSCode中的快捷键
VS Code中的快捷键 文件和编辑操作 Ctrl+S:保存文件 Ctrl+K S:保存全部文件 Ctrl+C:复制 Ctrl+V:粘贴 Ctrl+X:剪切 Ctrl+F:查找 Ctrl+H:替换 C ...
- SQL-去除最大值与最小值求均值的问题
背景 今天有同事问我一道关于数据库SQL的面试题,我刚开始随便给了一个思路,后来思索发现这个思路有漏洞,于是总结下来,仅供参考. 问题: 薪水表中是员工薪水的基本信息,包括雇员编号,和薪水,查询除去最 ...