/// <summary> /// Returns true during the first frame the player releases the button /// </summary> /// <param name="buttonKey"></param> /// <param name="player"></param> public static bool GetButtonUp(PlayerButton button, IInputPlayer player = null) { string buttonKey = button.ToString(); if (player == null) { bool result = keyboardController.GetButtonUp(KeyboardButtonLookUp(0, buttonKey)); for (int i = 0; i < xboxControllers.Count; i++) { if (xboxControllers[i].IsConnected) { result |= xboxControllers[i].GetButtonUp(XboxButtonLookUp(i, buttonKey)); } } return(result); } else { if (player.InputMethod == InputMethod.Keyboard) { return(keyboardController.GetButtonUp(KeyboardButtonLookUp(player.PlayerIndex + 1, buttonKey))); } else if (player.InputMethod == InputMethod.XboxController) { return(xboxControllers[player.PlayerIndex].GetButtonUp(XboxButtonLookUp(player.PlayerIndex + 1, buttonKey))); } else { return(false); } } }
private void Start() { pm = GetComponent <PlayerMovement>(); player = GetComponent <IInputPlayer>(); //sp = GetComponent<SpriteRenderer>(); HUDManager.singleton.setLiveCount(lives); _maxHealth = lives; }
public bool freezeInPlace; // player cannot move at all private void Start() { scaleX = sprite.transform.localScale.x; inControl = true; rb = GetComponent <Rigidbody2D>(); player = GetComponent <IInputPlayer>(); //sp = GetComponent<SpriteRenderer>(); anim = GetComponent <AnimationController>(); }
/// <summary> /// Resets the state of the button pressed by the player /// </summary> /// <param name="buttonKey"></param> /// <param name="player"></param> public static void ResetButton(XboxController.XboxButton button, IInputPlayer player) { if (player == null) { return; } else { xboxControllers[player.PlayerIndex].ResetButton(button); } Input.ResetInputAxes(); }
/// <summary> /// Resets the state of the button pressed by the player /// </summary> /// <param name="buttonKey"></param> /// <param name="player"></param> public static void ResetButton(PlayerButton button, IInputPlayer player) { string buttonKey = button.ToString(); if (player == null) { return; } else { xboxControllers[player.PlayerIndex].ResetButton(XboxButtonLookUp(player.PlayerIndex + 1, buttonKey)); } Input.ResetInputAxes(); }
public InputAction(IInputPlayer player, string id) { Player = player; Id = id; Enabled = true; mouseButtons = new List <MouseButton>(); mouseButtonsNegative = new List <MouseButton>(); keyboardKeys = new List <KeyboardKey>(); keyboardKeysNegative = new List <KeyboardKey>(); gamepadButtons = new List <GamepadButton>(); gamepadButtonsNegative = new List <GamepadButton>(); gamepadAxis = new List <GamepadAxis>(); ResetBindings(); }
/// <summary> /// Returns the axis value during the first frame the axis reaches its maximum aboslute value /// </summary> /// <param name="axisKey"></param> /// <param name="player"></param> public static float GetAxisDown(PlayerAxis axis, IInputPlayer player = null) { string axisKey = axis.ToString(); if (player == null) { List <float> valueList = new List <float>(); // Add keyboard values to list valueList.Add(keyboardController.GetAxisDown(KeyboardAxisLookUp(0, "(Pos)" + axisKey))); valueList.Add(-keyboardController.GetAxisDown(KeyboardAxisLookUp(0, "(Neg)" + axisKey))); // Add xbox values to list for (int i = 0; i < xboxControllers.Count; i++) { if (xboxControllers[i].IsConnected) { valueList.Add(xboxControllers[i].GetAxisDown(XboxAxisLookUp(0, axisKey))); } } return(LargestAbsoluteValue(valueList)); } else { if (player.InputMethod == InputMethod.Keyboard) { float keyboardPos = keyboardController.GetAxisDown(KeyboardAxisLookUp(player.PlayerIndex + 1, "(Pos)" + axisKey)); float keyboardNeg = -keyboardController.GetAxisDown(KeyboardAxisLookUp(player.PlayerIndex + 1, "(Neg)" + axisKey)); return(LargestAbsoluteValue(new List <float> { keyboardPos, keyboardNeg })); } else if (player.InputMethod == InputMethod.XboxController) { return(xboxControllers[(int)player.PlayerIndex].GetAxisDown(XboxAxisLookUp(player.PlayerIndex + 1, axisKey))); } else { return(0); } } }
public void SetButton(XboxController.XboxButton passed) { List <string> xboxCodes = canvas.GetComponent <MenuOptions>().xboxCodes; player = GameObject.Find("Player").GetComponentInChildren <IInputPlayer>(); foreach (string xKey in xboxCodes) { if (passed.ToString() == xKey) { return; } } InputManager.RemapXboxButton(action, passed, player); xboxCodes.Remove(keyName); keyName = passed.ToString(); xboxCodes.Add(keyName); GetComponentInChildren <Text>().text = keyName; }
public void SetButton(KeyCode passed) { List <string> keyboardCodes = canvas.GetComponent <MenuOptions>().keyboardCodes; player = GameObject.Find("Player").GetComponentInChildren <IInputPlayer>(); foreach (string key in keyboardCodes) { if (passed.ToString() == key) { return; } } InputManager.RemapKeyboardButton(action, passed, player); keyboardCodes.Remove(keyName); keyName = passed.ToString(); keyboardCodes.Add(keyName); text.GetComponentInChildren <Text>().text = keyName; }
/// <summary> /// If the player is not null, returns the first xbox button pressed by the player. /// If the player is null, returns the first xbox button pressed by any player. /// If no player exists, returns None /// </summary> /// <param name="player"></param> public static XboxController.XboxButton GetNextXboxButton(IInputPlayer player = null) { if (player == null) { foreach (XboxController xc in xboxControllers) { XboxController.XboxButton nextButton; if ((nextButton = xc.NextXboxButton) != XboxController.XboxButton.None) { return(nextButton); } } return(XboxController.XboxButton.None); } else { return(xboxControllers[(int)player.PlayerIndex].NextXboxButton); } }
public IInputPlayer AddPlayer(string playerId) { IInputPlayer result = null; foreach (var player in players) { if (player.Id == playerId) { result = player; break; } } if (result == null) { result = new InputPlayer(playerId); players.Add(result); } return(result); }
// Start is called before the first frame update void Start() { player = transform.parent.gameObject.GetComponentInChildren <IInputPlayer>(); keyboardCodes.Add("W"); keyboardCodes.Add("S"); keyboardCodes.Add("D"); keyboardCodes.Add("A"); foreach (InputManager.Button b in GameObject.Find("Managers").GetComponent <InputManager>().buttons) { keyboardCodes.Add(b.keyboardButton.ToString()); xboxCodes.Add(b.xboxButton.ToString()); } isTitle = (SceneManager.GetActiveScene().name == "Title") ? true : false; if (isTitle) { current = 1; panels[current].SetActive(true); } else { current = 0; panels[current].SetActive(true); } }
/// <summary> /// Remaps/Updates the Keyboard Axis/Button dictionaries with a new key /// </summary> /// <param name="buttonKey"></param> /// <param name="key"></param> /// <param name="player"></param> public static void RemapKeyboardButton(PlayerButton button, KeyCode key, IInputPlayer player) { string buttonKey = button.ToString(); if (player == null) { return; } else { if (keyboardAxisDictList[player.PlayerIndex + 1].ContainsKey(buttonKey)) { keyboardAxisDictList[player.PlayerIndex + 1][buttonKey] = key; } else if (keyboardButtonDictList[player.PlayerIndex + 1].ContainsKey(buttonKey)) { keyboardButtonDictList[player.PlayerIndex + 1][buttonKey] = key; } else { Debug.InputLog("No keyboard dictionary contains the key: " + buttonKey, Debug.LogType.Warning); } } }
public void RemovePlayer(IInputPlayer player) { players.Remove(player); }
/// <summary> /// Remaps/Updates the Xbox button dictionary with a new button /// </summary> /// <param name="buttonKey"></param> /// <param name="button"></param> /// <param name="player"></param> public static void RemapXboxButton(PlayerButton button, XboxController.XboxButton xButton, IInputPlayer player) { string buttonKey = button.ToString(); // !!!NOTE!!! - Currently remapping xbox axis is not supported if (player == null) { return; } else { xboxButtonDictList[(int)player.PlayerIndex + 1][buttonKey] = xButton; } }
void Start() { player = GetComponent <IInputPlayer>(); pMovement = GetComponent <PlayerMovement>(); originalSpeed = pMovement.speed; }