// call this to activate the selected button public void ActivateButton() { // get the activated button (execute might change this so grab it now) var activatedButton = m_buttonList[m_selectedButtonIndex]; // execute the current button and check if it returned true if (activatedButton.Execute()) { // update the current button m_currentButton = activatedButton; // do the first update m_currentButton.Update(); } }
// unity update void Update() { // don't do anything if the game is paused if (SpaceflightController.m_instance.m_gameIsPaused) { return; } // check if we are activating the currently selected button if (m_activatingButton) { // yes - so update the timer m_activatingButtonTimer += Time.deltaTime; // after a certain amount of time, execute the button if (m_activatingButtonTimer >= 0.35f) { // reset the activate button flag and timer m_activatingButton = false; m_activatingButtonTimer = 0.0f; ActivateButton(); } return; } // check if we have a current funciton if (m_currentButton != null) { // call update on it if (m_currentButton.Update()) { // the button did the update - don't let this update do anything more return; } } // check if we moved the stick down if (InputController.m_instance.m_south) { if (m_ignoreControllerTimer == 0.0f) { m_ignoreControllerTimer = 0.3f; if (m_selectedButtonIndex < (m_buttonList.Length - 1)) { if (m_buttonList[m_selectedButtonIndex + 1] != null) { m_selectedButtonIndex++; UpdateButtonSprites(); SoundController.m_instance.PlaySound(SoundController.Sound.Click); } } } } else if (InputController.m_instance.m_north) // check if we have moved the stick up { if (m_ignoreControllerTimer == 0.0f) { m_ignoreControllerTimer = 0.3f; if (m_selectedButtonIndex > 0) { m_selectedButtonIndex--; UpdateButtonSprites(); SoundController.m_instance.PlaySound(SoundController.Sound.Click); } } } else // we have centered the stick { m_ignoreControllerTimer = 0.0f; } // check if we have pressed the fire button if (InputController.m_instance.m_submit) { InputController.m_instance.Debounce(); if (m_buttonList[m_selectedButtonIndex] == null) { SoundController.m_instance.PlaySound(SoundController.Sound.Error); } else { // set the activate button flag and reset the timer m_activatingButton = true; m_activatingButtonTimer = 0.0f; // update the button sprite for the currently selected button m_buttonImageList[m_selectedButtonIndex].sprite = m_buttonActiveSprite; // play the activate sound SoundController.m_instance.PlaySound(SoundController.Sound.Activate); } } }