public NewUnityInputDevice(UnityInput.Gamepad unityGamepad) { UnityGamepad = unityGamepad; SortOrder = unityGamepad.deviceId; DeviceClass = InputDeviceClass.Controller; DeviceStyle = DetectDeviceStyle(unityGamepad); leftCommandControl = DeviceStyle.LeftCommandControl(); rightCommandControl = DeviceStyle.RightCommandControl(); Name = unityGamepad.displayName; Meta = unityGamepad.displayName; AddControl(InputControlType.LeftStickLeft, "Left Stick Left", lowerDeadZone, upperDeadZone); AddControl(InputControlType.LeftStickRight, "Left Stick Right", lowerDeadZone, upperDeadZone); AddControl(InputControlType.LeftStickUp, "Left Stick Up", lowerDeadZone, upperDeadZone); AddControl(InputControlType.LeftStickDown, "Left Stick Down", lowerDeadZone, upperDeadZone); AddControl(InputControlType.RightStickLeft, "Right Stick Left", lowerDeadZone, upperDeadZone); AddControl(InputControlType.RightStickRight, "Right Stick Right", lowerDeadZone, upperDeadZone); AddControl(InputControlType.RightStickUp, "Right Stick Up", lowerDeadZone, upperDeadZone); AddControl(InputControlType.RightStickDown, "Right Stick Down", lowerDeadZone, upperDeadZone); AddControl(InputControlType.LeftTrigger, unityGamepad.leftTrigger.displayName, lowerDeadZone, upperDeadZone); AddControl(InputControlType.RightTrigger, unityGamepad.rightTrigger.displayName, lowerDeadZone, upperDeadZone); AddControl(InputControlType.DPadUp, "DPad Up", lowerDeadZone, upperDeadZone); AddControl(InputControlType.DPadDown, "DPad Down", lowerDeadZone, upperDeadZone); AddControl(InputControlType.DPadLeft, "DPad Left", lowerDeadZone, upperDeadZone); AddControl(InputControlType.DPadRight, "DPad Right", lowerDeadZone, upperDeadZone); AddControl(InputControlType.Action1, unityGamepad.buttonWest.displayName); AddControl(InputControlType.Action2, unityGamepad.buttonNorth.displayName); AddControl(InputControlType.Action3, unityGamepad.buttonEast.displayName); AddControl(InputControlType.Action4, unityGamepad.buttonSouth.displayName); AddControl(InputControlType.LeftBumper, unityGamepad.leftShoulder.displayName); AddControl(InputControlType.RightBumper, unityGamepad.rightShoulder.displayName); AddControl(InputControlType.LeftStickButton, unityGamepad.leftStickButton.displayName); AddControl(InputControlType.RightStickButton, unityGamepad.rightStickButton.displayName); AddControl(leftCommandControl, unityGamepad.selectButton.displayName); AddControl(rightCommandControl, unityGamepad.startButton.displayName); // foreach (var control in unityGamepad.allControls) // { // Debug.Log( $"{control.displayName}, {control.shortDisplayName}" ); // } }
/// <summary> /// A coroutine used to play patterns /// </summary> /// <param name="pattern"></param> /// <param name="lowFreqAmplitudes"></param> /// <param name="highFreqAmplitudes"></param> /// <param name="repeat"></param> /// <returns></returns> private static IEnumerator RumblePatternCoroutine(long[] pattern, int[] lowFreqAmplitudes, int[] highFreqAmplitudes, int repeat, MonoBehaviour coroutineSupport, int controllerID = -1) { float startedAt = Time.unscaledTime; float currentTime = startedAt; int currentIndex = 0; UnityEngine.InputSystem.Gamepad currentGamepad = GetGamepad(controllerID); while (currentIndex < pattern.Length) { if (currentGamepad == null) { yield break; } int count = 0; float totalLowFrequency = 0; float totalHighFrequency = 0; do { float duration = pattern[currentIndex]; float lowFrequencyAmplitude = (lowFreqAmplitudes.Length > currentIndex) ? lowFreqAmplitudes[currentIndex] / 255f : 0f; totalLowFrequency += lowFrequencyAmplitude; float highFrequencyAmplitude = (highFreqAmplitudes.Length > currentIndex) ? highFreqAmplitudes[currentIndex] / 255f : 0f; totalHighFrequency += highFrequencyAmplitude; currentTime += duration / 1000f; count++; currentIndex++; } while (currentTime < Time.unscaledTime && currentIndex < pattern.Length); currentGamepad.SetMotorSpeeds(totalLowFrequency / count, totalHighFrequency / count); while (currentTime > Time.unscaledTime && currentIndex < pattern.Length) { yield return(null); } } currentGamepad.SetMotorSpeeds(0f, 0f); }
private void SetGamePad(UnityEngine.InputSystem.Gamepad gamepad) { this.gamepad = gamepad; }
public void Init(UnityEngine.InputSystem.Gamepad gamepad, float defaultRotation) { SetGamePad(gamepad); SetDefaultRotation(defaultRotation); }
private string GetUniqueGamepadId(UnityEngine.InputSystem.Gamepad gamepad) { return($"ID{gamepad.deviceId}_{gamepad.name}"); }
void Update() { if (stateHandeler == null) { return; } if (stateHandeler.currentState.ID == "Start") { CheckForPlayers(); } if (stateHandeler.currentState.ID == "Lobby") { var elapse = lobbyTimer.RecordTime(Time.fixedDeltaTime); int ct = (int)currentLobbyTime - (int)elapse; lobbyTimerText.text = ":" + ct; if (lobbyTimer.IsDone()) { nextState = stateHandeler.StateChange(); } } if (stateHandeler.currentState.ID == "SetUp") { if (!gameStartTimer.IsDone()) { var elapse = gameStartTimer.RecordTime(Time.fixedDeltaTime); int ct = (int)currentMathcStartTime - (int)elapse; launchText.text = ":" + ct; } if (gameStartTimer.IsDone() && !allPlayersReady) { allPlayersReady = true; player1Ready = true; player2Ready = true; var roll = Random.Range(0, 1); Debug.Log(roll); UnityEngine.InputSystem.Gamepad ag = roll > .5f ? Gamepad.all[0] : Gamepad.all[1]; SetActivePlayer(ag); StartMatch(); } var p1South = Gamepad.all[0].buttonSouth.ReadValue() > 0 ? true : false; var p2South = Gamepad.all[1].buttonSouth.ReadValue() > 0 ? true : false; if (p1South && !allPlayersReady) { allPlayersReady = true; player1Ready = true; player2Ready = true; SetActivePlayer(Gamepad.all[0]); StartMatch(); } if (p2South && !allPlayersReady) { allPlayersReady = true; player1Ready = true; player2Ready = true; SetActivePlayer(Gamepad.all[1]); StartMatch(); } } if (stateHandeler.currentState.ID == "Main") { UpdatePlayerStats(); if (!matchTimer.IsDone()) { var elapse = matchTimer.RecordTime(Time.fixedDeltaTime); int ct = (int)currentMatchTimer - (int)elapse; matchTimerText.text = ":" + ct; var rte = roundTimer.RecordTime(Time.fixedDeltaTime); var timeLeftInround = currentRoundTimer - rte; if (roundTimer.IsDone()) { if (activePlayer.id == player1.id) { player1.SetActiveTeam(false); player2.SetActiveTeam(true); activePlayer = player2; } else if (activePlayer.id == player2.id) { player2.SetActiveTeam(false); player1.SetActiveTeam(true); activePlayer = player1; } SetActivePlayer(activePlayer); currentRoundTimer = roundTimerInSeconds; roundTimer.SetTimer(roundTimerInSeconds); } //spawn mobs } } }
private void SetActivePlayer(UnityEngine.InputSystem.Gamepad gamepad) { activePlayer = players[gamepad].GetComponent <PlayerKit>(); SetActivePlayer(activePlayer); }
public void SetGamePad(UnityEngine.InputSystem.Gamepad gamepad, float defaultPos) { this.gamepad = gamepad; movement.Init(gamepad, defaultPos); }
/// <summary> /// Make the gamepad the <see cref="current"/> gamepad. /// </summary> /// <remarks> /// This is called automatically by the system when there is input on a gamepad. /// </remarks> public override void MakeCurrent() { base.MakeCurrent(); current = this; }