InputDriver.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. using System;
  2. using System.Collections;
  3. using System.Runtime.CompilerServices;
  4. using Core;
  5. using FBInput.Controller;
  6. using UnityEngine;
  7. namespace FBInput
  8. {
  9. public class InputDriver : BaseBehaviour
  10. {
  11. public static int Solution { get; set; }
  12. private IEnumerator CheckForControllers()
  13. {
  14. for (;;)
  15. {
  16. string[] controllers = UnityEngine.Input.GetJoystickNames();
  17. if (this._isControllerConnected || controllers.Length <= 0)
  18. {
  19. goto IL_92;
  20. }
  21. string[] array = controllers;
  22. if (InputDriver._003C_003Ef__mg_0024cache0 == null)
  23. {
  24. InputDriver._003C_003Ef__mg_0024cache0 = new Predicate<string>(string.IsNullOrEmpty);
  25. }
  26. if (Array.TrueForAll<string>(array, InputDriver._003C_003Ef__mg_0024cache0))
  27. {
  28. goto IL_92;
  29. }
  30. this._isControllerConnected = true;
  31. UnityEngine.Debug.Log("Connected");
  32. IL_F2:
  33. yield return new WaitForSeconds(1f);
  34. continue;
  35. IL_92:
  36. if (this._isControllerConnected)
  37. {
  38. if (controllers.Length != 0)
  39. {
  40. string[] array2 = controllers;
  41. if (InputDriver._003C_003Ef__mg_0024cache1 == null)
  42. {
  43. InputDriver._003C_003Ef__mg_0024cache1 = new Predicate<string>(string.IsNullOrEmpty);
  44. }
  45. if (!Array.TrueForAll<string>(array2, InputDriver._003C_003Ef__mg_0024cache1))
  46. {
  47. goto IL_F2;
  48. }
  49. }
  50. this._isControllerConnected = false;
  51. UnityEngine.Debug.Log("Disconnected");
  52. goto IL_F2;
  53. }
  54. goto IL_F2;
  55. }
  56. yield break;
  57. }
  58. private void Awake()
  59. {
  60. base.StartCoroutine(this.CheckForControllers());
  61. }
  62. private void Update()
  63. {
  64. for (int i = 0; i < this._controllers.Length; i++)
  65. {
  66. this._controllers[i].Update();
  67. }
  68. this.UpdateGlobalInput();
  69. this.UpdateGameInput();
  70. this.UpdateUIInput();
  71. this.UpdateStoryInput();
  72. this.UpdateShiInput();
  73. }
  74. private void UpdateGlobalInput()
  75. {
  76. Core.Input.AnyKey.Update(DS4Controller.AnyKey.Pressed || VirtualController.AnyKey.Pressed);
  77. }
  78. private void UpdateGameInput()
  79. {
  80. Vector2 vector = Vector2.zero;
  81. bool flag = false;
  82. bool flag2 = false;
  83. bool flag3 = false;
  84. bool flag4 = false;
  85. bool flag5 = false;
  86. bool flag6 = false;
  87. bool flag7 = false;
  88. bool flag8 = false;
  89. bool flag9 = false;
  90. bool flag10 = false;
  91. bool flag11 = false;
  92. bool flag12 = false;
  93. bool flag13 = false;
  94. bool flag14 = false;
  95. bool flag15 = false;
  96. bool flag16 = false;
  97. bool flag17 = false;
  98. bool flag18 = false;
  99. bool flag19 = false;
  100. bool flag20 = false;
  101. bool flag21 = false;
  102. bool flag22 = false;
  103. bool flag23 = false;
  104. bool flag24 = false;
  105. bool flag25 = false;
  106. bool flag26 = false;
  107. bool flag27 = false;
  108. bool flag28 = false;
  109. bool flag29 = false;
  110. if (this._isControllerConnected)
  111. {
  112. Vector2 value = DS4Controller.LS.Value;
  113. vector += new Vector2(Mathf.Abs(value.x), Mathf.Abs(value.y));
  114. flag |= (Vector2.Angle(Vector2.up, vector) <= 45f);
  115. flag2 |= (DS4Controller.LS.Value.x > 0f);
  116. flag3 |= (DS4Controller.LS.Value.x < 0f);
  117. flag4 |= (DS4Controller.LS.Value.y < 0f && flag);
  118. flag5 |= (DS4Controller.LS.Value.y > 0f && flag);
  119. bool pressed = DS4Controller.Right.Pressed;
  120. bool pressed2 = DS4Controller.Left.Pressed;
  121. bool pressed3 = DS4Controller.Up.Pressed;
  122. bool pressed4 = DS4Controller.Down.Pressed;
  123. flag2 = (flag2 || pressed);
  124. flag3 = (flag3 || pressed2);
  125. flag4 = (flag4 || pressed3);
  126. flag5 = (flag5 || pressed4);
  127. flag17 |= (Vector2.Angle(Vector2.up, vector) <= 22.5f);
  128. flag18 |= (Vector2.Angle(Vector2.right, vector) <= 22.5f);
  129. flag19 |= (vector != Vector2.zero && Vector2.Angle(Vector2.up, vector) > 22.5f && Vector2.Angle(Vector2.right, vector) > 22.5f);
  130. bool flag30 = flag17 && DS4Controller.LS.Value.y < 0f;
  131. bool flag31 = flag17 && DS4Controller.LS.Value.y > 0f;
  132. bool flag32 = flag18 && DS4Controller.LS.Value.x < 0f;
  133. bool flag33 = flag18 && DS4Controller.LS.Value.x > 0f;
  134. bool flag34 = flag19 && DS4Controller.LS.Value.y < 0f && DS4Controller.LS.Value.x > 0f;
  135. bool flag35 = flag19 && DS4Controller.LS.Value.y > 0f && DS4Controller.LS.Value.x > 0f;
  136. bool flag36 = flag19 && DS4Controller.LS.Value.y < 0f && DS4Controller.LS.Value.x < 0f;
  137. bool flag37 = flag19 && DS4Controller.LS.Value.y > 0f && DS4Controller.LS.Value.x > 0f;
  138. flag22 |= (pressed2 || flag32);
  139. flag23 |= (pressed || flag33);
  140. flag20 |= (pressed3 || flag30);
  141. flag21 |= (pressed4 || flag31);
  142. flag24 |= ((pressed && pressed3) || flag34);
  143. flag25 |= ((pressed && pressed4) || flag35);
  144. flag26 |= ((pressed2 && pressed3) || flag36);
  145. flag27 |= ((pressed2 && pressed4) || flag37);
  146. flag10 |= DS4Controller.Square.Pressed;
  147. flag8 |= DS4Controller.Triangle.Pressed;
  148. flag9 |= DS4Controller.Cross.Pressed;
  149. flag11 |= DS4Controller.Square.Pressed;
  150. flag7 |= DS4Controller.Circle.Pressed;
  151. flag13 |= (flag10 && flag5);
  152. flag14 |= (flag10 && flag4);
  153. flag15 |= (flag5 && flag9);
  154. flag16 |= DS4Controller.R1.Pressed;
  155. bool pressed5 = DS4Controller.L1.Pressed;
  156. flag6 |= (pressed5 && flag10);
  157. flag12 |= DS4Controller.Circle.Pressed;
  158. flag28 |= DS4Controller.L2.Pressed;
  159. flag29 |= DS4Controller.R2.Pressed;
  160. }
  161. Vector2 value2 = VirtualController.LeftJoystick.Value;
  162. vector += new Vector2(Mathf.Abs(value2.x), Mathf.Abs(value2.y));
  163. flag |= (Vector2.Angle(Vector2.up, vector) <= 45f);
  164. flag2 |= (VirtualController.LeftJoystick.Value.x > 0f);
  165. flag3 |= (VirtualController.LeftJoystick.Value.x < 0f);
  166. flag4 |= (VirtualController.LeftJoystick.Value.y > 0f && flag);
  167. flag5 |= (VirtualController.LeftJoystick.Value.y < 0f && flag);
  168. flag6 |= VirtualController.Button1.Pressed;
  169. flag7 |= VirtualController.Button3.Pressed;
  170. flag8 = (flag8 || flag7);
  171. flag9 |= VirtualController.Button4.Pressed;
  172. flag10 |= VirtualController.Button5.Pressed;
  173. flag11 = (flag11 || flag10);
  174. flag12 = (flag12 || flag10);
  175. flag28 |= (VirtualController.L2.Pressed || VirtualController.Button6.Pressed);
  176. flag29 |= VirtualController.R2.Pressed;
  177. int solution = InputDriver.Solution;
  178. if (solution != 0)
  179. {
  180. if (solution == 1)
  181. {
  182. flag14 |= VirtualController.Button2.Pressed;
  183. flag13 = (flag13 || flag14);
  184. Vector2 value3 = VirtualController.LeftSwipe.Value;
  185. Vector2 vector2 = new Vector2(Mathf.Abs(value3.x), Mathf.Abs(value3.y));
  186. flag17 |= (Vector2.Angle(Vector2.up, vector2) <= 22.5f);
  187. flag18 |= (Vector2.Angle(Vector2.right, vector2) <= 22.5f);
  188. flag19 |= (vector2 != Vector2.zero && Vector2.Angle(Vector2.up, vector2) > 22.5f && Vector2.Angle(Vector2.right, vector2) > 22.5f);
  189. flag20 |= (flag17 && VirtualController.LeftSwipe.Value.y > 0f);
  190. flag21 |= (flag17 && VirtualController.LeftSwipe.Value.y < 0f);
  191. flag22 |= (flag18 && VirtualController.LeftSwipe.Value.x < 0f);
  192. flag23 |= (flag18 && VirtualController.LeftSwipe.Value.x > 0f);
  193. flag24 |= (flag19 && VirtualController.LeftSwipe.Value.x > 0f && VirtualController.LeftSwipe.Value.y > 0f);
  194. flag25 |= (flag19 && VirtualController.LeftSwipe.Value.x > 0f && VirtualController.LeftSwipe.Value.y < 0f);
  195. flag26 |= (flag19 && VirtualController.LeftSwipe.Value.x < 0f && VirtualController.LeftSwipe.Value.y > 0f);
  196. flag27 |= (flag19 && VirtualController.LeftSwipe.Value.x < 0f && VirtualController.LeftSwipe.Value.y < 0f);
  197. }
  198. }
  199. else
  200. {
  201. flag13 |= (flag10 && flag5);
  202. flag14 |= (flag10 && flag4);
  203. flag17 |= (Vector2.Angle(Vector2.up, vector) <= 22.5f);
  204. flag18 |= (Vector2.Angle(Vector2.right, vector) <= 22.5f);
  205. flag19 |= (vector != Vector2.zero && Vector2.Angle(Vector2.up, vector) > 22.5f && Vector2.Angle(Vector2.right, vector) > 22.5f);
  206. flag20 |= (flag17 && VirtualController.LeftJoystick.Value.y > 0f);
  207. flag21 |= (flag17 && VirtualController.LeftJoystick.Value.y < 0f);
  208. flag22 |= (flag18 && VirtualController.LeftJoystick.Value.x < 0f);
  209. flag23 |= (flag18 && VirtualController.LeftJoystick.Value.x > 0f);
  210. flag24 |= (flag19 && VirtualController.LeftJoystick.Value.x > 0f && VirtualController.LeftJoystick.Value.y > 0f);
  211. flag25 |= (flag19 && VirtualController.LeftJoystick.Value.x > 0f && VirtualController.LeftJoystick.Value.y < 0f);
  212. flag26 |= (flag19 && VirtualController.LeftJoystick.Value.x < 0f && VirtualController.LeftJoystick.Value.y > 0f);
  213. flag27 |= (flag19 && VirtualController.LeftJoystick.Value.x < 0f && VirtualController.LeftJoystick.Value.y < 0f);
  214. flag16 |= VirtualController.Button2.Pressed;
  215. }
  216. Core.Input.Game.MoveDown.Update(flag5);
  217. Core.Input.Game.MoveLeft.Update(flag3);
  218. Core.Input.Game.MoveRight.Update(flag2);
  219. Core.Input.Game.MoveUp.Update(flag4);
  220. Core.Input.Game.JumpDown.Update(flag15);
  221. Core.Input.Game.BladeStorm.Update(flag6);
  222. Core.Input.Game.UpRising.Update(flag14);
  223. Core.Input.Game.HitGround.Update(flag13);
  224. Core.Input.Game.Execute.Update(flag7);
  225. Core.Input.Game.CirtAtk.Update(flag8);
  226. Core.Input.Game.Jump.Update(flag9);
  227. Core.Input.Game.Atk.Update(flag10);
  228. Core.Input.Game.Charging.Update(flag11);
  229. Core.Input.Game.Search.Update(flag12);
  230. Core.Input.Game.Flash.Left.Update(flag22 && flag16);
  231. Core.Input.Game.Flash.Right.Update(flag23 && flag16);
  232. Core.Input.Game.Flash.Up.Update(flag20 && flag16);
  233. Core.Input.Game.Flash.Down.Update(flag21 && flag16);
  234. Core.Input.Game.Flash.RightUp.Update(flag24 && flag16);
  235. Core.Input.Game.Flash.RightDown.Update(flag25 && flag16);
  236. Core.Input.Game.Flash.LeftUp.Update(flag26 && flag16);
  237. Core.Input.Game.Flash.LeftDown.Update(flag27 && flag16);
  238. Core.Input.Game.Flash.FaceDirection.Update(flag16);
  239. Core.Input.Game.L2.Update(flag28);
  240. Core.Input.Game.R2.Update(flag29);
  241. }
  242. private void UpdateUIInput()
  243. {
  244. Core.Input.UI.Up.Update(DS4Controller.Up.Pressed || DS4Controller.LSUp.Pressed);
  245. Core.Input.UI.Down.Update(DS4Controller.Down.Pressed || DS4Controller.LSDown.Pressed);
  246. Core.Input.UI.Left.Update(DS4Controller.Left.Pressed || DS4Controller.LSLeft.Pressed);
  247. Core.Input.UI.Right.Update(DS4Controller.Right.Pressed || DS4Controller.LSRight.Pressed);
  248. bool pressed = DS4Controller.Circle.Pressed;
  249. bool pressed2 = DS4Controller.Cross.Pressed;
  250. bool pressed3 = DS4Controller.Options.Pressed;
  251. bool pressed4 = VirtualController.Button5.Pressed;
  252. bool flag = VirtualController.Button4.Pressed || UnityEngine.Input.GetKey(KeyCode.Escape);
  253. bool pressed5 = VirtualController.Options.Pressed;
  254. Core.Input.UI.Confirm.Update(pressed || pressed4);
  255. Core.Input.UI.Cancel.Update(pressed2 || flag);
  256. Core.Input.UI.Pause.Update(pressed3 || pressed5);
  257. Core.Input.UI.Debug.Update(DS4Controller.R3.Pressed || UnityEngine.Input.GetKey(KeyCode.BackQuote));
  258. }
  259. private void UpdateStoryInput()
  260. {
  261. Core.Input.Story.Skip.Update(DS4Controller.Triangle.Pressed || UnityEngine.Input.GetKey(KeyCode.Escape) || VirtualController.Button3.Pressed);
  262. }
  263. private void UpdateShiInput()
  264. {
  265. Vector2 to = new Vector2(Mathf.Abs(VirtualController.LeftJoystick.Value.x), Mathf.Abs(VirtualController.LeftJoystick.Value.y));
  266. bool flag = Vector2.Angle(Vector2.up, to) <= 45f;
  267. bool flag2 = VirtualController.LeftJoystick.Value.x > 0f;
  268. bool flag3 = VirtualController.LeftJoystick.Value.x < 0f;
  269. bool flag4 = VirtualController.LeftJoystick.Value.y > 0f && flag;
  270. bool flag5 = VirtualController.LeftJoystick.Value.y < 0f && flag;
  271. Core.Input.Shi.Down.Update(DS4Controller.Down.Pressed || DS4Controller.LSDown.Pressed || flag5);
  272. Core.Input.Shi.Up.Update(DS4Controller.Up.Pressed || DS4Controller.LSUp.Pressed || flag4);
  273. Core.Input.Shi.Left.Update(DS4Controller.Left.Pressed || DS4Controller.LSLeft.Pressed || flag3);
  274. Core.Input.Shi.Right.Update(DS4Controller.Right.Pressed || DS4Controller.LSRight.Pressed || flag2);
  275. Core.Input.Shi.Jump.Update(DS4Controller.Square.Pressed || DS4Controller.Cross.Pressed || VirtualController.Button5.Pressed);
  276. Core.Input.Shi.Pause.Update(DS4Controller.Options.Pressed);
  277. }
  278. private IController[] _controllers = new IController[]
  279. {
  280. new DS4Controller(),
  281. new VirtualController()
  282. };
  283. private bool _isControllerConnected;
  284. [CompilerGenerated]
  285. private static Predicate<string> _003C_003Ef__mg_0024cache0;
  286. [CompilerGenerated]
  287. private static Predicate<string> _003C_003Ef__mg_0024cache1;
  288. public static class Vibration
  289. {
  290. public static void SetVibration(float leftMotorValue, float rightMotorValue)
  291. {
  292. }
  293. }
  294. }
  295. }