PS4InputPlayer.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. using System;
  2. using UnityEngine;
  3. public class PS4InputPlayer : IInputPlayer
  4. {
  5. public bool GetButton(string buttonName)
  6. {
  7. switch (buttonName)
  8. {
  9. case "DpadLeft":
  10. return UnityEngine.Input.GetAxisRaw("dpad1_horizontal") < -0.2f;
  11. case "DpadRight":
  12. return UnityEngine.Input.GetAxisRaw("dpad1_horizontal") > 0.2f;
  13. case "DpadUp":
  14. return UnityEngine.Input.GetAxisRaw("dpad1_vertical") > 0.2f;
  15. case "DpadDown":
  16. return UnityEngine.Input.GetAxisRaw("dpad1_vertical") < -0.2f;
  17. case "LSLeft":
  18. return UnityEngine.Input.GetAxisRaw("leftstick1horizontal") < -0.002f;
  19. case "LSRight":
  20. return UnityEngine.Input.GetAxisRaw("leftstick1horizontal") > 0.002f;
  21. case "LSUp":
  22. return UnityEngine.Input.GetAxisRaw("leftstick1vertical") < -0.002f;
  23. case "LSDown":
  24. return UnityEngine.Input.GetAxisRaw("leftstick1vertical") > 0.002f;
  25. case "Cross":
  26. return UnityEngine.Input.GetKey(KeyCode.Joystick1Button0);
  27. case "Circle":
  28. return UnityEngine.Input.GetKey(KeyCode.Joystick1Button1);
  29. case "Triangle":
  30. return UnityEngine.Input.GetKey(KeyCode.Joystick1Button3);
  31. case "Square":
  32. return UnityEngine.Input.GetKey(KeyCode.Joystick1Button2);
  33. case "R1":
  34. return UnityEngine.Input.GetKey(KeyCode.Joystick1Button5);
  35. case "L1":
  36. return UnityEngine.Input.GetKey(KeyCode.Joystick1Button4);
  37. case "R2":
  38. return UnityEngine.Input.GetAxisRaw("joystick1_right_trigger") < -0.1f;
  39. case "L2":
  40. return UnityEngine.Input.GetAxisRaw("joystick1_left_trigger") > 0.1f;
  41. case "R3":
  42. return UnityEngine.Input.GetKey(KeyCode.Joystick1Button8);
  43. case "L3":
  44. return UnityEngine.Input.GetKey(KeyCode.Joystick1Button9);
  45. case "Options":
  46. return UnityEngine.Input.GetKey(KeyCode.Joystick1Button7);
  47. }
  48. throw new ArgumentOutOfRangeException("buttonName", buttonName, string.Format("Button \"{0}\" is not exist.", buttonName));
  49. }
  50. public Vector2 GetJoystick(string axis)
  51. {
  52. if (axis != null)
  53. {
  54. if (axis == "LS")
  55. {
  56. return new Vector2(UnityEngine.Input.GetAxis("leftstick1horizontal"), UnityEngine.Input.GetAxis("leftstick1vertical"));
  57. }
  58. if (axis == "RS")
  59. {
  60. return new Vector2(UnityEngine.Input.GetAxis("rightstick1horizontal"), UnityEngine.Input.GetAxis("rightstick1vertical"));
  61. }
  62. }
  63. throw new ArgumentOutOfRangeException("axis", axis);
  64. }
  65. public Vector2 GetJoystickRaw(string axis)
  66. {
  67. if (axis != null)
  68. {
  69. if (axis == "LS")
  70. {
  71. return new Vector2(UnityEngine.Input.GetAxisRaw("leftstick1horizontal"), UnityEngine.Input.GetAxisRaw("leftstick1vertical"));
  72. }
  73. if (axis == "RS")
  74. {
  75. return new Vector2(UnityEngine.Input.GetAxisRaw("rightstick1horizontal"), UnityEngine.Input.GetAxisRaw("rightstick1vertical"));
  76. }
  77. }
  78. throw new ArgumentOutOfRangeException("axis", axis);
  79. }
  80. public void SetVibration(float leftMotorValue, float rightMotorValue)
  81. {
  82. }
  83. public static class DSKeyCode1
  84. {
  85. public const KeyCode Cross = KeyCode.Joystick1Button0;
  86. public const KeyCode Circle = KeyCode.Joystick1Button1;
  87. public const KeyCode Square = KeyCode.Joystick1Button2;
  88. public const KeyCode Triangle = KeyCode.Joystick1Button3;
  89. public const KeyCode L1 = KeyCode.Joystick1Button4;
  90. public const KeyCode R1 = KeyCode.Joystick1Button5;
  91. public const KeyCode TouchPadButton = KeyCode.Joystick1Button6;
  92. public const KeyCode Options = KeyCode.Joystick1Button7;
  93. public const KeyCode L3 = KeyCode.Joystick1Button8;
  94. public const KeyCode R3 = KeyCode.Joystick1Button9;
  95. }
  96. public static class DSAxis1
  97. {
  98. public const string DpadHorizontal = "dpad1_horizontal";
  99. public const string DpadVertical = "dpad1_vertical";
  100. public const string LeftStickHorizontal = "leftstick1horizontal";
  101. public const string LeftStickVertical = "leftstick1vertical";
  102. public const string RightStickHorizontal = "rightstick1horizontal";
  103. public const string RightStickVertical = "rightstick1vertical";
  104. public const string L2 = "joystick1_left_trigger";
  105. public const string R2 = "joystick1_right_trigger";
  106. }
  107. }