private void Update() { if (!isPlayer1Input && currentState == CheckState.Player1Needed) { toolTip.text = askUserToInputString; if (ControllerControls.ButtonPress(Players.P1, ControllerButtons.A)) { isPlayer1Input = true; controlIcons[0].enabled = true; currentState = CheckState.Player2Needed; SaveManager.SaveArcadeControlScheme(SupportedControllers.KeyboardP2ControllerP1); newScheme = SupportedControllers.KeyboardP2ControllerP1; toolTip.text = controllerSelected; } else if (KeyboardControls.ButtonPress(Players.P1, Buttons.B8)) { isPlayer1Input = true; controlIcons[1].enabled = true; currentState = CheckState.Player2Needed; SaveManager.SaveArcadeControlScheme(SupportedControllers.KeyboardP1ControllerP2); newScheme = SupportedControllers.KeyboardP1ControllerP2; toolTip.text = keyboardSelected; } } if ((isPlayer1Input) && (currentState == CheckState.Player2Needed)) { ClosePopup(); } }
/// <summary> /// Saves Control Scheme /// </summary> /// <param name="Scheme">The supported controller setting to save</param> public static void SaveArcadeControlScheme(SupportedControllers Scheme) { BinaryFormatter Formatter = new BinaryFormatter(); string SavePath = Application.persistentDataPath + "/controlconfig.masf"; FileStream Stream = new FileStream(SavePath, FileMode.OpenOrCreate); ArcadeData Data = new ArcadeData(Scheme); Formatter.Serialize(Stream, Data); Stream.Close(); }
/// <summary> /// Runs every 2 seconds to check what controller is in play. May need to adjust this as and when I get the complete product running.... /// </summary> /// <returns>Nothing, but changes the SupportedControllers enum value when the controls are changed</returns> private IEnumerator ControlCheck() { isCoRunning = true; // Gets all the joystick names, retruns a sring array with any names and blank entries if a joystick was unplugged activeControllers = Input.GetJoystickNames(); // Dermines if there is a controller plugged into the PC, note it will only assign player 1 if (activeControllers.Length > 0) { for (int i = 0; i < activeControllers.Length; i++) { if ((activeControllers.Length == 1) && (activeControllers[0] != "")) { isMixedControls = true; } else if ((activeControllers.Length >= 2) && (activeControllers[1].Contains("")) && (activeControllers[0].Contains("Controller"))) { isMixedControls = true; } else if ((activeControllers.Length >= 2) && (activeControllers[0].Contains("")) && (activeControllers[activeControllers.Length - 1].Contains("Controller"))) { isMixedControls = true; } else { isMixedControls = false; } } if (!isMixedControls) { if ((activeControllers.Length >= 2) && (activeControllers[activeControllers.Length - 1].Contains("Controller")) && (activeControllers[0].Contains("Controller"))) { ControllerType = SupportedControllers.GamePadBoth; } else if ((activeControllers.Length >= 2) && (activeControllers[0].Contains("Generic")) && (activeControllers[1].Contains("Generic"))) { ControllerType = SupportedControllers.ArcadeBoard; } else if ((activeControllers.Length >= 2) && activeControllers[0].Contains("") && activeControllers[activeControllers.Length - 1].Contains("")) { ControllerType = SupportedControllers.KeyboardBoth; } } else if (isMixedControls) { if (activeControllers.Length == 1 && activeControllers[0].Contains("Controller")) { if (SaveManager.LoadArcadeControlScheme() != null) { ControllerType = SaveManager.LoadArcadeControlScheme().SetMixedInputConfig; } else { isMixedControls = true; if ((ControllerType != SupportedControllers.KeyboardP1ControllerP2) && (ControllerType != SupportedControllers.KeyboardP2ControllerP1)) { OpenPopup(); } } } else if (activeControllers.Length >= 2 && activeControllers[0].Contains("Controller") && activeControllers[1].Contains("")) { if (SaveManager.LoadArcadeControlScheme() != null) { ControllerType = SaveManager.LoadArcadeControlScheme().SetMixedInputConfig; } else { isMixedControls = true; if ((ControllerType != SupportedControllers.KeyboardP1ControllerP2) && (ControllerType != SupportedControllers.KeyboardP2ControllerP1)) { OpenPopup(); } } } else if (activeControllers.Length >= 2 && activeControllers[1].Contains("Controller") && activeControllers[0].Contains("")) { if (SaveManager.LoadArcadeControlScheme() != null) { ControllerType = SaveManager.LoadArcadeControlScheme().SetMixedInputConfig; } else { isMixedControls = true; if ((ControllerType != SupportedControllers.KeyboardP1ControllerP2) && (ControllerType != SupportedControllers.KeyboardP2ControllerP1)) { OpenPopup(); } } } else if (activeControllers.Length >= 2 && activeControllers[activeControllers.Length - 1].Contains("Controller") && activeControllers[0].Contains("")) { if (SaveManager.LoadArcadeControlScheme() != null) { ControllerType = SaveManager.LoadArcadeControlScheme().SetMixedInputConfig; } else { isMixedControls = true; if ((ControllerType != SupportedControllers.KeyboardP1ControllerP2) && (ControllerType != SupportedControllers.KeyboardP2ControllerP1)) { OpenPopup(); } } } } } else { ControllerType = SupportedControllers.KeyboardBoth; } yield return(new WaitForSeconds(2)); isCoRunning = false; }
public ArcadeData(SupportedControllers ControlScheme) { SetMixedInputConfig = ControlScheme; }