Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        /// <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);
                }
            }
        }