1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Item
  5. {
  6.  
  7. public string Id;
  8.  
  9. public string Name;
  10.  
  11. public string ParentId;
  12.  
  13. public Item(string name, string id, string parentid)
  14. {
  15. this.Name = name;
  16. this.Id = id;
  17. this.ParentId = parentid;
  18. }
  19.  
  20. }
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. public class NodeMessage : MonoBehaviour
  6. {
  7.  
  8. public string Tag;
  9.  
  10. public List<NodeMessage> NodeList;
  11.  
  12. }
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Xml;
  5.  
  6. public class TreeNode : MonoBehaviour
  7. {
  8. public GameObject Panel;
  9. public List<Item> ItemList;
  10. dfScrollPanel scrollpanel;
  11.  
  12. void Start()
  13. {
  14. scrollpanel = this.GetComponent<dfScrollPanel>();
  15. ReadXML();
  16. AddNodes();
  17. }
  18.  
  19. void AddNodes()
  20. {
  21. for (int i = ; i < ItemList.Count; i++)
  22. {
  23. if (ItemList[i].ParentId == "")
  24. {
  25. var treeNode = scrollpanel.AddPrefab(Panel);
  26. var newNode = treeNode.GetComponent<NodeMessage>();
  27. newNode.Tag = ItemList[i].Id;
  28. treeNode.Find("Sprite").GetComponent<dfSprite>().SpriteName = "ArrowNormal";
  29. treeNode.Find("Node").GetComponent<dfButton>().Text = ItemList[i].Name;
  30. AddChildNodes(newNode);
  31. }
  32. }
  33. foreach (Transform child in scrollpanel.transform)
  34. {
  35. var TreeNode = child.GetComponent<NodeMessage>();
  36. if (TreeNode.NodeList.Count == )
  37. {
  38. dfPanel NodePanel = child.GetComponent<dfPanel>();
  39. NodePanel.Find("Sprite").GetComponent<dfSprite>().IsVisible = false;
  40. }
  41. }
  42. }
  43.  
  44. public void AddChildNodes(NodeMessage message)
  45. {
  46. for (int i = ; i < ItemList.Count; i++)
  47. {
  48. if (ItemList[i].ParentId == message.Tag)
  49. {
  50. var treeNode = scrollpanel.AddPrefab(Panel);
  51. var newNode = treeNode.GetComponent<NodeMessage>();
  52. newNode.Tag = ItemList[i].Id;
  53. treeNode.Find("Node").GetComponent<dfButton>().Text = ItemList[i].Name;
  54. treeNode.Find("Sprite").GetComponent<dfSprite>().SpriteName = "ArrowNormal";
  55. var parentTransform = message.GetComponent<dfPanel>().Find("Panel").transform;
  56. treeNode.Find("Panel").transform.localPosition = new Vector2(parentTransform.localPosition.x + 0.1f, );
  57. message.NodeList.Add(newNode);
  58. AddChildNodes(newNode);
  59. treeNode.IsVisible = false;
  60. }
  61. }
  62. }
  63.  
  64. public void tubiaoOnClick(bool isShow, string tag, List<NodeMessage> nodelist)
  65. {
  66. for (int i = ; i < ItemList.Count; i++)
  67. {
  68. if (ItemList[i].Id == tag)
  69. {
  70. SelectNodeList(isShow, nodelist);
  71. }
  72. }
  73. }
  74.  
  75. void SelectNodeList(bool isShow, List<NodeMessage> nodelist)
  76. {
  77. for (int j = ; j < nodelist.Count; j++)
  78. {
  79. dfPanel NodePanel = nodelist[j].GetComponent<dfPanel>();
  80. var node = NodePanel.GetComponent<NodeMessage>();
  81. if (isShow == true)
  82. {
  83. NodePanel.IsVisible = true;
  84. }
  85. else
  86. {
  87. tubiaoOnClick(isShow, node.Tag, node.NodeList);
  88. NodePanel.IsVisible = false;
  89. NodePanel.Find("Sprite").GetComponent<dfSprite>().SpriteName = "ArrowNormal";
  90. NodePanel.Find("tubiao").GetComponent<TuBiao>().isShow = false;
  91.  
  92. }
  93. }
  94. }
  95.  
  96. void ReadXML()
  97. {
  98. XmlDocument doc = new XmlDocument();
  99. doc.Load(Application.dataPath + @"\TreeView.xml");
  100. XmlElement rootElem = doc.DocumentElement;
  101. XmlNodeList itemlist = rootElem.GetElementsByTagName("node");
  102.  
  103. ItemList = new List<Item>();
  104. foreach (XmlNode xn1 in itemlist)
  105. {
  106. XmlElement xe = (XmlElement)xn1;
  107. XmlNodeList xml = xe.ChildNodes;
  108. Item item = new Item(xe.GetAttribute("name").ToString(), xml.Item().InnerText, xml.Item().InnerText);
  109. ItemList.Add(item);
  110. }
  111.  
  112. }
  113.  
  114. }
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class TuBiao : MonoBehaviour
  5. {
  6.  
  7. private TreeNode TreeNode;
  8. dfSprite Sprite;
  9. NodeMessage Message;
  10. public bool isShow = false;
  11.  
  12. void Start()
  13. {
  14. Sprite = this.transform.FindChild("Sprite").GetComponent<dfSprite>();
  15. TreeNode = this.transform.parent.parent.parent.GetComponent<TreeNode>();
  16. Message = this.transform.parent.parent.GetComponent<NodeMessage>();
  17. }
  18.  
  19. void OnClick()
  20. {
  21. if (Sprite.SpriteName == "ArrowNormal")
  22. Sprite.SpriteName = "ArrowUnfold";
  23. else
  24. Sprite.SpriteName = "ArrowNormal";
  25. isShow = !isShow;
  26. TreeNode.tubiaoOnClick(isShow, Message.Tag, Message.NodeList);
  27.  
  28. }
  29.  
  30. }

XML如下:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <projects>
  3. <node name="Node1">
  4. <id></id>
  5. <parentid></parentid>
  6. </node>
  7. <node name="Node1 - 1">
  8. <id></id>
  9. <parentid></parentid>
  10. </node>
  11. <node name="Node1 - 1 - 1">
  12. <id></id>
  13. <parentid></parentid>
  14. </node>
  15. <node name="Node1 - 1 - 2">
  16. <id></id>
  17. <parentid></parentid>
  18. </node>
  19. <node name="Node1 - 2">
  20. <id></id>
  21. <parentid></parentid>
  22. </node>
  23. <node name="Node1 - 2 - 1">
  24. <id></id>
  25. <parentid></parentid>
  26. </node>
  27. <node name="Node1 - 2 - 2">
  28. <id></id>
  29. <parentid></parentid>
  30. </node>
  31. <node name="Node2">
  32. <id></id>
  33. <parentid></parentid>
  34. </node>
  35. <node name="Node2 - 1">
  36. <id></id>
  37. <parentid></parentid>
  38. </node>
  39. <node name="Node2 - 2">
  40. <id></id>
  41. <parentid></parentid>
  42. </node>
  43. <node name="Node2 - 2 - 1">
  44. <id></id>
  45. <parentid></parentid>
  46. </node>
  47. <node name="Node2 - 2 - 2">
  48. <id></id>
  49. <parentid></parentid>
  50. </node>
  51. <node name="Node2 - 3">
  52. <id></id>
  53. <parentid></parentid>
  54. </node>
  55. <node name="Node3">
  56. <id></id>
  57. <parentid></parentid>
  58. </node>
  59. <node name="Node3 - 1">
  60. <id></id>
  61. <parentid></parentid>
  62. </node>
  63. <node name="Node3 - 1 - 1">
  64. <id></id>
  65. <parentid></parentid>
  66. </node>
  67. <node name="Node3 - 1 - 2">
  68. <id></id>
  69. <parentid></parentid>
  70. </node>
  71. <node name="Node3 - 2">
  72. <id></id>
  73. <parentid></parentid>
  74. </node>
  75. <node name="Node3 - 2 - 1">
  76. <id></id>
  77. <parentid></parentid>
  78. </node>
  79. <node name="Node3 - 2 - 2">
  80. <id></id>
  81. <parentid></parentid>
  82. </node>
  83. </projects>

Unity基于DFGUI的TreeView设计的更多相关文章

  1. SOA实践之基于服务总线的设计

    在上文中,主要介绍了SOA的概念,什么叫做“服务”,“服务”应该具备哪些特性.本篇中,我将介绍SOA的一种很常见的设计实践--基于服务总线的设计. 基于服务总线的设计 基于总线的设计,借鉴了计算机内部 ...

  2. 基于Apriori算法的Nginx+Lua+ELK异常流量拦截方案 郑昀 基于杨海波的设计文档(转)

    郑昀 基于杨海波的设计文档 创建于2015/8/13 最后更新于2015/8/25 关键词:异常流量.rate limiting.Nginx.Apriori.频繁项集.先验算法.Lua.ELK 本文档 ...

  3. 基于MATLAB2016b图形化设计自动生成Verilog语言的积分模块及其应用

    在电力电子变流器设备中,常常需要计算发电量,由于电力电子变流器设备一般是高频变流设备,所以发电量的计算几乎时实时功率的积分,此时就会用到一个积分模块.发电量计算的公式如下:Q=∫P. FPGA由于其并 ...

  4. 基于ZedBoard的Webcam设计(一):USB摄像头(V4L2接口)的图片采集【转】

    转自:http://www.cnblogs.com/surpassal/archive/2012/12/19/zed_webcam_lab1.html 一直想把USB摄像头接到Zedboard上,搭建 ...

  5. 基于FPGA的DDS设计(一)

    最近在学习基于FPGA的DDS设计,借此机会把学习过程记录下来,当作自己的学习笔记也希望能够帮助到学习DDS的小伙伴. DDS(Direct Digital Synthesizer)直接数字合成器,这 ...

  6. atitit.基于虚拟机的启动器设计 --java 启动器 java生成exe

    atitit.基于虚拟机的启动器设计 --java 启动器   java生成exe exe4j   vs  nativej 1. step1读取配置文件 1 1.1. regular mode   . ...

  7. 基于WPF系统框架设计(5)-Ribbon整合Avalondock 2.0实现多文档界面设计(二)

    AvalonDock 是一个.NET库,用于在停靠模式布局(docking)中排列一系列WPF/WinForm控件.最新发布的版本原生支持MVVM框架.Aero Snap特效并具有更好的性能. Ava ...

  8. unity 基于scrollRect实现翻页显示

    unity 基于scrollRect实现翻页显示,并定为到某一页,而不是某一页的中间方法(第二个脚本采用实际位置计算,并在update里实现平滑过渡): 组场景时,经常需要获取鼠标(或者点击)开始结束 ...

  9. 基于libuv的TCP设计(三)

      基于libuv的TCP设计(一) 基于libuv的TCP设计(二)   一.第二版本的libuv_tcp已经基本可以使用.不会出错与崩溃现象,支持几百路客户端同时连接.可是有一缺陷就占用CPU非常 ...

随机推荐

  1. spring作用域(Spring Bean Scopes Example)

    http://docs.spring.io/spring/docs/2.0.x/reference/beans.html#beans-factory-scopes In Spring, bean sc ...

  2. 搭建ssm+maven环境遇到的问题

    1. @RunWith(SpringJUnit4ClassRunner.class) gives error 在使用junit测试过程中 2.com.google.gson.JsonIOExcepti ...

  3. Linux环境下GNU, GCC, G++编译器(转)

    一,GNU GNU是“GNU 's Not Unix”的递归缩写, Stallman宣布GNU应当发音为Guh-NOO(革奴)以避免与new这个单词混淆(注:Gnu在英文中原意为非洲牛羚,发音与new ...

  4. 〖Linux〗(2013.08.02)使用ctag+cscope查看Android源代码

    1. 安装ctags和cscope sudo apt-get install -y exuberant-ctags cscope 2. vimrc中的配置 """&quo ...

  5. 转载:【Linux+windows】PHP5.5安装PHPRedis扩展

    首先,你必须安装了 Redis服务器,然后才能安装php-redis扩展,就像先安装mysql,然后再将php-mysql扩展安装并引入(区别是:php-redis扩展插件php没有自带,php-my ...

  6. centos 配置 samba 与windows共享文件夹

    yum install samba /etc/samba/smb.conf directory mask = 0777 ← 指定新建目录的属性(以下4行) force directory mode = ...

  7. Altium PCB布局时快速摆放元件的技巧

    http://www.openedv.com/posts/list/45238.htm pcb窗口:工具--->交叉选择模式

  8. 跨服务器查询信息的sql

    --跨服务器查询信息的sql: select * from openrowset( 'SQLOLEDB', '192.168.1.104'; 'sa'; '123.com',[AutoMonitorD ...

  9. ctags简明用法

    1.安装: sudo apt install ctags 2.生成tags文件: //进入目标目录 ctags -R . 3.在vim中设置tags的绝对目录,这样就可以在任何子目录使用了. :set ...

  10. 如何运行Struts2官网最新Demo?

    本篇将讲述下如何运行官网当前最新Struts2.5.10.1 版本的Demo. Struts2 官网:http://struts.apache.org/ 0x00 Demo下载 Struts2 官网2 ...