仅适用于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)的更多相关文章

  1. unity editor 折叠树

    https://blog.csdn.net/e295166319/article/details/52370575 需要两个类:树节点类和界面实现类 1:树节点类(TreeNode) using Un ...

  2. 帆软报表(finereport) 折叠树

    在进行展现数据时,希望模板的数据是可以动态折叠的,即点击数据前面的加号才展开对应下面的数据,可通过树节点按钮实现折叠树效果 实现思路: 1.这里建立一个内置数据集 添加数据 设置模板样式,添加颜色和对 ...

  3. vue 仿zTree折叠树

    需求: vue实现仿zTree折叠树,此文章仅作为记录文档. 实现: <template> <div class="line-tree"> <div ...

  4. layout折叠后显示标题

    Easyui的layout折叠后显示怎样可以显示标题 //在layout的panle全局配置中,增加一个onCollapse处理title$.extend($.fn.layout.paneldefau ...

  5. web页面显示折叠树菜单笔记

    zTree -- jQuery 树插件 http://pan.baidu.com/s/1skwh94h

  6. Unity编辑器的扩展:IMGUI

    IMGUI 介绍 所有关于 Editor 的相关 UI,包括 Inspector.Hierarchy.Window.Game 视图上动态创建的那些半透明 UI.还有 Scene 视图上可添加的辅助显示 ...

  7. Unity EditorWindow知识记录

    1.创建EditorWindow using UnityEditor; using UnityEngine; public class ZZEditorWindow : EditorWindow { ...

  8. d3.js之树形折叠树

    1.效果 children和_children 2.技术分解 2.1折叠函数 // (1) 递归调用,有子孙的就把children(显示)给_children(不显示)暂存,便于折叠, functio ...

  9. jquery easyui菜单树显示

    目前做了一个easyui项目需要显示多级菜单,菜单配置到数据库中,因此每级菜单都需要到数据库中取,用了jQuery EasyUI方便多了. 效果体验:http://hovertree.com/texi ...

  10. Unity光照图UV显示

    美术的同学觉得 Unity 光照图烘焙的不够美丽,需要在 ps 里修一修,但是不知道每个物体对应的光照图在哪个区域,UV 是如何分布的,于是要求写一个工具显示,于是有了下面这个: 打开场景自动读取当前 ...

随机推荐

  1. 搭建Vue脚手架(vue-cli)

    windows下环境安装前置环境 node.js安装 https://nodejs.org/en/download/ 安装成功后打开cmd 输入如下,如果能看到node和npm的版本号了,说明已经安装 ...

  2. 即构SDK10月迭代:新增多款语音音效、外部采集码流控制及Android SDK 最低支持操作系统版本调整

    即构SDK10月迭代内容来喽~~~ 本月调整了Android SDK 最低支持的操作系统版本,新增了流删除回调原因, 4种变音效果和外部采集码流控制,同时还对登录房间.媒体播放器以及第三方库进行了优化 ...

  3. Spring-Bean(二)

    环境在spring-Bean(一)的配置下 https://www.cnblogs.com/doubleconquer/p/15603706.html 来查看ApplicationContext的执行 ...

  4. 使用 virt-install 命令创建虚拟机

    实践 参考文档:官方手册 这个命令适用于创建第一个虚拟机,后面如果再增加,修改xml文件或者使用clone命令就可以了. centos.sh #!/bin/bash name='centos7' is ...

  5. Echarts: 同时显示柱状图和前端

    完整代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...

  6. Unity的IPostprocessBuild:深入解析与实用案例

    Unity IPostprocessBuild技术文章 Unity IPostprocessBuild是Unity引擎中的一个非常有用的功能,它可以让开发者在构建项目后自动执行一些操作.这个功能可以帮 ...

  7. Cobalt Strike使用教程二

    0x00 前言 继前一章介绍了Cobalt Strike的基本用法,本章接着介绍如何攻击.提权.维权等. 0x01 与Metasploit联动 Cobalt Strike → Metasploit m ...

  8. .NET Core多线 (5) 常见性能问题

    合集:.NET Core多线程温故知新 .NET Core多线程(1)Thread与Task .NET Core多线程(2)异步 - 上 .NET Core多线程(3)异步 - 下 .NET Core ...

  9. Go 如何正确关闭通道

    序言 Go 在通道这一块,没有内置函数判断通道是否已经关闭,也没有可以直接获取当前通道数量的方法.所以对于通道,Go 显示的不是那么优雅.另外,如果对通道进行了错误的使用,将会直接引发系统 panic ...

  10. MySQL——后码锁(Next-Key Block)

    众所周知,Mysql的事务隔离级别分为4个,分别是READ-UNCOMMITED,READ-COMMITED,REPEATABLE-READ,SERIALIZABLE,在常规数据库概论中,前三种事务隔 ...