/// <summary> /// Awake this instance. /// </summary> void Awake() { stingPlayer = GameObject.FindGameObjectWithTag("GameTools").GetComponent <StingPlayer>(); // gets the panels and displays them for the main menu instanceItem = Toolbox.Instance; currentState = MENU_STATES.START; selectedItem = 0; mainMenuItems = mainMenuPanels.GetComponentsInChildren <Button> (); mainMenuItems [0].Select(); saveFilesItems = loadGamePanels.GetComponentsInChildren <Button> (true); //skipLoadGame = SaveLoad.isAnySavedGame (); // load our current save load SaveLoad.Load(); // load saved games SaveLoad.CreatedSavedGamesArray(); // now, if we already have games, we also want to display them differently. // so let's do that updateGamePanel(); }
// display panel and allow selection of options for saving a game or // loading a game // we should have up to three games saved. // and they should have different attributes. Let's see if we can // save transform as well. public void ShowMainMenu() { // choose which panels show loadGamePanels.SetActive(false); mainMenuPanels.SetActive(true); // change the state selectedItem = 0; currentState = MENU_STATES.START; instanceItem.isLocked = false; mainMenuItems [0].Select(); // if we have no games to load, then make sure that we don't have our // load game button working if (!SaveLoad.isAnySavedGame()) { mainMenuItems [1].enabled = false; } else { mainMenuItems [1].enabled = true; } }
/// <summary> /// Hides the panels. /// </summary> public void ShowGamePanel() { // choose which panels are visible loadGamePanels.SetActive(true); mainMenuPanels.SetActive(false); // change the state currentState = MENU_STATES.NEW_GAME; selectedItem = 0; instanceItem.isLocked = false; saveFilesItems [0].Select(); }
/// <summary> /// Main Menu key was pressed /// </summary> /// <param name="keyPressed">Key pressed.</param> public void MainMenuKeypress(string keyPressed) { if (keyPressed.Equals("up")) { selectedItem--; // for now, the item is just 0 if (selectedItem < 0) { // set the selected item at the end // right now, we have 2 save files selectedItem = mainMenuItems.Length - 1; } if (!SaveLoad.isAnySavedGame() && selectedItem == 1) { selectedItem = 0; } mainMenuItems [selectedItem].Select(); } // if key pressed is down, increment our index to travel down // the menu else if (keyPressed.Equals("down")) { selectedItem++; if (selectedItem >= mainMenuItems.Length) { selectedItem = 0; } if (!SaveLoad.isAnySavedGame() && selectedItem == 1) { selectedItem = 2; } mainMenuItems [selectedItem].Select(); } // if moving forward: check our index and determine which item to load else if (keyPressed.Equals("forward")) { // check which number we are on if (selectedItem == 0) { ShowGamePanel(); currentState = MENU_STATES.NEW_GAME; // if we have a sting source, play sting if (stingPlayer != null) { stingPlayer.playSelectItemSound(); } } else if (selectedItem == 1) { ShowGamePanel(); currentState = MENU_STATES.LOAD; // if we have a sting source, play sting if (stingPlayer != null) { stingPlayer.playSelectItemSound(); } } // otherwise, if we select the last element, exit the game else if (selectedItem == 3) { Application.Quit(); } } }