/// <summary> /// 设置标签上显示的文字 /// </summary> /// <param name="vo"></param> public void setValue(MyTreeMenuItemVO vo, MyTreeMenuItem parent) { treeMenu = NGUITools.FindInParents <MyTreeMenu>(gameObject); this.parent = parent; this.value = vo; lable.text = vo.name; }
/// <summary> /// 进度条定位到指定节点位置 /// </summary> /// <param name="item"></param> public void Locate(string value, bool isMenu, bool isFoldMenu = true) { MyTreeMenuItem clickItem = nodes[value]; currentItem = clickItem; List <MyTreeMenuItem> items = clickItem.getParents(); if (!isFoldMenu) { clickItem.foldAllChildMenuNode(true); } //foreach (MyTreeMenuItem item in nodes.Values) //{ // if(!items.Contains(item)) // item.allFoldNode(); //} //if (items.Count > 0) //{ // for (int i = items.Count - 1; i >= 0; i--) // { // items[i].foldMenuNode(false); // } //} menuClick(clickItem.gameObject, isMenu, true, isFoldMenu); //menuClick(clickItem.gameObject, value, false); //clickItem.foldMenuNode(false); int count = treeGrid.GetChildList().Count; float progress = (float)treeGrid.GetIndex(currentItem.transform) / count; scrollBar.value = progress; scrollBarChange(); treeGrid.repositionNow = true; treeGrid.Reposition(); }
public List <MyTreeMenuItem> getParents() { List <MyTreeMenuItem> items = new List <MyTreeMenuItem>(); if (parent != null) { items.Add(parent); MyTreeMenuItem item = null; while (true) { if (item == null) { item = parent.getParent(); } else { item = item.getParent(); } if (item == null) { break; } items.Add(item); } } return(items); }
private void setValue(List <MyTreeMenuItemVO> menuItemVO, MyTreeMenuItem parent, int level, string firstStr) { List <MyTreeMenuItem> items = new List <MyTreeMenuItem>(); foreach (MyTreeMenuItemVO item in menuItemVO) { GameObject obj = getPrefab("MyUI/TreeMenuItem"); GameObject menuItem = generate(treeGrid.transform, obj, Vector3.one, Vector3.zero, Vector3.zero); string name = ""; if (firstStr != null) { name = firstStr + "_" + item.ItemName; } else { name = item.ItemName; } menuItem.name = name; MyTreeMenuItem treeMenuItem = menuItem.GetComponent <MyTreeMenuItem>(); treeMenuItem.setValue(item, parent); items.Add(treeMenuItem); menuItem.GetComponent <MyUIDragScrollView>().scrollView = scrollView;//不太懂 if (parent != null) { parent.addNode(treeMenuItem); } else { rootNodes.Add(item.value, treeMenuItem); } nodes.Add(item.value, treeMenuItem); if (item.treeMenuItemVO != null && item.treeMenuItemVO.Count > 0) //双重保险吗? { treeMenuItem.sprite.spriteName = myTreeItemFold[level]; //取。。。 treeMenuItem.setIsLeafNode(false, level); treeMenuItem.lable.fontSize = myTreeItemFontSize[level]; treeMenuItem.lable.color = myTreeItemTextColor[level]; parents.Add(name, treeMenuItem); setValue(item.treeMenuItemVO, treeMenuItem, level + 1, name);//递归 } else { treeMenuItem.sprite.spriteName = myTreeItemChildNode[level]; treeMenuItem.setIsLeafNode(true, level); treeMenuItem.lable.fontSize = myTreeItemFontSize[level]; leafNodes.Add(name, treeMenuItem); } } foreach (MyTreeMenuItem item in items) { item.allFoldNode(); } treeGrid.repositionNow = true; treeGrid.Reposition(); }
public void removeNode(MyTreeMenuItem item) { if (Nodes == null) { Nodes = new List <MyTreeMenuItem>(); } if (Nodes.Contains(item)) { Nodes.Remove(item); } }
public void foldPartChildMenuNode(MyTreeMenuItem exclude) { foreach (MyTreeMenuItem item in Nodes) { if (item == exclude) { continue; } item.foldMenuNode(true); } }
public void addNode(MyTreeMenuItem item) { if (Nodes == null) { Nodes = new List <MyTreeMenuItem>(); itemState = new Dictionary <MyTreeMenuItem, bool>(); } if (Nodes.Contains(item)) { Debug.LogWarning("已经存在该菜单节点"); } else { Nodes.Add(item); itemState.Add(item, false); } }
/// <summary> /// 菜单某个节点被点击时 /// </summary> /// <param name="obj"></param> /// <param name="value"></param> /// <param name="isTriggerEvent">是否出发点击事件</param> /// <param name="isFoldMenu">是否折叠被点击的非叶子节点菜单</param> public void menuClick(GameObject obj, bool isMenu, bool isTriggerEvent = true, bool isFoldMenu = true) { this.currentItem = obj.GetComponent <MyTreeMenuItem>(); string value = currentItem.getItemVO().value; if (currentItem.getIsLeafNode()) { //Debug.Log(obj.name); if (leafNodesClickEvent != null && isTriggerEvent) { leafNodesClickEvent(value, isMenu); } if (currentLeafItem != null) { currentLeafItem.sprite.spriteName = myTreeItemChildNode[currentLeafItem.getNodeLevel()]; } currentLeafItem = obj.GetComponent <MyTreeMenuItem>(); currentLeafItem.sprite.spriteName = myTreeItemChildNodeSelect[currentLeafItem.getNodeLevel()]; if (currentItem.getParent() != null) { currentItem.getParent().foldPartChildMenuNode(currentItem); } else { foreach (MyTreeMenuItem item in rootNodes.Values) { if (item != currentItem) { item.foldMenuNode(true); } } } } else if (isParent) { if (isFoldMenu) { currentItem.foldMenuNode(); if (currentItem.getParent() != null) { currentItem.getParent().foldPartChildMenuNode(currentItem); } else { foreach (MyTreeMenuItem item in rootNodes.Values) { if (item != currentItem) { item.foldMenuNode(true); } //currentItem.sprite.spriteName = myTreeItemNoFold[currentItem.getNodeLevel()];//添加的 } } } if (currentLeafItem != null) { currentLeafItem.sprite.spriteName = myTreeItemChildNode[currentLeafItem.getNodeLevel()]; } if (leafNodesClickEvent != null && isTriggerEvent) { leafNodesClickEvent(value, isMenu); } } }