/// <summary> /// set a smart control to be inverted or not /// </summary> public static void SetInverted(int smartControlNameHashed, bool invert, SinputSystems.InputDeviceSlot slot = SinputSystems.InputDeviceSlot.any) { SinputUpdate(); var controlFound = false; for (int i = 0; i < smartControls.Length; i++) { if (smartControls[i].nameHashed == smartControlNameHashed) { controlFound = true; if (slot == SinputSystems.InputDeviceSlot.any) { for (int k = 0; k < totalPossibleDeviceSlots; k++) { smartControls[i].inversion[k] = invert; } } else { smartControls[i].inversion[(int)slot] = invert; } } } if (!controlFound) { Debug.LogError("Sinput Error: Hashed Smart Control \"" + smartControlNameHashed + "\" not found in list of SmartControls."); } }
} //default wait is half a second /// <summary> /// tells Sinput to return false/0f for any input checks until the wait time has passed /// </summary> public static void ResetInputs(float waitTime, SinputSystems.InputDeviceSlot slot = SinputSystems.InputDeviceSlot.any) { SinputUpdate(); if (slot == SinputSystems.InputDeviceSlot.any) { //reset all slots' input for (int i = 0; i < totalPossibleDeviceSlots; i++) { zeroInputWaits[i] = waitTime; zeroInputs[i] = true; } } else { //reset only a specific slot's input zeroInputWaits[(int)slot] = waitTime; zeroInputs[(int)slot] = true; } //reset smartControl values if (smartControls != null) { for (int i = 0; i < smartControls.Length; i++) { smartControls[i].ResetAllValues(slot); } } }
public PlayerController joinPlayer(SinputSystems.InputDeviceSlot slot) { GameObject newPlayer = Instantiate(playerPrefab); PlayerController pc = newPlayer.AddComponent <PlayerController>(); //pc.initialize(slot, newPlayer.GetComponent<Rigidbody2D>()); return(pc); }
internal static float AxisCheck(int controlNameHashed, out bool prefersDeltaUse, SinputSystems.InputDeviceSlot slot = SinputSystems.InputDeviceSlot.any, bool getRawValue = false) { SinputUpdate(); prefersDeltaUse = true; // Defaults to true, but doesn't matter because when default, the value returned is 0 if (zeroInputs[(int)slot]) { return(0f); } if (controlNameHashed == HashedEmptyString) { return(0f); } var controlFound = false; var returnV = 0f; for (int i = 0; i < _controls.Length; i++) { if (_controls[i].nameHashed == controlNameHashed) { controlFound = true; bool prefersDeltaUseTmp; var v = _controls[i].GetAxisState(slot, out prefersDeltaUseTmp); if (Math.Abs(v) > returnV) { prefersDeltaUse = prefersDeltaUseTmp; returnV = v; } } } for (int i = 0; i < smartControls.Length; i++) { if (smartControls[i].nameHashed == controlNameHashed) { controlFound = true; bool prefersDeltaUseTmp; var v = smartControls[i].GetValue(slot, getRawValue, out prefersDeltaUseTmp); if (Math.Abs(v) > returnV) { prefersDeltaUse = prefersDeltaUseTmp; returnV = v; } } } if (!controlFound) { Debug.LogError("Sinput Error: Hashed Control \"" + controlNameHashed + "\" not found in list of Controls or SmartControls."); } return(returnV); }
/// <summary> /// gets scale of a smart control /// </summary> public static float GetScale(int smartControlNameHashed, SinputSystems.InputDeviceSlot slot = SinputSystems.InputDeviceSlot.any) { for (int i = 0; i < smartControls.Length; i++) { if (smartControls[i].nameHashed == smartControlNameHashed) { return(smartControls[i].scales[(int)slot]); } } Debug.LogError("Sinput Error: Hashed Smart Control \"" + smartControlNameHashed + "\" not found in list of SmartControls."); return(1f); }
// Update is called once per frame void Update() { SinputSystems.InputDeviceSlot slot = Sinput.GetSlotPress("Join"); if (slot != SinputSystems.InputDeviceSlot.any) { GameObject newPlayer = (GameObject)GameObject.Instantiate(playerPrefab); newPlayer.transform.position = new Vector3(Random.Range(-4f, 4f), 3f, Random.Range(-4f, 4f)); newPlayer.GetComponent <MultiplayerPlayer>().playerSlot = slot; } }
/// <summary> /// Returns false if the value returned by GetAxis(controlName) on this frame should NOT be multiplied by delta time. /// <para>For example, this will return true for gamepad stick values, false for mouse movement values</para> /// </summary> public static bool PrefersDeltaUse(int controlNameHashed, SinputSystems.InputDeviceSlot slot = SinputSystems.InputDeviceSlot.any) { SinputUpdate(); if (controlNameHashed == HashedEmptyString) { return(false); } var preferDelta = true; var controlFound = false; var returnV = 0f; for (int i = 0; i < _controls.Length; i++) { if (_controls[i].nameHashed == controlNameHashed) { controlFound = true; bool tmpPreferDelta; var v = _controls[i].GetAxisState(slot, out tmpPreferDelta); if (Math.Abs(v) > returnV) { returnV = v; preferDelta = tmpPreferDelta; } } } //now check smart controls for framerate independence for (int i = 0; i < smartControls.Length; i++) { if (smartControls[i].nameHashed == controlNameHashed) { controlFound = true; bool tmpPreferDelta; var v = smartControls[i].GetValue(slot, true, out tmpPreferDelta); if (Math.Abs(v) > returnV) { returnV = v; preferDelta = tmpPreferDelta; } } } if (!controlFound) { Debug.LogError("Sinput Error: Hashed Control \"" + controlNameHashed + "\" not found in list of Controls or SmartControls."); } return(preferDelta); }
/// <summary> /// returns true if a smart control is inverted /// </summary> public static bool GetInverted(int smartControlNameHashed, SinputSystems.InputDeviceSlot slot = SinputSystems.InputDeviceSlot.any) { SinputUpdate(); for (int i = 0; i < smartControls.Length; i++) { if (smartControls[i].nameHashed == smartControlNameHashed) { return(smartControls[i].inversion[(int)slot]); } } Debug.LogError("Sinput Error: Hashed Smart Control \"" + smartControlNameHashed + "\" not found in list of SmartControls."); return(false); }
static Vector2 Vector2Check(int controlNameAHashed, int controlNameBHashed, SinputSystems.InputDeviceSlot slot, bool normalClip) { SinputUpdate(); Vector2 returnVec2; returnVec2.x = AxisCheck(controlNameAHashed, slot); returnVec2.y = AxisCheck(controlNameBHashed, slot); if (normalClip) { var magnitude = returnVec2.magnitude; if (magnitude > 1f) { returnVec2 = returnVec2 / magnitude; // Normalize reusing magnitude (optimization) } } return(returnVec2); }
static bool ButtonCheck(int controlNameHashed, SinputSystems.InputDeviceSlot slot, SinputSystems.ButtonAction bAction, bool getRawValue = false) { SinputUpdate(); if (zeroInputs[(int)slot]) { return(false); } var controlFound = false; for (int i = 0; i < _controls.Length; i++) { if (_controls[i].nameHashed == controlNameHashed) { controlFound = true; if (_controls[i].GetButtonState(bAction, slot, getRawValue)) { return(true); } } } for (int i = 0; i < smartControls.Length; i++) { if (smartControls[i].nameHashed == controlNameHashed) { controlFound = true; if (smartControls[i].ButtonCheck(bAction, slot)) { return(true); } } } if (!controlFound) { Debug.LogError("Sinput Error: Hashed Control \"" + controlNameHashed + "\" not found in list of controls or SmartControls."); } return(false); }
// Update is called once per frame void Update() { SinputSystems.InputDeviceSlot slot = Sinput.GetSlotPress("Join"); if (slot != SinputSystems.InputDeviceSlot.any) { //a player has pressed join! //first we check if this player has already joined bool alreadyJoined = false; for (int i = 0; i < players.Count; i++) { if (players[i].playerSlot == slot) { alreadyJoined = true; //lets assume this player is trying to unjoin, and remove them :) Destroy(players[i].gameObject); players.RemoveAt(i); i--; } } if (!alreadyJoined) { //this is a new player looking to join, so lets let them! GameObject newPlayer = (GameObject)GameObject.Instantiate(playerPrefab); newPlayer.transform.position = new Vector3(Random.Range(-4f, 4f), 3f, Random.Range(-4f, 4f)); newPlayer.GetComponent <ShootyPlayer>().playerSlot = slot; players.Add(newPlayer.GetComponent <ShootyPlayer>()); //lets prevent any new inputs from this slot for a few frames //This isn't necessary, but will prevent people accidentally pressing join twice quickly :) Sinput.ResetInputs(slot); } } }
/// <summary> /// returns true if a smart control is inverted /// </summary> public static bool GetInverted(string smartControlName, SinputSystems.InputDeviceSlot slot = SinputSystems.InputDeviceSlot.any) { return(GetInverted(Animator.StringToHash(smartControlName), slot)); }
/// <summary> /// gets scale of a smart control /// </summary> public static float GetScale(string smartControlName, SinputSystems.InputDeviceSlot slot = SinputSystems.InputDeviceSlot.any) { return(GetScale(Animator.StringToHash(smartControlName), slot)); }
/// <summary> /// set a smart control to be inverted or not /// </summary> public static void SetInverted(string smartControlName, bool invert, SinputSystems.InputDeviceSlot slot = SinputSystems.InputDeviceSlot.any) { SetInverted(Animator.StringToHash(smartControlName), invert, slot); }
/// <summary> /// Returns a Vector3 made with GetAxis() values applied to x, y, and z /// </summary> public static Vector3 GetVector(string controlNameA, string controlNameB, string controlNameC, SinputSystems.InputDeviceSlot slot = SinputSystems.InputDeviceSlot.any, bool normalClip = true) { return(Vector3Check(Animator.StringToHash(controlNameA), Animator.StringToHash(controlNameB), Animator.StringToHash(controlNameC), slot, normalClip)); }
//frame delta preference /// <summary> /// Returns false if the value returned by GetAxis(controlName) on this frame should NOT be multiplied by delta time. /// <para>For example, this will return true for gamepad stick values, false for mouse movement values</para> /// </summary> public static bool PrefersDeltaUse(string controlName, SinputSystems.InputDeviceSlot slot = SinputSystems.InputDeviceSlot.any) { return(PrefersDeltaUse(Animator.StringToHash(controlName), slot)); }
/// <summary> /// tells Sinput to return false/0f for any input checks until half a second has passed /// </summary> /// <param name="slot"></param> public static void ResetInputs(SinputSystems.InputDeviceSlot slot = SinputSystems.InputDeviceSlot.any) { ResetInputs(0.5f, slot); } //default wait is half a second
/// <summary> /// Returns true if a Sinput Control or Smart Control was Released this frame, regardless of the Control's toggle setting. /// </summary> public static bool GetButtonUpRaw(int controlNameHashed, SinputSystems.InputDeviceSlot slot = SinputSystems.InputDeviceSlot.any) { return(ButtonCheck(controlNameHashed, slot, SinputSystems.ButtonAction.UP, true)); }
public void initialize(SinputSystems.InputDeviceSlot slot) { this.slot = slot; playerRigidbody = gameObject.GetComponent <Rigidbody2D>(); }
/// <summary> /// Returns true if a Sinput Control or Smart Control was Pressed this frame, or if it has been held long enough to start repeating. /// <para>Use this for menu scrolling inputs</para> /// </summary> public static bool GetButtonDownRepeating(string controlName, SinputSystems.InputDeviceSlot slot = SinputSystems.InputDeviceSlot.any) { return(GetButtonDownRepeating(Animator.StringToHash(controlName), slot)); }
/// <summary> /// Returns true if a Sinput Control or Smart Control was Pressed this frame, or if it has been held long enough to start repeating. /// <para>Use this for menu scrolling inputs</para> /// </summary> public static bool GetButtonDownRepeating(int controlNameHashed, SinputSystems.InputDeviceSlot slot = SinputSystems.InputDeviceSlot.any) { return(ButtonCheck(controlNameHashed, slot, SinputSystems.ButtonAction.REPEATING)); }
/// <summary> /// sets scale ("sensitivity") of a smart control /// </summary> public static void SetScale(string smartControlName, float scale, SinputSystems.InputDeviceSlot slot = SinputSystems.InputDeviceSlot.any) { SetScale(Animator.StringToHash(smartControlName), scale, slot); }
/// <summary> /// Returns the raw value of a Sinput Control or Smart Control /// </summary> public static float GetAxisRaw(string controlName, SinputSystems.InputDeviceSlot slot = SinputSystems.InputDeviceSlot.any) { return(AxisCheck(Animator.StringToHash(controlName), out var _, slot, true)); }
internal static float AxisCheck(int controlNameHashed, SinputSystems.InputDeviceSlot slot = SinputSystems.InputDeviceSlot.any, bool getRawValue = false) { bool _; return(AxisCheck(controlNameHashed, out _, slot, getRawValue)); }
public void joinPlayer(PlayerController playerC, SinputSystems.InputDeviceSlot slot) { playerC.initialize(slot); }