// Creates one page worth of level buttons for a given page. Sets their names // and properties, and makes sure they're in the correct part of the window. // Also removes any existing level buttons. void SpawnLevelButtons(int page) { ClearCurrentButtons(); int maxButtonIndex = (currentPage + 1) * ButtonsPerPage; if (maxButtonIndex > levelNames.Length) { maxButtonIndex = levelNames.Length; } for (int i = currentPage * ButtonsPerPage; i < maxButtonIndex; i++) { GameObject button = GameObject.Instantiate( CommonData.prefabs.menuLookup[StringConstants.PrefabsLevelSelectButton]); Menus.LevelSelectButtonGUI component = button.GetComponent <Menus.LevelSelectButtonGUI>(); if (component != null) { component.buttonId = i; levelButtons[i] = button; button.transform.SetParent(menuComponent.Panel.transform, false); component.ButtonText.text = levelNames[i]; } else { Debug.LogError("Level select button prefab had no LevelSelectButtionGUI component."); } gui.transform.SetParent(CommonData.mainCamera.transform, false); } SetButtonColors(mapSelection); }
public override void HandleUIEvent(GameObject source, object eventData) { Menus.LevelSelectButtonGUI buttonComponent = source.GetComponent <Menus.LevelSelectButtonGUI>(); if (source == menuComponent.CancelButton.gameObject) { CancelButtonPressed(); } else if (source == menuComponent.TopTimesButton.gameObject) { manager.PushState(new TopTimes(null)); } else if (source == menuComponent.PlayButton.gameObject) { manager.PushState(new Gameplay(Gameplay.GameplayMode.Gameplay)); } else if (source == menuComponent.BackButton.gameObject) { ChangePage(-1); } else if (source == menuComponent.ForwardButton.gameObject) { ChangePage(1); } else if (buttonComponent != null) { // They pressed one of the buttons for a level. mapSelection = buttonComponent.buttonId; SetButtonColors(mapSelection); LevelSelected(mapSelection); } }
protected void SetButtonColors(int selection) { foreach (KeyValuePair <int, GameObject> pair in levelButtons) { Menus.LevelSelectButtonGUI levelSelectButton = pair.Value.GetComponent <Menus.LevelSelectButtonGUI>(); levelSelectButton.ButtonText.color = (levelSelectButton.buttonId == selection) ? SelectedButtonColor : ActiveButtonColor; } }