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 是如何分布的,于是要求写一个工具显示,于是有了下面这个: 打开场景自动读取当前 ...
随机推荐
- 谷歌语法的基础知识&FOFA
谷歌语法 谷歌语法基础符号: "xxx":表示完全匹配,即关键字不能分开,顺序也不能变 +:"xxx"+www.baidu.com 搜索xxx与baidu.c ...
- Hugging News #0717: 开源大模型榜单更新、音频 Transformers 课程完成发布!
每一周,我们的同事都会向社区的成员们发布一些关于 Hugging Face 相关的更新,包括我们的产品和平台更新.社区活动.学习资源和内容更新.开源库和模型更新等,我们将其称之为「Hugging Ne ...
- 快速搭建 phpmyadmin 开发环境
真的很喜欢 phpmyadmin 这个 PHP 程序. 虽然工作上基本都用 Navicat,但是很多东西都是习惯了,就很难改变! 比如建表,执行 SQL 语句,界面操作肯定是 phpmyadmin 更 ...
- .Net 一套接口多实现
.Net 一套接口多实现 接口(interface)可理解为规范.标准.协议.接口是用来约束各方都在同一组规范下工作. 电脑外设USB接口,各个品牌商家生产的U盘.鼠标都能够被电脑主板识别并工作,这是 ...
- Mysql基础8-多表查询
一.多表关系 一对多或者多对一 案例:部门与员工的关系 关系:一个部门对应多个员工,一个员工对应一个部门(不考虑跨部门的特殊情况) 实现:在多的一方建立外键,指向一的一方的主键,这里员工表是多的的一方 ...
- Linux 问题:普通用户(non-root)无法ssh登录
vi /etc/pam.d/sshd ## 将下面那行注释,保存文件即可. # Disallow non-root logins when /etc/nologin exists. account r ...
- shell 默认参数
#!/bin/bash dst_dir=${2:-/tmp} # 当 $2 为空或null时,设置默认值. docker cp prometheus:$1 $dst_dir
- Python类与面向对象
Python类与面向对象 一.面向对象 1.1 面向对象概述 面向对象与面向过程? 面向过程编程的基本思想是:分析解决问题的步骤,使用函数实现每步对应的功能,按照步骤的先后顺序依次调用函数.面向过程只 ...
- 【入门教程】3202年了,还有人没用stable diffusion画过自己的AI小姐姐吗。
个人绘画作品: 说明 本文主要是讲一下如何安装.使用整合包,以及介绍画真人图片的大模型(介绍的整合包只提供二次元模型,个人不太感兴趣) 通过最简单的介绍帮助大家快速入门,开始画图,不会深入的进行讲解, ...
- C#应用处理传入参数 - 开源研究系列文章
今天介绍关于C#的程序传入参数的处理例子. 程序的传入参数应用比较普遍,特别是一个随操作系统启动的程序,需要设置程序启动的时候不显示主窗体,而是在后台运行,于是就有了传入参数问题,比如传入/h或者/m ...