示例#1
0
        public void Update()
        {
            if (Input.GetKeyDown(KeyCode.Keypad0))
            {
                isOpen = !isOpen;
            }

            if (!isOpen)
            {
                return;
            }

            if (Input.GetKeyDown(KeyCode.Keypad2))
            {
                selectedIndex++;

                bool wrap = !inSection && selectedIndex >= menuButtons.Count ||
                            inSection && selectedIndex >= currentSection.GetChildren().Count;

                if (wrap)
                {
                    selectedIndex = 0;
                }
            }

            if (Input.GetKeyDown(KeyCode.Keypad8))
            {
                selectedIndex--;
                if (selectedIndex < 0)
                {
                    if (inSection)
                    {
                        selectedIndex = currentSection.GetChildren().Count - 1;
                    }
                    else
                    {
                        selectedIndex = menuButtons.Count - 1;
                    }
                }
            }

            if (Input.GetKeyDown(KeyCode.Keypad5) || Input.GetKeyDown(KeyCode.KeypadEnter))
            {
                Button buttonToExecute;

                if (!inSection)
                {
                    buttonToExecute = (Button)menuButtons[selectedIndex];
                }
                else
                {
                    buttonToExecute = (Button)currentSection.GetChildren()[selectedIndex];
                }

                if (buttonToExecute is SectionButton sectionButton)
                {
                    currentSection = sectionButton;
                    selectedIndex  = 0;
                    inSection      = true;
                }
                else
                {
                    buttonToExecute.Execute();
                }
            }

            if (Input.GetKeyDown(KeyCode.KeypadMinus))
            {
                if (inSection)
                {
                    if (currentSection.HasParent())
                    {
                        selectedIndex  = 0;
                        currentSection = currentSection.GetParent();
                    }
                    else
                    {
                        selectedIndex  = 0;
                        inSection      = false;
                        currentSection = null;
                    }
                }
            }
        }
示例#2
0
 public void SetParent(SectionButton parent)
 {
     this.parent = parent;
     hasParent   = true;
 }