private void Poll(InputPlayer player, InputEventPollingType pollingType) { InputReceiver receiver = _receivers[player]; if (receiver == null) { return; } Rewired.Player rePlayer = ReInput.players.GetPlayer((int)receiver.InputPlayer); foreach (var action in ReInput.mapping.Actions) { if (rePlayer.GetButtonDown(action.id)) { _receivers[player]?.ReceiveButtonEvent(new InputActionEvent(action.id, pollingType, InputEventType.Down)); } if (rePlayer.GetButtonUp(action.id)) { _receivers[player]?.ReceiveButtonEvent(new InputActionEvent(action.id, pollingType, InputEventType.Up)); } if (rePlayer.GetButton(action.id)) { _receivers[player]?.ReceiveButtonEvent(new InputActionEvent(action.id, pollingType, InputEventType.Hold)); } _receivers[player]?.ReceiveAxisEvent(rePlayer.GetAxis(action.id), new InputAxisEvent(action.id, pollingType)); } }
public void UnPossess(InputReceiver receiver) { foreach (InputPlayer key in _receivers.Keys) { if (_receivers[key] == receiver) { _receivers[key] = null; } } }
public void StopRumble(InputPlayer player) { InputReceiver receiver = _receivers[player]; if (receiver == null) { return; } ReInput.players.GetPlayer((int)receiver.InputPlayer).StopVibration(); }
/// <summary> /// Spawns the player gameObject on a free PlayerSpawn in the scene /// </summary> /// <param name="playerPrefab">The player prefab to spawn</param> /// <param name="inputPlayer">Sets the InputPlayer field on the InputReceiver of the player prefab (if applicable)</param> /// <param name="autoPossess">If true, looks for the InputReceiver component on the player and has the PlayerInputController possess it</param> /// <returns></returns> public GameObject SpawnPlayer(GameObject playerPrefab, InputPlayer inputPlayer = InputPlayer.P1, bool autoPossess = true) { Tuple <Vector3, Quaternion> spawn = GetBestPlayerSpawnLocationAndRotation(); Debug.AssertFormat(spawn != null, $"Failed to spawn player: no {nameof(PlayerSpawn)} found in the scene"); GameObject player = Instantiate(playerPrefab, spawn.Item1, spawn.Item2); InputReceiver inputReceiver = player.GetComponent <InputReceiver>(); inputReceiver.InputPlayer = inputPlayer; if (inputReceiver != null && autoPossess) { GameBase.Instance.PlayerInputController.Possess(inputReceiver); } return(player); }
public void SetRumble(InputPlayer player, int motorIndex, float amount, float duration = 0.0f) { InputReceiver receiver = _receivers[player]; if (receiver == null) { return; } if (duration > 0.0f) { ReInput.players.GetPlayer((int)receiver.InputPlayer).SetVibration(motorIndex, amount, duration); } else { ReInput.players.GetPlayer((int)receiver.InputPlayer).SetVibration(motorIndex, amount); } }
public override void OnInspectorGUI() { base.OnInspectorGUI(); if (!Application.isPlaying) { return; } EditorGUILayout.HelpBox("Receivers", MessageType.Info); foreach (KeyValuePair <InputPlayer, InputReceiver> kvp in _pic.Receivers) { InputReceiver scenePlayer = null; if (kvp.Value != null) { scenePlayer = GameObject.Find(kvp.Value.name).GetComponent <InputReceiver>(); } scenePlayer = (InputReceiver)EditorGUILayout.ObjectField( new GUIContent(kvp.Key.ToString()), scenePlayer, typeof(InputReceiver), true); } }
public void Possess(InputReceiver receiver) { _receivers[receiver.InputPlayer] = receiver; }