Created
April 19, 2013 03:35
-
-
Save anonymous/5417966 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class scriptScreenMainMenu : MonoBehaviour | |
{ | |
public Transform GameManagerSpawn; | |
private GameObject _gameManager; | |
private string[] _currentMenu; | |
private string[] _mainMenu; | |
private string[] _optionsMenu; | |
private string[] _videoMenu; | |
private int _selectedIndex=0; | |
private static float _selectionChangeDelay = 0.5f; | |
private float _selectionCooldownTimer; | |
private bool _keyboardActivateSelection = false; | |
public string Version; | |
void Start() | |
{ | |
_gameManager = GameObject.FindWithTag("GameManager"); | |
if(_gameManager.GetComponent<scriptAudioManager>().ActiveTrack == null) | |
_gameManager.GetComponent<scriptAudioManager>().PlaySong("pew2-title-draft4"); | |
_mainMenu = _currentMenu = new string[4] { "New Game", | |
"Tutorial", | |
"Options", | |
"Quit" }; | |
_optionsMenu = new string[3] { "1280 x 720", | |
"1920 x 1080", | |
"Back"}; | |
_videoMenu = new string[4] { "", | |
"", | |
"", | |
"" }; | |
} | |
void Update() | |
{ | |
float input = Input.GetAxis("VerticalMenu"); | |
if (Input.GetAxis("SelectMenu1") > 0) | |
_keyboardActivateSelection = true; | |
else | |
_keyboardActivateSelection = false; | |
if (input != 0 && _selectionCooldownTimer <= 0) | |
{ | |
if (input > 0) | |
input = 1; | |
else if (input < 0) | |
input = -1; | |
_selectedIndex -= (int)input; | |
if (_selectedIndex < 0) | |
_selectedIndex = _currentMenu.Length - 1; | |
if (_selectedIndex > _currentMenu.Length - 1) | |
_selectedIndex = 0; | |
_selectionCooldownTimer = _selectionChangeDelay; | |
} | |
else if (input == 0) | |
_selectionCooldownTimer = 0; | |
else | |
_selectionCooldownTimer -= Time.deltaTime; | |
} | |
void OnGUI() | |
{ | |
GUILayout.BeginArea(AspectUtility.screenRect); | |
GUI.BeginGroup(new Rect(AspectUtility.screenWidth / 2 - 50, AspectUtility.screenHeight / 2 - 50, 300, 375)); | |
if (_currentMenu == _mainMenu) | |
{ | |
GUI.Box(new Rect(0, 0, 100, 175), "Main Menu"); | |
GUI.SetNextControlName(_mainMenu[0]); | |
if (GUI.Button(new Rect(10, 30, 80, 30), "Start Game") || (_keyboardActivateSelection && _selectedIndex == 0)) | |
_gameManager.GetComponent<scriptGameManager>().LoadLevel("ScreenLoad"); | |
GUI.SetNextControlName(_mainMenu[1]); | |
if (GUI.Button(new Rect(10, 60, 80, 30), "Tutorial") || (_keyboardActivateSelection && _selectedIndex == 1)) | |
_gameManager.GetComponent<scriptGameManager>().LoadLevel("ScreenTutorial"); | |
GUI.SetNextControlName(_mainMenu[2]); | |
if (GUI.Button(new Rect(10, 90, 80, 30), "Options") || (_keyboardActivateSelection && _selectedIndex == 2)) | |
ChangeMenu(_optionsMenu); | |
GUI.SetNextControlName(_mainMenu[3]); | |
if (GUI.Button(new Rect(10, 120, 80, 30), "Exit") || (_keyboardActivateSelection && _selectedIndex == 3)) | |
_gameManager.GetComponent<scriptGameManager>().ToggleQuitPrompt(); | |
} | |
else if (_currentMenu == _optionsMenu) | |
{ | |
GUI.SetNextControlName(_optionsMenu[0]); | |
if (GUI.Button(new Rect(10, 30, 100, 30), "1280 x 720") || (_keyboardActivateSelection && _selectedIndex == 0)) | |
{ | |
Screen.SetResolution(1280, 720, true); | |
AspectUtility.SetCamera(); | |
} | |
GUI.SetNextControlName(_optionsMenu[1]); | |
if (GUI.Button(new Rect(10, 60, 100, 30), "1920 x 1080") || (_keyboardActivateSelection && _selectedIndex == 1)) | |
{ | |
Screen.SetResolution(1920, 1080, true); | |
AspectUtility.SetCamera(); | |
} | |
GUI.SetNextControlName(_optionsMenu[2]); | |
if (GUI.Button(new Rect(10, 120, 100, 30), "Back") || (_keyboardActivateSelection && _selectedIndex == 2)) | |
{ | |
ChangeMenu(_mainMenu); | |
} | |
} | |
else if (_currentMenu == _videoMenu) | |
{ | |
} | |
if(_selectedIndex >=0) | |
GUI.FocusControl(_currentMenu[_selectedIndex]); | |
GUI.EndGroup(); | |
GUI.BeginGroup(new Rect(AspectUtility.screenWidth / 2 - 150, AspectUtility.screenHeight / 2 + 130, 300, 400)); | |
_gameManager.GetComponent<scriptGameManager>().scoreManager.DisplayHighScores(); | |
GUI.EndGroup(); | |
GUI.Label(new Rect(AspectUtility.screenWidth - 200, AspectUtility.screenHeight - 20, 200, 25), "Build Version: " + Version); | |
GUILayout.EndArea(); | |
} | |
private void ChangeMenu(string[] nextMenu) | |
{ | |
_currentMenu = nextMenu; | |
_selectedIndex = -1; | |
//Faking a remove button focus function | |
GUI.SetNextControlName("Deselect"); | |
GUI.Button(new Rect(0, 0, 0, 0), ""); | |
GUI.FocusControl("Deselect"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment