Beispiel #1
0
    public void CreateMenuTree()
    {
        int         curLevelNum = 1;
        GameObject  newLevel    = (GameObject)Instantiate(buildMenuLevel, transform.position, transform.rotation, buildMenuContainer.transform);
        UIMenuLevel curLevel    = new UIMenuLevel(newLevel);
        UIMenuLevel rootLevel   = curLevel;

        for (int i = 0; i < menuArray.Length; i++)
        {
            MenuNode    item      = menuArray[i];
            UIMenuLevel nextLevel = curLevel;
            if (item.level > curLevelNum)
            {
                GameObject  newLevelObj = (GameObject)Instantiate(buildMenuLevel, transform.position, transform.rotation, buildMenuContainer.transform);
                UIMenuLevel newNode     = new UIMenuLevel(curLevel, newLevelObj);
                curLevel.children.Add(newNode);
                nextLevel = newNode;
            }
            else if (item.level < curLevelNum)
            {
                nextLevel = curLevel;
                for (int k = 0; k < (curLevelNum - item.level); k++)
                {
                    nextLevel = nextLevel.parent;
                }
            }

            GameObject newButton = (GameObject)Instantiate(buildMenuItem, transform.position, transform.rotation);
            newButton.transform.GetChild(0).gameObject.GetComponent <Image>().sprite = item.icon;
            newButton.transform.SetParent(nextLevel.level.transform, false);
            Button butt = newButton.GetComponent <Button>();
            if (item.isLeaf)
            {
                BuildableTile bTile = item.building.GetBuildableTile();
                butt.onClick.AddListener(() => ClickedLeafNode(bTile));
            }
            else
            {
                butt.onClick.AddListener(() => ClickedNonLeafNode(newButton.transform.GetSiblingIndex(), item.level));
            }
            curLevel    = nextLevel;
            curLevelNum = item.level;
        }
        buildMenuContainer.GetComponent <LayoutGroup>().SetLayoutHorizontal();
        LayoutRebuilder.ForceRebuildLayoutImmediate(buildMenuContainer.GetComponent <RectTransform>());
        for (int i = 1; i < buildMenuContainer.transform.childCount; i++)
        {
            buildMenuContainer.transform.GetChild(i).gameObject.SetActive(false);
        }
        buildMenuContainer.SetActive(false);
        curMenuNode = rootLevel;
        curLevelInt = 1;
    }
Beispiel #2
0
 public void HideBuildMenu()
 {
     for (int i = 1; i < buildMenuContainer.transform.childCount; i++)
     {
         buildMenuContainer.transform.GetChild(i).gameObject.SetActive(false);
     }
     while (curMenuNode.parent != null)
     {
         curMenuNode = curMenuNode.parent;
     }
     buildMenuContainer.SetActive(false);
     curLevelInt = 1;
 }
Beispiel #3
0
 public void ClickedNonLeafNode(int childNum, int level)
 {
     mm.StartRunMode();
     if (level < curLevelInt)
     {
         for (int i = 0; i < (curLevelInt - level); i++)
         {
             curMenuNode.level.SetActive(false);
             curMenuNode = curMenuNode.parent;
         }
         curLevelInt -= (curLevelInt - level);
     }
     curMenuNode = curMenuNode.children[childNum];
     curMenuNode.level.SetActive(true);
     curLevelInt++;
 }
Beispiel #4
0
 public UIMenuLevel(GameObject level)
 {
     this.parent = null;
     this.level  = level;
     children    = new List <UIMenuLevel>();
 }
Beispiel #5
0
 public UIMenuLevel(UIMenuLevel parent, GameObject level)
 {
     this.parent = parent;
     this.level  = level;
     children    = new List <UIMenuLevel>();
 }