public void AddPlayer(ControllerInputWrapper.Buttons connectCode) { KeyboardWrapper kw = new KeyboardWrapper(-1); if(!playerControls.ContainsValue(kw) && kw.GetButton(connectCode)) { for(int j = 1; j < 5; j++) { if(!playerControls.ContainsKey((PlayerID)j)) { playerControls.Add((PlayerID)(j), kw); Debug.Log((PlayerID)(j) + ": " + kw + " added"); return; } } } if(playerControls.Count < 4) { string[] controllerNames = Input.GetJoystickNames(); for (int i = 0; i < controllerNames.Length; i++) { ControllerInputWrapper ciw = getControllerType(i); if(ciw != null && !playerControls.ContainsValue(ciw) && ciw.GetButton(connectCode)) { for(int j = 1; j < 5; j++) { if(!playerControls.ContainsKey((PlayerID)j)) { playerControls.Add((PlayerID)(j), ciw); Debug.Log((PlayerID)(j) + ": " + ciw + " added"); break; } } } } } }
public bool AddPlayer(ControllerInputWrapper.Buttons connectCode) { KeyboardWrapper kw = new KeyboardWrapper(-1); if(!playerControls.ContainsValue(kw) && kw.GetButton(connectCode)) { for(int j = 1; j < 5; j++) { if(!playerControls.ContainsKey((PlayerID)j)) { RegisterPlayerController(j, kw); return true; } } } if(playerControls.Count < 4) { string[] controllerNames = Input.GetJoystickNames(); for (int i = 0; i < controllerNames.Length; i++) { ControllerInputWrapper ciw = getControllerType(i); if(ciw != null && !playerControls.ContainsValue(ciw) && ciw.GetButton(connectCode)) { for(int j = 1; j < 5; j++) { if(!playerControls.ContainsKey((PlayerID)j)) { RegisterPlayerController(j, ciw); return true; } } } } } return false; }
public void AllowPlayerRemoval(ControllerInputWrapper.Buttons removalButton) { PlayerID playerToRemove = PlayerID.None; foreach(KeyValuePair<PlayerID, ControllerInputWrapper> kvp in ControllerManager.instance.playerControls) { if(kvp.Value.GetButton(removalButton)) { playerToRemove = kvp.Key; break; } } if(playerToRemove != PlayerID.None) { Debug.Log(playerToRemove + " removed"); playerControls.Remove(playerToRemove); } }
/// <summary> /// Removes a controller from the controller list and shifts over any controllers past it. /// </summary> /// <param name="playerToRemove">The ID of the controller to remove.</param> private void RemoveController(PlayerID playerToRemove) { playerControls.Remove(playerToRemove); if ((int)playerToRemove <= NumPlayers) { // Shift all players after the removed player back one place. for (int i = (int)playerToRemove + 1; i <= NumPlayers + 1; i++) { PlayerID currentID = (PlayerID)i; ControllerInputWrapper controller = playerControls[currentID]; playerControls.Remove(currentID); playerControls.Add((PlayerID)(i - 1), controller); } } }
/// <summary> /// Registers a player in the controls map. /// </summary> /// <param name="id">The ID of the player being registered. </param> /// <param name="ciw">The controller being registered. </param> private void RegisterPlayerController(int id, ControllerInputWrapper ciw) { // if (IsAllAI()) { // for (int i = NumPlayers; i > 0; i--) { // PlayerID currentID = (PlayerID)i; // ControllerInputWrapper controller = playerControls[currentID]; // playerControls.Remove(currentID); // if (i < 4) { // playerControls.Add((PlayerID)(i + 1), controller); // } // } // id = 1; // } playerControls.Add((PlayerID)(id), ciw); Debug.Log((PlayerID)(id) + ": " + ciw + " added"); }
public static float GetAxis(ControllerInputWrapper.Axis axis, int joyNum, bool isRaw = false) { joyNum--;//Off by one error if (joyNum < 0) { if (joyNum == -1) { return keyboardWrapper.GetAxis(axis, joyNum, isRaw); } return 0; } if (playerControls[joyNum] == null) { return 0; } return playerControls[joyNum].GetAxis(axis, joyNum + 1, isRaw); }
public override bool Equals(object obj) { if (obj == null) { return(false); } ControllerInputWrapper test = obj as ControllerInputWrapper; if ((System.Object)test == null) { return(false); } if (test.joyNum == this.joyNum) { return(true); } return(false); }
public bool AddPlayer(ControllerInputWrapper.Buttons connectCode) { KeyboardWrapper kw = new KeyboardWrapper(-1); if (!playerControls.ContainsValue(kw) && kw.GetButton(connectCode)) { for (int j = 1; j < 5; j++) { if (!playerControls.ContainsKey((PlayerID)j)) { playerControls.Add((PlayerID)(j), kw); Debug.Log((PlayerID)(j) + ": " + kw + " added"); return(true); } } } if (playerControls.Count < 4) { string[] controllerNames = Input.GetJoystickNames(); for (int i = 0; i < controllerNames.Length; i++) { ControllerInputWrapper ciw = getControllerType(i); if (ciw != null && !playerControls.ContainsValue(ciw) && ciw.GetButton(connectCode)) { for (int j = 1; j < 5; j++) { if (!playerControls.ContainsKey((PlayerID)j)) { playerControls.Add((PlayerID)(j), ciw); Debug.Log((PlayerID)(j) + ": " + ciw + " added"); return(true); } } } } } return(false); }
/// <summary> /// Adds an AI controller to the game. /// </summary> /// <returns>Whether the AI controller was successfully added.</returns> public bool AddAI(ControllerInputWrapper.Buttons connectCode) { if (playerControls.Count < 4) { foreach (KeyValuePair <PlayerID, ControllerInputWrapper> kvp in ControllerManager.instance.playerControls) { ControllerInputWrapper ciw = kvp.Value; if (ciw != null && ciw.GetButton(connectCode)) { for (int j = 1; j < 5; j++) { if (!playerControls.ContainsKey((PlayerID)j)) { AIWrapper aiw = new AIWrapper(-2); playerControls.Add((PlayerID)(j), aiw); Debug.Log((PlayerID)(j) + ": " + aiw + " added"); return(true); } } } } } return(false); }
public bool GetButtonAll(ControllerInputWrapper.Buttons button, bool isDown) { //This definitely needs an update........... Like seriously.. // int i = 0; // foreach (ControllerInputWrapper cW in playerControls) // { // if (!cW.GetButton(button, i, isDown)){ // return false; // } // } // return true; return false; }
public bool GetButtonUp(ControllerInputWrapper.Buttons button, int joyNum) { // joyNum--; // if (joyNum < 0 || playerControls[joyNum] == null) // { // return false; // } // return playerControls[joyNum].GetButtonUp(button, joyNum + 1); return false; }
public bool GetButton(ControllerInputWrapper.Buttons button, PlayerID id, bool isDown = false) { if(!playerControls.ContainsKey(id)) return false; if (playerControls[id] == null) { return false; } return playerControls[id].GetButton(button, isDown); }
public float GetTrigger(ControllerInputWrapper.Triggers trigger, PlayerID id, bool isRaw = false) { if(!playerControls.ContainsKey(id)) return 0; if (playerControls[id] == null) { return 0; } return playerControls[id].GetTrigger(trigger, isRaw); }
public float GetAxis(ControllerInputWrapper.Axis axis, PlayerID id, bool isRaw = false) { if(!playerControls.ContainsKey(id)) return 0; if (playerControls[id] == null) { return 0; } return playerControls[id].GetAxis(axis, isRaw); }
/// <summary> /// Adds an AI controller to the game. /// </summary> /// <returns>Whether the AI controller was successfully added.</returns> public bool AddAI(ControllerInputWrapper.Buttons connectCode) { if (playerControls.Count < 4) { foreach(KeyValuePair<PlayerID, ControllerInputWrapper> kvp in ControllerManager.instance.playerControls) { ControllerInputWrapper ciw = kvp.Value; if (ciw != null && ciw.GetButton(connectCode)) { for (int j = 1; j < 5; j++) { if (!playerControls.ContainsKey((PlayerID)j)) { AIWrapper aiw = new AIWrapper(-2); playerControls.Add((PlayerID)(j), aiw); Debug.Log((PlayerID)(j) + ": " + aiw + " added"); return true; } } } } } return false; }
/// <summary> /// Removes the last AI player from the game. /// </summary> /// <returns>The index of the AI player that was removed.</returns> /// <param name="removalButton">The button that needs to be pressed to remove an AI.</param> public int AllowAIRemoval(ControllerInputWrapper.Buttons removalButton) { PlayerID playerToRemove = PlayerID.None; bool removing = false; foreach(KeyValuePair<PlayerID, ControllerInputWrapper> kvp in playerControls) { if(kvp.Value.GetButton(removalButton)) { removing = true; break; } } if(removing) { foreach(KeyValuePair<PlayerID, ControllerInputWrapper> kvp in playerControls) { if(kvp.Value is AIWrapper && kvp.Key > playerToRemove) { playerToRemove = kvp.Key; } } } if(playerToRemove != PlayerID.None) { RemoveController(playerToRemove); } return (int)playerToRemove; }
public int AllowPlayerRemoval(ControllerInputWrapper.Buttons removalButton) { PlayerID playerToRemove = PlayerID.None; foreach(KeyValuePair<PlayerID, ControllerInputWrapper> kvp in playerControls) { if(kvp.Value.GetButton(removalButton)) { playerToRemove = kvp.Key; break; } } if(playerToRemove != PlayerID.None) { RemoveController(playerToRemove); } return (int)playerToRemove; }
/// <summary> /// Registers a player in the controls map. /// </summary> /// <param name="id">The ID of the player being registered. </param> /// <param name="ciw">The controller being registered. </param> private void RegisterPlayerController(int id, ControllerInputWrapper ciw) { if (IsAllAI()) { for (int i = NumPlayers; i > 0; i--) { PlayerID currentID = (PlayerID)i; ControllerInputWrapper controller = playerControls[currentID]; playerControls.Remove(currentID); if (i < 4) { playerControls.Add((PlayerID)(i + 1), controller); } } id = 1; } playerControls.Add((PlayerID)(id), ciw); Debug.Log((PlayerID)(id) + ": " + ciw + " added"); }
public static bool GetButtonUp(ControllerInputWrapper.Buttons button, int joyNum) { joyNum--; if (joyNum < 0 || playerControls[joyNum] == null) { return false; } return playerControls[joyNum].GetButtonUp(button, joyNum + 1); }
public static bool GetButton(ControllerInputWrapper.Buttons button, int joyNum, bool isDown = false) { joyNum--; //Debug.Log(joyNum); if (joyNum < 0) { if (joyNum == -1) { return keyboardWrapper.GetButton(button, joyNum, isDown); } return false; } if (playerControls[joyNum] == null) { return false; } return playerControls[joyNum].GetButton(button, joyNum + 1, isDown); }
public static float GetTrigger(ControllerInputWrapper.Triggers trigger, int joyNum, bool isRaw = false) { joyNum--; if (joyNum < 0) { if (joyNum == -1) { return keyboardWrapper.GetTrigger(trigger, joyNum, isRaw); } return 0; } if (playerControls[joyNum] == null) { return 0; } //Debug.Log (trigger); return playerControls[joyNum].GetTrigger(trigger, joyNum + 1, isRaw); }
// Registers a player given an ID and controller type private void RegisterPlayerController(int id, ControllerInputWrapper ciw) { playerControls.Add((PlayerID)(id), ciw); Debug.Log((PlayerID)(id) + ": " + ciw + " added"); }