UITreeMenu.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. //------------------------------------------------------------------------------
  2. // <auto-generated>
  3. // This code was generated by a tool.
  4. // Runtime Version:4.0.30319.42000
  5. //
  6. // Changes to this file may cause incorrect behavior and will be lost if
  7. // the code is regenerated.
  8. // </auto-generated>
  9. //------------------------------------------------------------------------------
  10. using UniRx;
  11. namespace QFramework
  12. {
  13. using System;
  14. using System.Collections;
  15. using System.Collections.Generic;
  16. using System.Linq;
  17. using UnityEngine;
  18. using UnityEngine.UI;
  19. using UniRx;
  20. using DG.Tweening;
  21. public class UITreeMenuData : QFramework.UIPanelData
  22. {
  23. //创建树形节点表模型
  24. public Dictionary<string, TreeNodeList> dicTreetGroupNodeList = new Dictionary<string, TreeNodeList>();
  25. }
  26. public partial class UITreeMenu : QFramework.UIPanel
  27. {
  28. //用来存放群组对象
  29. public List<GameObject> groupObj = new List<GameObject>();
  30. UITreeMenuProxy proxy;
  31. protected override void OnInit(QFramework.IUIData uiData)
  32. {
  33. mData = uiData as UITreeMenuData ?? new UITreeMenuData();
  34. //解析数据
  35. proxy = DAL.Instance.Get<UITreeMenuProxy>();
  36. //数据分类
  37. DataClassification(proxy.GetUITreeData());
  38. //TreeNodeData.Instance.Init();
  39. InitUI();
  40. }
  41. private void InitUI()
  42. {
  43. //UI组生成
  44. foreach (var item in mData.dicTreetGroupNodeList)
  45. {
  46. GenerateTreeNode(item.Key.ToString(),item.Value);
  47. }
  48. //
  49. btnClose.onClick.AddListener(() =>
  50. {
  51. UITree.DOMove(MoveForwordTarget.transform.position,0.5f).OnComplete(() => BtnExpand.gameObject.SetActive(true));
  52. });
  53. BtnExpand.onClick.AddListener( ()=>
  54. {
  55. UITree.DOMove(MoveBackTarget.transform.position, 0.5f);
  56. BtnExpand.gameObject.SetActive(false);
  57. });
  58. }
  59. /// <summary>
  60. /// 生成一个下拉列表
  61. /// </summary>
  62. /// <param name="GrenerteName">列表名称</param>
  63. /// <param name="treeNodeList">数据</param>
  64. public GameObject GenerateTreeNode(string grenerteName, TreeNodeList treeNodeList)
  65. {
  66. GameObject tmpScrollObj = Instantiate<GameObject>(ScrollPrefab.gameObject, UITreeCtrl.transform, false);
  67. tmpScrollObj.name = grenerteName;
  68. Transform tmpContent = tmpScrollObj.transform.Find("Viewport/Content");
  69. UINodeListCtrl tmpCtrl = tmpContent.GetComponent<UINodeListCtrl>();
  70. tmpCtrl.SetGroupInfo(tmpContent.GetComponent<ToggleGroup>());
  71. tmpCtrl.GenerateTreeNodeList(UITreeNode01, UITreeNode02, treeNodeList);
  72. groupObj.Add(tmpScrollObj);
  73. return tmpScrollObj;
  74. }
  75. /// <summary>
  76. /// 数据表分类
  77. /// </summary>
  78. public void DataClassification(List<TreeNodeInfo> infos)
  79. {
  80. SortTreeNodelist(infos);
  81. foreach (var item in infos)
  82. {
  83. if (!mData.dicTreetGroupNodeList.ContainsKey(item.m_GroupName))
  84. {
  85. TreeNodeList tmpTreeNodeItems = new TreeNodeList();
  86. mData.dicTreetGroupNodeList.Add(item.m_GroupName, tmpTreeNodeItems);
  87. }
  88. CheckAndAddToDic(item,item.m_GroupName);
  89. }
  90. }
  91. /// <summary>
  92. /// 检查并将自己添加到分组中
  93. /// </summary>
  94. /// <param name="item">按钮信息</param>
  95. /// <param name="groupName">组名</param>
  96. /// <param name="parentNodeName">父节点名字</param>
  97. /// <returns></returns>
  98. public void CheckAndAddToDic(TreeNodeInfo treeNodeInfo,string groupName)
  99. {
  100. //父级不为空并且父级不在储存列表中
  101. if (!string.IsNullOrEmpty(treeNodeInfo.m_NodeParentName))
  102. {
  103. if (mData.dicTreetGroupNodeList[groupName].treeNodeItems.Find(t => t.Content.Value == treeNodeInfo.m_NodeParentName) == null)
  104. {
  105. List<TreeNodeInfo> tmpInfos = proxy.GetUITreeData();
  106. TreeNodeInfo tmpInfo = tmpInfos.Find(t => t.m_NodeName == treeNodeInfo.m_NodeParentName);
  107. CheckAndAddToDic(tmpInfo, groupName);
  108. }
  109. }
  110. TreeNodeItem tempItem = new TreeNodeItem();
  111. tempItem.Content.Value = treeNodeInfo.m_NodeName;
  112. tempItem.ParentName.Value = string.IsNullOrEmpty(treeNodeInfo.m_NodeParentName) ? null : treeNodeInfo.m_NodeParentName;
  113. tempItem.Layer.Value = treeNodeInfo.m_NodeLayer;
  114. tempItem.id = treeNodeInfo.m_Id;
  115. tempItem.equipmentUniqueID = treeNodeInfo.m_EquipmentUniqueID;
  116. tempItem.gropName = treeNodeInfo.m_GroupName;
  117. mData.dicTreetGroupNodeList[groupName].AddTreeNode(tempItem);
  118. }
  119. private GameObject currentGroup = null;
  120. /// <summary>
  121. ///重新对数据进行拍寻
  122. /// </summary>
  123. public void SortTreeNodelist(List<TreeNodeInfo> infos)
  124. {
  125. for (int i = 0; i < infos.Count; i++)
  126. {
  127. for (int j = 0; j < infos.Count - 1 - i; j++)
  128. {
  129. if (infos[j].m_Id > infos[j + 1].m_Id)
  130. {
  131. TreeNodeInfo tmpItem = infos[j];
  132. infos[j] = infos[j + 1];
  133. infos[j + 1] = tmpItem;
  134. }
  135. }
  136. }
  137. }
  138. protected override void OnOpen(QFramework.IUIData uiData)
  139. {
  140. }
  141. protected override void OnShow()
  142. {
  143. }
  144. protected override void OnHide()
  145. {
  146. }
  147. protected override void OnClose()
  148. {
  149. }
  150. public void SetMode(string model)
  151. {
  152. if (currentGroup != null) currentGroup.SetActive(false);
  153. GameObject tmpObj = groupObj.Find(t => t.name == model);
  154. if (tmpObj != null)
  155. {
  156. currentGroup = tmpObj;
  157. tmpObj.SetActive(true);
  158. }
  159. }
  160. }
  161. }