DNP_InputHandler.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. #if ENABLE_INPUT_SYSTEM && DNP_NewInputSystem
  5. using UnityEngine.InputSystem;
  6. namespace DamageNumbersPro.Demo
  7. {
  8. public static class DNP_InputHandler
  9. {
  10. // Directions
  11. public static bool GetRight()
  12. {
  13. if(Keyboard.current == null)
  14. {
  15. return false;
  16. }
  17. else
  18. {
  19. return Keyboard.current[Key.D].isPressed || Keyboard.current[Key.RightArrow].isPressed;
  20. }
  21. }
  22. public static bool GetLeft()
  23. {
  24. if (Keyboard.current == null)
  25. {
  26. return false;
  27. }
  28. else
  29. {
  30. return Keyboard.current[Key.A].isPressed || Keyboard.current[Key.LeftArrow].isPressed;
  31. }
  32. }
  33. public static bool GetBack()
  34. {
  35. if (Keyboard.current == null)
  36. {
  37. return false;
  38. }
  39. else
  40. {
  41. return Keyboard.current[Key.S].isPressed || Keyboard.current[Key.DownArrow].isPressed;
  42. }
  43. }
  44. public static bool GetForward()
  45. {
  46. if (Keyboard.current == null)
  47. {
  48. return false;
  49. }
  50. else
  51. {
  52. return Keyboard.current[Key.W].isPressed || Keyboard.current[Key.UpArrow].isPressed;
  53. }
  54. }
  55. // Vertical
  56. public static bool GetJump()
  57. {
  58. if (Keyboard.current == null)
  59. {
  60. return false;
  61. }
  62. else
  63. {
  64. return Keyboard.current[Key.Space].isPressed;
  65. }
  66. }
  67. public static bool GetUp()
  68. {
  69. if (Keyboard.current == null)
  70. {
  71. return false;
  72. }
  73. else
  74. {
  75. return Keyboard.current[Key.E].isPressed || Keyboard.current[Key.Space].isPressed;
  76. }
  77. }
  78. public static bool GetDown()
  79. {
  80. if (Keyboard.current == null)
  81. {
  82. return false;
  83. }
  84. else
  85. {
  86. return Keyboard.current[Key.Q].isPressed || Keyboard.current[Key.LeftShift].isPressed;
  87. }
  88. }
  89. // Mouse
  90. public static bool GetLeftClick()
  91. {
  92. if (Mouse.current == null)
  93. {
  94. return false;
  95. }
  96. else
  97. {
  98. return Mouse.current.leftButton.wasPressedThisFrame;
  99. }
  100. }
  101. public static bool GetLeftHeld()
  102. {
  103. if (Mouse.current == null)
  104. {
  105. return false;
  106. }
  107. else
  108. {
  109. return Mouse.current.leftButton.isPressed;
  110. }
  111. }
  112. public static bool GetRightClick()
  113. {
  114. if (Mouse.current == null)
  115. {
  116. return false;
  117. }
  118. else
  119. {
  120. return Mouse.current.rightButton.wasPressedThisFrame;
  121. }
  122. }
  123. public static bool GetRightHeld()
  124. {
  125. if (Mouse.current == null)
  126. {
  127. return false;
  128. }
  129. else
  130. {
  131. return Mouse.current.rightButton.isPressed;
  132. }
  133. }
  134. public static Vector2 GetMouseDelta()
  135. {
  136. if (Mouse.current == null)
  137. {
  138. return Vector2.zero;
  139. }
  140. else
  141. {
  142. return 100f * Mouse.current.delta.ReadValue() / (float) Screen.height;
  143. }
  144. }
  145. public static float GetMouseScroll()
  146. {
  147. if (Mouse.current == null)
  148. {
  149. return 0;
  150. }
  151. else
  152. {
  153. return Mouse.current.scroll.ReadValue().y;
  154. }
  155. }
  156. // Escape
  157. public static bool GetEscape()
  158. {
  159. if (Mouse.current == null)
  160. {
  161. return false;
  162. }
  163. else
  164. {
  165. return Keyboard.current[Key.Escape].wasPressedThisFrame;
  166. }
  167. }
  168. }
  169. }
  170. #else
  171. namespace DamageNumbersPro.Demo
  172. {
  173. public static class DNP_InputHandler
  174. {
  175. // Directions
  176. public static bool GetRight()
  177. {
  178. return Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow);
  179. }
  180. public static bool GetLeft()
  181. {
  182. return Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow);
  183. }
  184. public static bool GetBack()
  185. {
  186. return Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow);
  187. }
  188. public static bool GetForward()
  189. {
  190. return Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow);
  191. }
  192. // Vertical
  193. public static bool GetJump()
  194. {
  195. return Input.GetKey(KeyCode.Space);
  196. }
  197. public static bool GetUp()
  198. {
  199. return Input.GetKey(KeyCode.E) || Input.GetKey(KeyCode.Space);
  200. }
  201. public static bool GetDown()
  202. {
  203. return Input.GetKey(KeyCode.Q) || Input.GetKey(KeyCode.LeftShift);
  204. }
  205. // Other
  206. public static bool GetLeftClick()
  207. {
  208. return Input.GetMouseButtonDown(0);
  209. }
  210. public static bool GetLeftHeld()
  211. {
  212. return Input.GetMouseButton(0);
  213. }
  214. public static bool GetRightClick()
  215. {
  216. return Input.GetMouseButtonDown(1);
  217. }
  218. public static bool GetRightHeld()
  219. {
  220. return Input.GetMouseButton(1);
  221. }
  222. public static Vector2 GetMouseDelta()
  223. {
  224. return new Vector2(Input.GetAxisRaw("Mouse X") * 2f, Input.GetAxisRaw("Mouse Y") * 2f);
  225. }
  226. public static float GetMouseScroll()
  227. {
  228. return Input.mouseScrollDelta.y;
  229. }
  230. // Escape
  231. public static bool GetEscape()
  232. {
  233. return Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.Tab) || Input.GetKeyDown(KeyCode.KeypadEnter) || Input.GetKeyDown(KeyCode.P) || Input.GetKeyDown(KeyCode.I);
  234. }
  235. }
  236. }
  237. #endif