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 是如何分布的,于是要求写一个工具显示,于是有了下面这个: 打开场景自动读取当前 ...
随机推荐
- [Java基础] ==和equals比较
==对比的是栈中的值,基本数据类型是变量值,引用类型是堆中内存对象的地址 equals:object中默认也是采用==比较,通常会重写 Object public boolean equals(Obj ...
- P3047 [USACO12FEB]Nearby Cows G 题解
P3047 [USACO12FEB]Nearby Cows G 题目描述 思路 使用换根DP, 设 \(dp[i][j]\) 表示以 \(i\) 为根节点的子树中深度小于等于 \(j\) 的点的权值之 ...
- sensor有点意思之RCCB传感器
1.RCCB sensor 无意中看到一种特殊规格的传感器,RCCB (Red-Clear-Clear-Blue)sensor,第一次听到这个名词,咱不知道就查一查,检索到RCCB sensor是一种 ...
- 基础版本:用KNN算法实现预测facebook签到位置模型的训练(内含数据集下载)
实现模型的训练一般的流程便是 # 导包 # 导入数据 # 数据处理 # 特征工程 # KNN算法预估流程 # 模型评估 接下来便实现以上流程 实现该模型训练我们需要导入一下的函数 1 # 导包 2 3 ...
- 行行AI人才直播第14期:【国内第二波人工智能进入者、连续创业者】土豆《土豆利用GPT成功融资两次的提示词和故事》
行行AI人才(海南行行智能科技有限公司)是博客园和顺顺智慧共同运营的AI行业人才全生命周期服务平台. 此刻,ChatGPT的火热程度已经无需多言.一时间,追逐大模型成了国内AI行业的标准动作,&quo ...
- 好用工具: Carbon--代码美化工具
问题背景 当进行PPT展示时,如果只是简单的复制粘贴代码.会看起来很难看,因此产生美化的想法. 使用方式 官网链接 https://carbon.now.sh
- 解决npm install 报错 'proxy' config is set properly. See: 'npm help config'
输入以下命令 npm config set proxy null npm config set https-proxy null 之后重新安装即可 文章参考 https://blog.csdn.net ...
- golang trace view 视图详解
大家好,我是蓝胖子,在golang中可以使用go pprof的工具对golang程序进行性能分析,其中通过go trace 命令生成的trace view视图对于我们分析系统延迟十分有帮助,鉴于当前对 ...
- C# OpenCVSharp图像入门_给绿幕图片视频加背景
OpenCV的全称是Open Source Computer Vision Library,是一个跨平台的计算机视觉库.OpenCV是由英特尔公司发起并参与开发,以BSD许可证授权发行,可以在商业和研 ...
- Kettle实例(获取Token并带入请求接口拉取数据到本地)
背景 近期工作中遇到许多需要协同的表单文档被放到云文档,那么我们本地做数据分析就需要先抽取云文档实时数据到本地数据库,根据接口文档我们需要先获取Token,再将返回值带到接口中发起请求拉取数据,因为在 ...