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); }