//This toggles whether the gameplay system will only accept configured buttons (standard), or any button (when configuring) public void ToggleButtonConfigState() { if (gameState == e_GameState.BUTTONCONFIGMENU) { gameState = e_GameState.BUTTONCONFIGMENUANYINPUT; } else { gameState = e_GameState.BUTTONCONFIGMENU; } }
// Use this for initialization void Start() { inputStorageArray = new GenericInput[(int)Header.e_ButtonAction.MAXNUMINPUT]; //check if file with config values exist if (!System.IO.File.Exists(Application.dataPath + InputConfigLocation)) { FillDefaultMenuValues(); } else //read values from file { string line; StreamReader streamR = new StreamReader(Application.dataPath + InputConfigLocation, Encoding.Default); int inputCounter = 0; using (streamR) { line = streamR.ReadLine(); while (line != null) { string[] lineTokenArray = line.Split(' '); //0 = discard //1 = key1 //2 = key2 //need to check each entry before filling them in to make sure they're valid bool entry1Found = false; bool entry2Found = false; bool allEntriesValid = false; for (int i = 0; i < (int)Controls.e_KeyButtonName.MAXNUMKEYBUTTON; i++) { if (!entry1Found) { entry1Found = lineTokenArray [1] == Header.keyButtonNames [i]; } if (!entry2Found) { entry2Found = lineTokenArray [2] == Header.keyButtonNames [i]; } if (entry1Found && entry2Found) { allEntriesValid = true; break; } } if (allEntriesValid) { bool inputStringAlreadyUsed = false; for (int i = 0; i < inputCounter; i++) { //check to make sure no repeated strings if (inputStorageArray [i].nameOfInputAxis == lineTokenArray [1] || inputStorageArray [i].nameOfInputAxis == lineTokenArray [2] || inputStorageArray [i].nameOfInputAxis2 == lineTokenArray [1] || inputStorageArray [i].nameOfInputAxis2 == lineTokenArray [2]) { //error in reading, use default values Debug.Log("Unable to read all saved input values"); FillDefaultMenuValues(); inputStringAlreadyUsed = true; break; } } if (inputStringAlreadyUsed) { break; } //set read values to inputStorageArray inputStorageArray [inputCounter] = new GenericInput((Header.e_ButtonAction)inputCounter, GetFunc(inputCounter), lineTokenArray [1], lineTokenArray [2]); inputCounter++; } else { //error in reading, use default values Debug.Log("Unable to read all saved input values"); FillDefaultMenuValues(); break; } line = streamR.ReadLine(); } } if (inputCounter != (int)Header.e_ButtonAction.MAXNUMINPUT) { //error in reading, use default values Debug.Log("File has incorrect number of lines"); FillDefaultMenuValues(); } } //get all reference components menuReferenceComponent = menuReference.GetComponent <ConfigMenu> (); //temp until an entry screen is made gameState = e_GameState.BUTTONCONFIGMENU; //set up menu now that inputs are confirmed //menuReferenceComponent.InitializeMenu (); }