Commit 792643fb by Tim Reiter

fixed dash shoulder trigger bug (only LB and RB are accepted now)

parent 94d91b15
...@@ -8,252 +8,252 @@ using System.Collections; ...@@ -8,252 +8,252 @@ using System.Collections;
namespace GamepadInput namespace GamepadInput
{ {
public static class GamePad public static class GamePad
{ {
public enum Button { A, B, Y, X, RightShoulder, LeftShoulder, RightStick, LeftStick, Back, Start } public enum Button { A, B, Y, X, RightShoulder, LeftShoulder, RightStick, LeftStick, Back, Start }
public enum Trigger { LeftTrigger, RightTrigger } public enum Trigger { LeftTrigger, RightTrigger }
public enum Axis { LeftStick, RightStick, Dpad } public enum Axis { LeftStick, RightStick, Dpad }
public enum Index { Any, One, Two, Three, Four } public enum Index { Any, One, Two, Three, Four }
public static bool GetButtonDown(Button button, Index controlIndex) public static bool GetButtonDown(Button button, Index controlIndex)
{ {
KeyCode code = GetKeycode(button, controlIndex); KeyCode code = GetKeycode(button, controlIndex);
return Input.GetKeyDown(code); return Input.GetKeyDown(code);
} }
public static bool GetButtonUp(Button button, Index controlIndex) public static bool GetButtonUp(Button button, Index controlIndex)
{ {
KeyCode code = GetKeycode(button, controlIndex); KeyCode code = GetKeycode(button, controlIndex);
return Input.GetKeyUp(code); return Input.GetKeyUp(code);
} }
public static bool GetButton(Button button, Index controlIndex) public static bool GetButton(Button button, Index controlIndex)
{ {
KeyCode code = GetKeycode(button, controlIndex); KeyCode code = GetKeycode(button, controlIndex);
return Input.GetKey(code); return Input.GetKey(code);
} }
/// <summary> /// <summary>
/// returns a specified axis /// returns a specified axis
/// </summary> /// </summary>
/// <param name="axis">One of the analogue sticks, or the dpad</param> /// <param name="axis">One of the analogue sticks, or the dpad</param>
/// <param name="controlIndex">The controller number</param> /// <param name="controlIndex">The controller number</param>
/// <param name="raw">if raw is false then the controlIndex will be returned with a deadspot</param> /// <param name="raw">if raw is false then the controlIndex will be returned with a deadspot</param>
/// <returns></returns> /// <returns></returns>
public static Vector2 GetAxis(Axis axis, Index controlIndex, bool raw = false) public static Vector2 GetAxis(Axis axis, Index controlIndex, bool raw = false)
{ {
string xName = "", yName = ""; string xName = "", yName = "";
switch (axis) switch (axis)
{ {
case Axis.Dpad: case Axis.Dpad:
xName = "DPad_XAxis_" + (int)controlIndex; xName = "DPad_XAxis_" + (int)controlIndex;
yName = "DPad_YAxis_" + (int)controlIndex; yName = "DPad_YAxis_" + (int)controlIndex;
break; break;
case Axis.LeftStick: case Axis.LeftStick:
xName = "L_XAxis_" + (int)controlIndex; xName = "L_XAxis_" + (int)controlIndex;
yName = "L_YAxis_" + (int)controlIndex; yName = "L_YAxis_" + (int)controlIndex;
break; break;
case Axis.RightStick: case Axis.RightStick:
xName = "R_XAxis_" + (int)controlIndex; xName = "R_XAxis_" + (int)controlIndex;
yName = "R_YAxis_" + (int)controlIndex; yName = "R_YAxis_" + (int)controlIndex;
break; break;
} }
Vector2 axisXY = Vector3.zero; Vector2 axisXY = Vector3.zero;
try try
{ {
if (raw == false) if (raw == false)
{ {
axisXY.x = Input.GetAxis(xName); axisXY.x = Input.GetAxis(xName);
axisXY.y = -Input.GetAxis(yName); axisXY.y = -Input.GetAxis(yName);
}
else
{
axisXY.x = Input.GetAxisRaw(xName);
axisXY.y = -Input.GetAxisRaw(yName);
}
}
catch (System.Exception e)
{
Debug.LogError(e);
Debug.LogWarning("Have you set up all axes correctly? \nThe easiest solution is to replace the InputManager.asset with version located in the GamepadInput package. \nWarning: do so will overwrite any existing input");
}
return axisXY;
} }
else
public static float GetTrigger(Trigger trigger, Index controlIndex, bool raw = false)
{ {
axisXY.x = Input.GetAxisRaw(xName); //
axisXY.y = -Input.GetAxisRaw(yName); string name = "";
} if (trigger == Trigger.LeftTrigger)
} name = "TriggersL_" + (int)controlIndex;
catch (System.Exception e) else if (trigger == Trigger.RightTrigger)
{ name = "TriggersR_" + (int)controlIndex;
Debug.LogError(e);
Debug.LogWarning("Have you set up all axes correctly? \nThe easiest solution is to replace the InputManager.asset with version located in the GamepadInput package. \nWarning: do so will overwrite any existing input");
}
return axisXY;
}
public static float GetTrigger(Trigger trigger, Index controlIndex, bool raw = false) //
{ float axis = 0;
// try
string name = ""; {
if (trigger == Trigger.LeftTrigger) if (raw == false)
name = "TriggersL_" + (int)controlIndex; axis = Input.GetAxis(name);
else if (trigger == Trigger.RightTrigger) else
name = "TriggersR_" + (int)controlIndex; axis = Input.GetAxisRaw(name);
}
catch (System.Exception e)
{
Debug.LogError(e);
Debug.LogWarning("Have you set up all axes correctly? \nThe easiest solution is to replace the InputManager.asset with version located in the GamepadInput package. \nWarning: do so will overwrite any existing input");
}
return axis;
}
//
float axis = 0;
try
{
if (raw == false)
axis = Input.GetAxis(name);
else
axis = Input.GetAxisRaw(name);
}
catch (System.Exception e)
{
Debug.LogError(e);
Debug.LogWarning("Have you set up all axes correctly? \nThe easiest solution is to replace the InputManager.asset with version located in the GamepadInput package. \nWarning: do so will overwrite any existing input");
}
return axis;
}
static KeyCode GetKeycode(Button button, Index controlIndex)
{
switch (controlIndex)
{
case Index.One:
switch (button)
{
case Button.A: return KeyCode.Joystick1Button0;
case Button.B: return KeyCode.Joystick1Button1;
case Button.X: return KeyCode.Joystick1Button2;
case Button.Y: return KeyCode.Joystick1Button3;
case Button.RightShoulder: return KeyCode.Joystick1Button5;
case Button.LeftShoulder: return KeyCode.Joystick1Button4;
case Button.Back: return KeyCode.Joystick1Button6;
case Button.Start: return KeyCode.Joystick1Button7;
case Button.LeftStick: return KeyCode.Joystick1Button8;
case Button.RightStick: return KeyCode.Joystick1Button9;
}
break;
case Index.Two:
switch (button)
{
case Button.A: return KeyCode.Joystick2Button0;
case Button.B: return KeyCode.Joystick2Button1;
case Button.X: return KeyCode.Joystick2Button2;
case Button.Y: return KeyCode.Joystick2Button3;
case Button.RightShoulder: return KeyCode.Joystick2Button5;
case Button.LeftShoulder: return KeyCode.Joystick2Button4;
case Button.Back: return KeyCode.Joystick2Button6;
case Button.Start: return KeyCode.Joystick2Button7;
case Button.LeftStick: return KeyCode.Joystick2Button8;
case Button.RightStick: return KeyCode.Joystick2Button9;
}
break;
case Index.Three:
switch (button)
{
case Button.A: return KeyCode.Joystick3Button0;
case Button.B: return KeyCode.Joystick3Button1;
case Button.X: return KeyCode.Joystick3Button2;
case Button.Y: return KeyCode.Joystick3Button3;
case Button.RightShoulder: return KeyCode.Joystick3Button5;
case Button.LeftShoulder: return KeyCode.Joystick3Button4;
case Button.Back: return KeyCode.Joystick3Button6;
case Button.Start: return KeyCode.Joystick3Button7;
case Button.LeftStick: return KeyCode.Joystick3Button8;
case Button.RightStick: return KeyCode.Joystick3Button9;
}
break;
case Index.Four:
static KeyCode GetKeycode(Button button, Index controlIndex) switch (button)
{ {
switch (controlIndex) case Button.A: return KeyCode.Joystick4Button0;
{ case Button.B: return KeyCode.Joystick4Button1;
case Index.One: case Button.X: return KeyCode.Joystick4Button2;
switch (button) case Button.Y: return KeyCode.Joystick4Button3;
{ case Button.RightShoulder: return KeyCode.Joystick4Button5;
case Button.A: return KeyCode.Joystick1Button0; case Button.LeftShoulder: return KeyCode.Joystick4Button4;
case Button.B: return KeyCode.Joystick1Button1; case Button.Back: return KeyCode.Joystick4Button6;
case Button.X: return KeyCode.Joystick1Button2; case Button.Start: return KeyCode.Joystick4Button7;
case Button.Y: return KeyCode.Joystick1Button3; case Button.LeftStick: return KeyCode.Joystick4Button8;
case Button.RightShoulder: return KeyCode.Joystick1Button5; case Button.RightStick: return KeyCode.Joystick4Button9;
case Button.LeftShoulder: return KeyCode.Joystick1Button4; }
case Button.Back: return KeyCode.Joystick1Button6;
case Button.Start: return KeyCode.Joystick1Button7;
case Button.LeftStick: return KeyCode.Joystick1Button8;
case Button.RightStick: return KeyCode.Joystick1Button9;
}
break;
case Index.Two:
switch (button)
{
case Button.A: return KeyCode.Joystick2Button0;
case Button.B: return KeyCode.Joystick2Button1;
case Button.X: return KeyCode.Joystick2Button2;
case Button.Y: return KeyCode.Joystick2Button3;
case Button.RightShoulder: return KeyCode.Joystick2Button5;
case Button.LeftShoulder: return KeyCode.Joystick2Button4;
case Button.Back: return KeyCode.Joystick2Button6;
case Button.Start: return KeyCode.Joystick2Button7;
case Button.LeftStick: return KeyCode.Joystick2Button8;
case Button.RightStick: return KeyCode.Joystick2Button9;
}
break;
case Index.Three:
switch (button)
{
case Button.A: return KeyCode.Joystick3Button0;
case Button.B: return KeyCode.Joystick3Button1;
case Button.X: return KeyCode.Joystick3Button2;
case Button.Y: return KeyCode.Joystick3Button3;
case Button.RightShoulder: return KeyCode.Joystick3Button5;
case Button.LeftShoulder: return KeyCode.Joystick3Button4;
case Button.Back: return KeyCode.Joystick3Button6;
case Button.Start: return KeyCode.Joystick3Button7;
case Button.LeftStick: return KeyCode.Joystick3Button8;
case Button.RightStick: return KeyCode.Joystick3Button9;
}
break;
case Index.Four:
switch (button) break;
{ case Index.Any:
case Button.A: return KeyCode.Joystick4Button0; switch (button)
case Button.B: return KeyCode.Joystick4Button1; {
case Button.X: return KeyCode.Joystick4Button2; case Button.A: return KeyCode.JoystickButton0;
case Button.Y: return KeyCode.Joystick4Button3; case Button.B: return KeyCode.JoystickButton1;
case Button.RightShoulder: return KeyCode.Joystick4Button5; case Button.X: return KeyCode.JoystickButton2;
case Button.LeftShoulder: return KeyCode.Joystick4Button4; case Button.Y: return KeyCode.JoystickButton3;
case Button.Back: return KeyCode.Joystick4Button6; case Button.RightShoulder: return KeyCode.JoystickButton5;
case Button.Start: return KeyCode.Joystick4Button7; case Button.LeftShoulder: return KeyCode.JoystickButton4;
case Button.LeftStick: return KeyCode.Joystick4Button8; case Button.Back: return KeyCode.JoystickButton6;
case Button.RightStick: return KeyCode.Joystick4Button9; case Button.Start: return KeyCode.JoystickButton7;
} case Button.LeftStick: return KeyCode.JoystickButton8;
case Button.RightStick: return KeyCode.JoystickButton9;
}
break;
}
return KeyCode.None;
}
break; public static GamepadState GetState(Index controlIndex, bool raw = false)
case Index.Any: {
switch (button) GamepadState state = new GamepadState();
{
case Button.A: return KeyCode.JoystickButton0;
case Button.B: return KeyCode.JoystickButton1;
case Button.X: return KeyCode.JoystickButton2;
case Button.Y: return KeyCode.JoystickButton3;
case Button.RightShoulder: return KeyCode.JoystickButton5;
case Button.LeftShoulder: return KeyCode.JoystickButton4;
case Button.Back: return KeyCode.JoystickButton6;
case Button.Start: return KeyCode.JoystickButton7;
case Button.LeftStick: return KeyCode.JoystickButton8;
case Button.RightStick: return KeyCode.JoystickButton9;
}
break;
}
return KeyCode.None;
}
public static GamepadState GetState(Index controlIndex, bool raw = false) state.A = GetButton(Button.A, controlIndex);
{ state.B = GetButton(Button.B, controlIndex);
GamepadState state = new GamepadState(); state.Y = GetButton(Button.Y, controlIndex);
state.X = GetButton(Button.X, controlIndex);
state.A = GetButton(Button.A, controlIndex); state.RightShoulder = GetButton(Button.RightShoulder, controlIndex);
state.B = GetButton(Button.B, controlIndex); state.LeftShoulder = GetButton(Button.LeftShoulder, controlIndex);
state.Y = GetButton(Button.Y, controlIndex); state.RightStick = GetButton(Button.RightStick, controlIndex);
state.X = GetButton(Button.X, controlIndex); state.LeftStick = GetButton(Button.LeftStick, controlIndex);
state.RightShoulder = GetButton(Button.RightShoulder, controlIndex); state.Start = GetButton(Button.Start, controlIndex);
state.LeftShoulder = GetButton(Button.LeftShoulder, controlIndex); state.Back = GetButton(Button.Back, controlIndex);
state.RightStick = GetButton(Button.RightStick, controlIndex);
state.LeftStick = GetButton(Button.LeftStick, controlIndex);
state.Start = GetButton(Button.Start, controlIndex); state.LeftStickAxis = GetAxis(Axis.LeftStick, controlIndex, raw);
state.Back = GetButton(Button.Back, controlIndex); state.rightStickAxis = GetAxis(Axis.RightStick, controlIndex, raw);
state.dPadAxis = GetAxis(Axis.Dpad, controlIndex, raw);
state.LeftStickAxis = GetAxis(Axis.LeftStick, controlIndex, raw); state.Left = (state.dPadAxis.x < 0);
state.rightStickAxis = GetAxis(Axis.RightStick, controlIndex, raw); state.Right = (state.dPadAxis.x > 0);
state.dPadAxis = GetAxis(Axis.Dpad, controlIndex, raw); state.Up = (state.dPadAxis.y > 0);
state.Down = (state.dPadAxis.y < 0);
state.Left = (state.dPadAxis.x < 0); state.LeftTrigger = GetTrigger(Trigger.LeftTrigger, controlIndex, raw);
state.Right = (state.dPadAxis.x > 0); state.RightTrigger = GetTrigger(Trigger.RightTrigger, controlIndex, raw);
state.Up = (state.dPadAxis.y > 0);
state.Down = (state.dPadAxis.y < 0);
state.LeftTrigger = GetTrigger(Trigger.LeftTrigger, controlIndex, raw); return state;
state.RightTrigger = GetTrigger(Trigger.RightTrigger, controlIndex, raw); }
return state;
} }
} public class GamepadState
{
public class GamepadState public bool A = false;
{ public bool B = false;
public bool A = false; public bool X = false;
public bool B = false; public bool Y = false;
public bool X = false; public bool Start = false;
public bool Y = false; public bool Back = false;
public bool Start = false; public bool Left = false;
public bool Back = false; public bool Right = false;
public bool Left = false; public bool Up = false;
public bool Right = false; public bool Down = false;
public bool Up = false; public bool LeftStick = false;
public bool Down = false; public bool RightStick = false;
public bool LeftStick = false; public bool RightShoulder = false;
public bool RightStick = false; public bool LeftShoulder = false;
public bool RightShoulder = false;
public bool LeftShoulder = false;
public Vector2 LeftStickAxis = Vector2.zero; public Vector2 LeftStickAxis = Vector2.zero;
public Vector2 rightStickAxis = Vector2.zero; public Vector2 rightStickAxis = Vector2.zero;
public Vector2 dPadAxis = Vector2.zero; public Vector2 dPadAxis = Vector2.zero;
public float LeftTrigger = 0; public float LeftTrigger = 0;
public float RightTrigger = 0; public float RightTrigger = 0;
} }
} }
\ No newline at end of file
...@@ -125,8 +125,7 @@ public class PlayerInputMapping : MonoBehaviour ...@@ -125,8 +125,7 @@ public class PlayerInputMapping : MonoBehaviour
{ {
if (usesGamepad) if (usesGamepad)
{ {
return (GamePad.GetTrigger(GamePad.Trigger.LeftTrigger, gamepadIndex) > 0.01f) || (GamePad.GetTrigger(GamePad.Trigger.RightTrigger, gamepadIndex) > 0.01f) return GamePad.GetButton(GamePad.Button.LeftShoulder, gamepadIndex) || GamePad.GetButton(GamePad.Button.RightShoulder, gamepadIndex);
|| GamePad.GetButton(GamePad.Button.LeftShoulder, gamepadIndex) || GamePad.GetButton(GamePad.Button.RightShoulder, gamepadIndex);
} }
else return Input.GetKey(keyCodes[(int)Keys.Dash]); else return Input.GetKey(keyCodes[(int)Keys.Dash]);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment