123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- //------------------------------------------------------------------------------
- // <auto-generated>
- // This code was generated by a tool.
- // Runtime Version:4.0.30319.42000
- //
- // Changes to this file may cause incorrect behavior and will be lost if
- // the code is regenerated.
- // </auto-generated>
- //------------------------------------------------------------------------------
- using UniRx;
- namespace QFramework
- {
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using UnityEngine;
- using UnityEngine.UI;
- using UniRx;
- using DG.Tweening;
- public class UITreeMenuData : QFramework.UIPanelData
- {
- //创建树形节点表模型
- public Dictionary<string, TreeNodeList> dicTreetGroupNodeList = new Dictionary<string, TreeNodeList>();
- }
- public partial class UITreeMenu : QFramework.UIPanel
- {
- //用来存放群组对象
- public List<GameObject> groupObj = new List<GameObject>();
- UITreeMenuProxy proxy;
-
- protected override void OnInit(QFramework.IUIData uiData)
- {
- mData = uiData as UITreeMenuData ?? new UITreeMenuData();
-
- //解析数据
- proxy = DAL.Instance.Get<UITreeMenuProxy>();
- //数据分类
- DataClassification(proxy.GetUITreeData());
- //TreeNodeData.Instance.Init();
-
- InitUI();
- }
-
- private void InitUI()
- {
- //UI组生成
- foreach (var item in mData.dicTreetGroupNodeList)
- {
- GenerateTreeNode(item.Key.ToString(),item.Value);
- }
- //
- btnClose.onClick.AddListener(() =>
- {
- UITree.DOMove(MoveForwordTarget.transform.position,0.5f).OnComplete(() => BtnExpand.gameObject.SetActive(true));
- });
- BtnExpand.onClick.AddListener( ()=>
- {
- UITree.DOMove(MoveBackTarget.transform.position, 0.5f);
- BtnExpand.gameObject.SetActive(false);
- });
- }
- /// <summary>
- /// 生成一个下拉列表
- /// </summary>
- /// <param name="GrenerteName">列表名称</param>
- /// <param name="treeNodeList">数据</param>
- public GameObject GenerateTreeNode(string grenerteName, TreeNodeList treeNodeList)
- {
- GameObject tmpScrollObj = Instantiate<GameObject>(ScrollPrefab.gameObject, UITreeCtrl.transform, false);
- tmpScrollObj.name = grenerteName;
- Transform tmpContent = tmpScrollObj.transform.Find("Viewport/Content");
- UINodeListCtrl tmpCtrl = tmpContent.GetComponent<UINodeListCtrl>();
- tmpCtrl.SetGroupInfo(tmpContent.GetComponent<ToggleGroup>());
- tmpCtrl.GenerateTreeNodeList(UITreeNode01, UITreeNode02, treeNodeList);
- groupObj.Add(tmpScrollObj);
- return tmpScrollObj;
- }
- /// <summary>
- /// 数据表分类
- /// </summary>
- public void DataClassification(List<TreeNodeInfo> infos)
- {
- SortTreeNodelist(infos);
- foreach (var item in infos)
- {
- if (!mData.dicTreetGroupNodeList.ContainsKey(item.m_GroupName))
- {
- TreeNodeList tmpTreeNodeItems = new TreeNodeList();
- mData.dicTreetGroupNodeList.Add(item.m_GroupName, tmpTreeNodeItems);
- }
- CheckAndAddToDic(item,item.m_GroupName);
- }
- }
- /// <summary>
- /// 检查并将自己添加到分组中
- /// </summary>
- /// <param name="item">按钮信息</param>
- /// <param name="groupName">组名</param>
- /// <param name="parentNodeName">父节点名字</param>
- /// <returns></returns>
- public void CheckAndAddToDic(TreeNodeInfo treeNodeInfo,string groupName)
- {
- //父级不为空并且父级不在储存列表中
- if (!string.IsNullOrEmpty(treeNodeInfo.m_NodeParentName))
- {
- if (mData.dicTreetGroupNodeList[groupName].treeNodeItems.Find(t => t.Content.Value == treeNodeInfo.m_NodeParentName) == null)
- {
- List<TreeNodeInfo> tmpInfos = proxy.GetUITreeData();
- TreeNodeInfo tmpInfo = tmpInfos.Find(t => t.m_NodeName == treeNodeInfo.m_NodeParentName);
- CheckAndAddToDic(tmpInfo, groupName);
- }
- }
- TreeNodeItem tempItem = new TreeNodeItem();
- tempItem.Content.Value = treeNodeInfo.m_NodeName;
- tempItem.ParentName.Value = string.IsNullOrEmpty(treeNodeInfo.m_NodeParentName) ? null : treeNodeInfo.m_NodeParentName;
- tempItem.Layer.Value = treeNodeInfo.m_NodeLayer;
- tempItem.id = treeNodeInfo.m_Id;
- tempItem.equipmentUniqueID = treeNodeInfo.m_EquipmentUniqueID;
- tempItem.gropName = treeNodeInfo.m_GroupName;
- mData.dicTreetGroupNodeList[groupName].AddTreeNode(tempItem);
- }
- private GameObject currentGroup = null;
- /// <summary>
- ///重新对数据进行拍寻
- /// </summary>
- public void SortTreeNodelist(List<TreeNodeInfo> infos)
- {
- for (int i = 0; i < infos.Count; i++)
- {
- for (int j = 0; j < infos.Count - 1 - i; j++)
- {
- if (infos[j].m_Id > infos[j + 1].m_Id)
- {
- TreeNodeInfo tmpItem = infos[j];
- infos[j] = infos[j + 1];
- infos[j + 1] = tmpItem;
- }
- }
- }
- }
- protected override void OnOpen(QFramework.IUIData uiData)
- {
- }
- protected override void OnShow()
- {
- }
- protected override void OnHide()
- {
- }
- protected override void OnClose()
- {
- }
- public void SetMode(string model)
- {
- if (currentGroup != null) currentGroup.SetActive(false);
-
- GameObject tmpObj = groupObj.Find(t => t.name == model);
- if (tmpObj != null)
- {
- currentGroup = tmpObj;
- tmpObj.SetActive(true);
- }
- }
- }
- }
|