public void Back() { MenuGameObject menuGameObject = currentObjectOnDisplay.GetComponent <MenuGameObject>(); menuGameObject.previousScreen.SetActive(true); currentObjectOnDisplay.SetActive(false); currentObjectOnDisplay = menuGameObject.previousScreen; PlayButtonSound(); }
public void GenerateCommandMenu(PlayerAbilities playerAbilities) { GameObject playerGameObject = playerAbilities.gameObject; List <PlayerAbility> abilityList = playerAbilities.PlayerAbilityList; GameObject panelGameObject = null; if (MenuGameObject != null) { panelGameObject = GetMenuPanelGameObject(); MenuGameObject.SetActive(true); Button[] menuButtons = panelGameObject.GetComponentsInChildren <Button>(); foreach (Button button in menuButtons) { Destroy(button.gameObject); } } else { MenuGameObject = Instantiate(commandMenuModel, Vector3.zero, Quaternion.identity); } this.SetMenuPosition(playerGameObject); panelGameObject = GetMenuPanelGameObject(); MenuButtons = new List <GameObject>(); SubMenuButtons = new List <GameObject>(); GameObject specialButtonGameObject = null; if (playerAbilities.HasSpecialAbilities) { specialButtonGameObject = Instantiate(buttonModel, panelGameObject.transform.position, panelGameObject.transform.rotation); specialButtonGameObject.name = "special ability button"; } bool isSpecialButonInitialized = false; foreach (PlayerAbility ability in abilityList) { GameObject buttonGameObject = Instantiate(buttonModel, panelGameObject.transform.position, panelGameObject.transform.rotation); buttonGameObject.name = ability.AbilityName; TextMeshProUGUI buttonText = buttonGameObject.GetComponentInChildren <TextMeshProUGUI>(); PlayerAbility.AbilityDelegate playerActions; buttonText.text = ability.AbilityName; switch (ability.AbilityType) { case AbilityTypeEnum.BASIC: if (ability.IsCommandPhaseMandatory) { playerActions = DisableMenuLight; } else { playerActions = DisableMenu; } playerActions += ability.AbilityAction; this.AllocateAbilities(ability, buttonGameObject, MenuButtons, playerActions, true); break; case AbilityTypeEnum.SPECIAL: if (ability.AbilityCategory == AbilityCategoryEnum.NORMAL) { if (!isSpecialButonInitialized) { TextMeshProUGUI specialButtonText = specialButtonGameObject.GetComponentInChildren <TextMeshProUGUI>(); Button specialButtonComponent = specialButtonGameObject.GetComponent <Button>(); specialButtonComponent.onClick.AddListener(() => DisplaySubMenu()); specialButtonText.text = "Special Ability"; specialButtonGameObject.transform.SetParent(panelGameObject.transform); MenuButtons.Add(specialButtonComponent.gameObject); isSpecialButonInitialized = true; } playerActions = ability.AbilityAction; playerActions = CalculateDisableBehaviour(ability, playerActions); this.AllocateAbilities(ability, buttonGameObject, SubMenuButtons, playerActions, false); } else if (ability.AbilityCategory == AbilityCategoryEnum.UI) { playerActions = HideSubMenu; this.AllocateAbilities(ability, buttonGameObject, SubMenuButtons, playerActions, false); } break; default: break; } buttonGameObject.transform.SetParent(panelGameObject.transform); } isFirstDisplay = false; }