TreeNodeList.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System.Collections.Generic;
  2. using UniRx;
  3. using UnityEngine;
  4. namespace QFramework
  5. {
  6. /// <summary>
  7. /// 树形节点表
  8. /// </summary>
  9. public class TreeNodeList
  10. {
  11. //节点表
  12. public ReactiveCollection<TreeNodeItem> TreeNodeItems = new ReactiveCollection<TreeNodeItem>();
  13. //所有节点字典
  14. public List<TreeNodeItem> treeNodeItems = new List<TreeNodeItem>();
  15. /// <summary>
  16. /// 添加节点
  17. /// </summary>
  18. /// <param name="content">内容</param>
  19. /// <param name="parent">父节点名称</param>
  20. /// <param name="layer">层级</param>
  21. public void AddTreeNode(TreeNodeItem treeNodeData)
  22. {
  23. if (string.IsNullOrEmpty(treeNodeData.ParentName.Value))
  24. {
  25. treeNodeData.ShowHidden.Value = true;
  26. treeNodeItems.Add(treeNodeData);
  27. TreeNodeItems.Add(treeNodeData);
  28. }
  29. else
  30. {
  31. TreeNodeItem tmpItem = treeNodeItems.Find(t => t.Content.Value == treeNodeData.ParentName.Value);
  32. if (tmpItem != null)
  33. {
  34. tmpItem.ChildTreeNodeList.TreeNodeItems.Add(treeNodeData);
  35. treeNodeItems.Add(treeNodeData);
  36. }
  37. }
  38. }
  39. }
  40. public class TreeNodeItem
  41. {
  42. /// <summary>
  43. /// 内容
  44. /// </summary>
  45. public StringReactiveProperty Content = new StringReactiveProperty(string.Empty);
  46. /// <summary>
  47. /// 父节点名称
  48. /// </summary>
  49. public StringReactiveProperty ParentName = new StringReactiveProperty(string.Empty);
  50. /// <summary>
  51. /// 子节点列表
  52. /// </summary>
  53. public TreeNodeList ChildTreeNodeList = new TreeNodeList();
  54. /// <summary>
  55. /// 层级
  56. /// </summary>
  57. public IntReactiveProperty Layer = new IntReactiveProperty(0);
  58. /// <summary>
  59. /// 是否展开
  60. /// </summary>
  61. public BoolReactiveProperty ExPanded = new BoolReactiveProperty(false);
  62. /// <summary>
  63. /// 显示或隐藏
  64. /// </summary>
  65. public BoolReactiveProperty ShowHidden = new BoolReactiveProperty(true);
  66. /// <summary>
  67. /// 位置
  68. /// </summary>
  69. public Vector3 position { get; set; }
  70. /// <summary>
  71. /// 转角
  72. /// </summary>
  73. public Vector3 rotation { get; set; }
  74. public int id { get; set; }
  75. public string index { get; set; }
  76. /// <summary>
  77. /// 设备唯一编码
  78. /// </summary>
  79. public int equipmentUniqueID { get; set; }
  80. public string gropName { get; set; }
  81. }
  82. }