//------------------------------------------------------------------------------ // // 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. // //------------------------------------------------------------------------------ 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 dicTreetGroupNodeList = new Dictionary(); } public partial class UITreeMenu : QFramework.UIPanel { //用来存放群组对象 public List groupObj = new List(); UITreeMenuProxy proxy; protected override void OnInit(QFramework.IUIData uiData) { mData = uiData as UITreeMenuData ?? new UITreeMenuData(); //解析数据 proxy = DAL.Instance.Get(); //数据分类 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); }); } /// /// 生成一个下拉列表 /// /// 列表名称 /// 数据 public GameObject GenerateTreeNode(string grenerteName, TreeNodeList treeNodeList) { GameObject tmpScrollObj = Instantiate(ScrollPrefab.gameObject, UITreeCtrl.transform, false); tmpScrollObj.name = grenerteName; Transform tmpContent = tmpScrollObj.transform.Find("Viewport/Content"); UINodeListCtrl tmpCtrl = tmpContent.GetComponent(); tmpCtrl.SetGroupInfo(tmpContent.GetComponent()); tmpCtrl.GenerateTreeNodeList(UITreeNode01, UITreeNode02, treeNodeList); groupObj.Add(tmpScrollObj); return tmpScrollObj; } /// /// 数据表分类 /// public void DataClassification(List 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); } } /// /// 检查并将自己添加到分组中 /// /// 按钮信息 /// 组名 /// 父节点名字 /// 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 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; /// ///重新对数据进行拍寻 /// public void SortTreeNodelist(List 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); } } } }