仅适用于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. 一文搞懂什么是 API

    在我学习软件开发之前,API 听起来像是一种啤酒(IPA,印度淡色艾尔).如今我经常使用这个术语,事实上最近我还尝试在酒吧里点了一个 API,结果酒保给了我一个: 404 资源未找到的回应 无论是在科 ...

  2. WinUI(WASDK)使用MediaPipe检查人体姿态关键点

    前言 之前有用这个MediaPipe.NET .NET包装库搞了手势识别,丰富了稚晖君的ElectronBot机器人的第三方上位机软件的功能,MediaPipe作为谷歌开源的机器视觉库,功能很丰富了, ...

  3. Flutter ncnn 使用

    Flutter 实现手机端 App,如果想利用 AI 模型添加新颖的功能,那么 ncnn 就是一种可考虑的手机端推理模型的框架. 本文即是 Flutter 上使用 ncnn 做模型推理的实践分享.有如 ...

  4. 2023ccpc大学生程序设计竞赛-wh

    对于大一的我,只听说线下大型比赛,而第一次参加也必然心情激动,生为大一,由于没有参赛经历,所有不知道参赛技巧,所以三个人像个无头苍蝇一样,跟着榜单做,我作为写码的,其他两名队友负责思路和想法,第一道签 ...

  5. Linux下Oracle单实例配置多监听

    Oracle单实例配置多监听 一.前言 有时候我们项目中需要使用Oracle数据库,同时要需要不同的数据源,而Oracle不像Mysql那样直接建个库即可,Oracle是以账号为单位,可以理解为一个账 ...

  6. mysql怎样实现不重复插入数据

    mysql使用用insert往数据表中插入数据时,为了不重复插入数据,往往先查询一下该条数据是否已经存在,若不存在才进行插入操作. 而使用 insert if not exists语句,就不需重复做上 ...

  7. 2021-4-19 vs加速启动小技巧之intellitrace

    在选项界面中将intellitrace的启用关闭后对于程序的打开有加速作用.

  8. 关于微信小程序原生组件与uniApp混合开发过程遇到的问题与解决方式

    前言: 在实际开发过程中,尤其是小程序的开发,我们常常会遇到一些在文档中解决不了的问题,在这里,我就浅谈一下我遇到的一些问题 1.小程序的构建框架是uni-app,却突然被要求用原生的微信小程序代码来 ...

  9. 关于Tensorflow!目标检测预训练模型的迁移学习

    ​ 前言 关于TF的目标检测迁移学习,我一开始是想通过Tensorflow提供的API,用JS来实现的.但是官方不但没有案例,网上也没有踩坑的博客,加之我又着急要弄水印检测. 于是就在网上看了很多人用 ...

  10. grub加密与解密

    前言 grub默认无加密,用户可免密以单用户模式进入系统修改root密码.若想增强其安全性,可以将grub加密. GRUB2提供两种类型的密码保护: 修改菜单条目时需要密码,但启动菜单条目时不需要密码 ...