Unity基于DFGUI的TreeView设计
using UnityEngine;
using System.Collections; public class Item
{ public string Id; public string Name; public string ParentId; public Item(string name, string id, string parentid)
{
this.Name = name;
this.Id = id;
this.ParentId = parentid;
} }
using UnityEngine;
using System.Collections;
using System.Collections.Generic; public class NodeMessage : MonoBehaviour
{ public string Tag; public List<NodeMessage> NodeList; }
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Xml; public class TreeNode : MonoBehaviour
{
public GameObject Panel;
public List<Item> ItemList;
dfScrollPanel scrollpanel; void Start()
{
scrollpanel = this.GetComponent<dfScrollPanel>();
ReadXML();
AddNodes();
} void AddNodes()
{
for (int i = ; i < ItemList.Count; i++)
{
if (ItemList[i].ParentId == "")
{
var treeNode = scrollpanel.AddPrefab(Panel);
var newNode = treeNode.GetComponent<NodeMessage>();
newNode.Tag = ItemList[i].Id;
treeNode.Find("Sprite").GetComponent<dfSprite>().SpriteName = "ArrowNormal";
treeNode.Find("Node").GetComponent<dfButton>().Text = ItemList[i].Name;
AddChildNodes(newNode);
}
}
foreach (Transform child in scrollpanel.transform)
{
var TreeNode = child.GetComponent<NodeMessage>();
if (TreeNode.NodeList.Count == )
{
dfPanel NodePanel = child.GetComponent<dfPanel>();
NodePanel.Find("Sprite").GetComponent<dfSprite>().IsVisible = false;
}
}
} public void AddChildNodes(NodeMessage message)
{
for (int i = ; i < ItemList.Count; i++)
{
if (ItemList[i].ParentId == message.Tag)
{
var treeNode = scrollpanel.AddPrefab(Panel);
var newNode = treeNode.GetComponent<NodeMessage>();
newNode.Tag = ItemList[i].Id;
treeNode.Find("Node").GetComponent<dfButton>().Text = ItemList[i].Name;
treeNode.Find("Sprite").GetComponent<dfSprite>().SpriteName = "ArrowNormal";
var parentTransform = message.GetComponent<dfPanel>().Find("Panel").transform;
treeNode.Find("Panel").transform.localPosition = new Vector2(parentTransform.localPosition.x + 0.1f, );
message.NodeList.Add(newNode);
AddChildNodes(newNode);
treeNode.IsVisible = false;
}
}
} public void tubiaoOnClick(bool isShow, string tag, List<NodeMessage> nodelist)
{
for (int i = ; i < ItemList.Count; i++)
{
if (ItemList[i].Id == tag)
{
SelectNodeList(isShow, nodelist);
}
}
} void SelectNodeList(bool isShow, List<NodeMessage> nodelist)
{
for (int j = ; j < nodelist.Count; j++)
{
dfPanel NodePanel = nodelist[j].GetComponent<dfPanel>();
var node = NodePanel.GetComponent<NodeMessage>();
if (isShow == true)
{
NodePanel.IsVisible = true;
}
else
{
tubiaoOnClick(isShow, node.Tag, node.NodeList);
NodePanel.IsVisible = false;
NodePanel.Find("Sprite").GetComponent<dfSprite>().SpriteName = "ArrowNormal";
NodePanel.Find("tubiao").GetComponent<TuBiao>().isShow = false; }
}
} void ReadXML()
{
XmlDocument doc = new XmlDocument();
doc.Load(Application.dataPath + @"\TreeView.xml");
XmlElement rootElem = doc.DocumentElement;
XmlNodeList itemlist = rootElem.GetElementsByTagName("node"); ItemList = new List<Item>();
foreach (XmlNode xn1 in itemlist)
{
XmlElement xe = (XmlElement)xn1;
XmlNodeList xml = xe.ChildNodes;
Item item = new Item(xe.GetAttribute("name").ToString(), xml.Item().InnerText, xml.Item().InnerText);
ItemList.Add(item);
} } }
using UnityEngine;
using System.Collections; public class TuBiao : MonoBehaviour
{ private TreeNode TreeNode;
dfSprite Sprite;
NodeMessage Message;
public bool isShow = false; void Start()
{
Sprite = this.transform.FindChild("Sprite").GetComponent<dfSprite>();
TreeNode = this.transform.parent.parent.parent.GetComponent<TreeNode>();
Message = this.transform.parent.parent.GetComponent<NodeMessage>();
} void OnClick()
{
if (Sprite.SpriteName == "ArrowNormal")
Sprite.SpriteName = "ArrowUnfold";
else
Sprite.SpriteName = "ArrowNormal";
isShow = !isShow;
TreeNode.tubiaoOnClick(isShow, Message.Tag, Message.NodeList); } }
XML如下:
<?xml version="1.0" encoding="utf-8"?>
<projects>
<node name="Node1">
<id></id>
<parentid></parentid>
</node>
<node name="Node1 - 1">
<id></id>
<parentid></parentid>
</node>
<node name="Node1 - 1 - 1">
<id></id>
<parentid></parentid>
</node>
<node name="Node1 - 1 - 2">
<id></id>
<parentid></parentid>
</node>
<node name="Node1 - 2">
<id></id>
<parentid></parentid>
</node>
<node name="Node1 - 2 - 1">
<id></id>
<parentid></parentid>
</node>
<node name="Node1 - 2 - 2">
<id></id>
<parentid></parentid>
</node>
<node name="Node2">
<id></id>
<parentid></parentid>
</node>
<node name="Node2 - 1">
<id></id>
<parentid></parentid>
</node>
<node name="Node2 - 2">
<id></id>
<parentid></parentid>
</node>
<node name="Node2 - 2 - 1">
<id></id>
<parentid></parentid>
</node>
<node name="Node2 - 2 - 2">
<id></id>
<parentid></parentid>
</node>
<node name="Node2 - 3">
<id></id>
<parentid></parentid>
</node>
<node name="Node3">
<id></id>
<parentid></parentid>
</node>
<node name="Node3 - 1">
<id></id>
<parentid></parentid>
</node>
<node name="Node3 - 1 - 1">
<id></id>
<parentid></parentid>
</node>
<node name="Node3 - 1 - 2">
<id></id>
<parentid></parentid>
</node>
<node name="Node3 - 2">
<id></id>
<parentid></parentid>
</node>
<node name="Node3 - 2 - 1">
<id></id>
<parentid></parentid>
</node>
<node name="Node3 - 2 - 2">
<id></id>
<parentid></parentid>
</node>
</projects>
Unity基于DFGUI的TreeView设计的更多相关文章
- SOA实践之基于服务总线的设计
在上文中,主要介绍了SOA的概念,什么叫做“服务”,“服务”应该具备哪些特性.本篇中,我将介绍SOA的一种很常见的设计实践--基于服务总线的设计. 基于服务总线的设计 基于总线的设计,借鉴了计算机内部 ...
- 基于Apriori算法的Nginx+Lua+ELK异常流量拦截方案 郑昀 基于杨海波的设计文档(转)
郑昀 基于杨海波的设计文档 创建于2015/8/13 最后更新于2015/8/25 关键词:异常流量.rate limiting.Nginx.Apriori.频繁项集.先验算法.Lua.ELK 本文档 ...
- 基于MATLAB2016b图形化设计自动生成Verilog语言的积分模块及其应用
在电力电子变流器设备中,常常需要计算发电量,由于电力电子变流器设备一般是高频变流设备,所以发电量的计算几乎时实时功率的积分,此时就会用到一个积分模块.发电量计算的公式如下:Q=∫P. FPGA由于其并 ...
- 基于ZedBoard的Webcam设计(一):USB摄像头(V4L2接口)的图片采集【转】
转自:http://www.cnblogs.com/surpassal/archive/2012/12/19/zed_webcam_lab1.html 一直想把USB摄像头接到Zedboard上,搭建 ...
- 基于FPGA的DDS设计(一)
最近在学习基于FPGA的DDS设计,借此机会把学习过程记录下来,当作自己的学习笔记也希望能够帮助到学习DDS的小伙伴. DDS(Direct Digital Synthesizer)直接数字合成器,这 ...
- atitit.基于虚拟机的启动器设计 --java 启动器 java生成exe
atitit.基于虚拟机的启动器设计 --java 启动器 java生成exe exe4j vs nativej 1. step1读取配置文件 1 1.1. regular mode . ...
- 基于WPF系统框架设计(5)-Ribbon整合Avalondock 2.0实现多文档界面设计(二)
AvalonDock 是一个.NET库,用于在停靠模式布局(docking)中排列一系列WPF/WinForm控件.最新发布的版本原生支持MVVM框架.Aero Snap特效并具有更好的性能. Ava ...
- unity 基于scrollRect实现翻页显示
unity 基于scrollRect实现翻页显示,并定为到某一页,而不是某一页的中间方法(第二个脚本采用实际位置计算,并在update里实现平滑过渡): 组场景时,经常需要获取鼠标(或者点击)开始结束 ...
- 基于libuv的TCP设计(三)
基于libuv的TCP设计(一) 基于libuv的TCP设计(二) 一.第二版本的libuv_tcp已经基本可以使用.不会出错与崩溃现象,支持几百路客户端同时连接.可是有一缺陷就占用CPU非常 ...
随机推荐
- 百度地图总结第二篇--POI检索功能
简单介绍: 眼下百度地图SDK所集成的检索服务包含:POI检索.公交信息查询.线路规划.地理编码.行政区边界数据检索.在线建议查询.短串分享(包含POI搜索结果分享.驾车/公交/骑行/步行路线规划分享 ...
- Python标准库:内置函数dict(mapping, **kwarg)
本函数是从一个映射函数对象构造一个新字典. 与dict(**kwarg)函数不一样的地方是參数输入是一个映射类型的函数对象,比方zip函数.map函数. 样例: #dict() #以键对方式构造字典 ...
- Spring中bean的生命周期!
Spring 中bean 的生命周期短暂吗? 在spring中,从BeanFactory或ApplicationContext取得的实例为Singleton,也就是预设为每一个Bean的别名只能维持一 ...
- Echarts实例
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- 工作总结 Rezor 里面的一些小知识----自定义类型 放在标签值中 会直接跳过去
0 的时候不报错 1 的时候 报错了 原因 是 imagesname[i] 索引超出了 为什么在 上面 报错呢? 不在这里报错呢? 说明了 Rezor 对于 自定义的变量 放在标签值里的时候,调 ...
- ArcGis10.0常见错误
1. 问题: Arcgis10.0 组件初始化失败 解决方法: ESRI.ArcGIS.RuntimeManager.BindLicense(ESRI.ArcGIS.ProductCode.Eng ...
- vector 类简介和例程
一.标准库的vector类型 vector是同一种类型的对象的集合 vector的数据结构很像数组,能非常高效和方便地访问单个元素 vector是一个类模板(class template) vecto ...
- 记一次解决layui 的bug - layer.open 与 layui渲染问题
场景是这样的,通过layer打开一个弹窗,里面放置一个表单,表单是用layui来渲染的. 当弹窗完成之后,我需要渲染表单中的一些内容.譬如laydate. layer.open({ type: 1, ...
- Atitit.struts2体系结构大总结
Atitit.struts2体系结构大总结 1. 国际化与异常处理 2 2. 第5章 拦截器 2 3. 第7章 输入校验 2 4. 避免表单重复提交与等待页面 2 5. Struts 2对Ajax的支 ...
- atitit.软件开发--socket框架选型--netty vs mina j
atitit.软件开发--socket框架选型--netty vs mina j . Netty是由JBOSS提供的一个java开源框架 Apache mina 三.文档比较 mina文档多,,, 好 ...