HandEvent.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using SC.XR.Unity.Module_InputSystem.InputDeviceHand;
  6. public class HandEvent : MonoBehaviour
  7. {
  8. private List<GameObject> dynamicEvents;
  9. private List<GameObject> staticEvents;
  10. public Material outlineL;
  11. public Material outlineR;
  12. public Material outlineRB;
  13. public Material outlineRL;
  14. public Material outlineRR;
  15. // Start is called before the first frame update
  16. void Start()
  17. {
  18. InputDeviceHandPartEventBase.eventDelegate += HandEventDelegate;
  19. dynamicEvents = GameObject.Find("DynamicEvent").GetAllChildren();
  20. staticEvents = GameObject.Find("StaticEvent").GetAllChildren();
  21. }
  22. // Update is called once per frame
  23. void Update()
  24. {
  25. }
  26. void OnDestroy()
  27. {
  28. InputDeviceHandPartEventBase.eventDelegate -= HandEventDelegate;
  29. }
  30. void HandEventDelegate(InputDeviceHandPart inputDeviceHandPart, HandEventType eventType, float EventPercent)
  31. {
  32. if (inputDeviceHandPart.PartType == SC.XR.Unity.Module_InputSystem.InputDevicePartType.HandLeft)
  33. {
  34. if (eventType == HandEventType.Static_Fist)
  35. {
  36. staticEvents[0].GetComponent<Image>().material = outlineL;
  37. StartCoroutine("SetToOrigin", 0);
  38. }
  39. else if (eventType == HandEventType.Static_Point)
  40. {
  41. staticEvents[1].GetComponent<Image>().material = outlineL;
  42. StartCoroutine("SetToOrigin", 1);
  43. }
  44. else if (eventType == HandEventType.Static_Peace)
  45. {
  46. staticEvents[2].GetComponent<Image>().material = outlineL;
  47. StartCoroutine("SetToOrigin", 2);
  48. }
  49. else if (eventType == HandEventType.Static_Three)
  50. {
  51. staticEvents[3].GetComponent<Image>().material = outlineL;
  52. StartCoroutine("SetToOrigin", 3);
  53. }
  54. else if (eventType == HandEventType.Static_Four)
  55. {
  56. staticEvents[4].GetComponent<Image>().material = outlineL;
  57. StartCoroutine("SetToOrigin", 4);
  58. }
  59. else if (eventType == HandEventType.Static_Five)
  60. {
  61. staticEvents[5].GetComponent<Image>().material = outlineL;
  62. StartCoroutine("SetToOrigin", 5);
  63. }
  64. else if (eventType == HandEventType.Static_Phone)
  65. {
  66. staticEvents[6].GetComponent<Image>().material = outlineL;
  67. StartCoroutine("SetToOrigin", 6);
  68. }
  69. else if (eventType == HandEventType.Static_Damn)
  70. {
  71. staticEvents[7].GetComponent<Image>().material = outlineL;
  72. StartCoroutine("SetToOrigin", 7);
  73. }
  74. else if (eventType == HandEventType.Static_Gun)
  75. {
  76. staticEvents[8].GetComponent<Image>().material = outlineL;
  77. StartCoroutine("SetToOrigin", 8);
  78. }
  79. else if (eventType == HandEventType.Static_Like)
  80. {
  81. staticEvents[9].GetComponent<Image>().material = outlineL;
  82. StartCoroutine("SetToOrigin", 9);
  83. }
  84. else if (eventType == HandEventType.Static_No_Like)
  85. {
  86. staticEvents[10].GetComponent<Image>().material = outlineL;
  87. StartCoroutine("SetToOrigin", 10);
  88. }
  89. else if (eventType == HandEventType.Static_OK)
  90. {
  91. staticEvents[11].GetComponent<Image>().material = outlineL;
  92. StartCoroutine("SetToOrigin", 11);
  93. }
  94. else if (eventType == HandEventType.Static_RockAndRoll)
  95. {
  96. staticEvents[12].GetComponent<Image>().material = outlineL;
  97. StartCoroutine("SetToOrigin", 12);
  98. }
  99. else if (eventType == HandEventType.Dynamic_Click_Down ||
  100. eventType == HandEventType.Dynamic_Click_Hold)
  101. {
  102. if (dynamicEvents[0].GetComponent<RawImage>().material == outlineRR ||
  103. dynamicEvents[0].GetComponent<RawImage>().material == outlineRB)
  104. {
  105. dynamicEvents[0].GetComponent<RawImage>().material = outlineRB;
  106. }
  107. else
  108. {
  109. dynamicEvents[0].GetComponent<RawImage>().material = outlineRL;
  110. }
  111. }
  112. else if (eventType == HandEventType.Dynamic_Click)
  113. {
  114. if (dynamicEvents[0].GetComponent<RawImage>().material == outlineRR ||
  115. dynamicEvents[0].GetComponent<RawImage>().material == outlineRB)
  116. {
  117. dynamicEvents[0].GetComponent<RawImage>().material = outlineRB;
  118. }
  119. else
  120. {
  121. dynamicEvents[0].GetComponent<RawImage>().material = outlineRL;
  122. }
  123. StartCoroutine("SetAboutClick", 0);
  124. }
  125. else if (eventType == HandEventType.Dynamic_Click_Up)
  126. {
  127. if (dynamicEvents[0].GetComponent<RawImage>().material == outlineRB)
  128. {
  129. dynamicEvents[0].GetComponent<RawImage>().material = outlineRR;
  130. }
  131. else
  132. {
  133. dynamicEvents[0].GetComponent<RawImage>().material = null;
  134. }
  135. }
  136. else if (eventType == HandEventType.Dynamic_Open)
  137. {
  138. if (dynamicEvents[0].GetComponent<RawImage>().material == outlineRB ||
  139. dynamicEvents[0].GetComponent<RawImage>().material == outlineRR)
  140. {
  141. dynamicEvents[0].GetComponent<RawImage>().material = outlineRR;
  142. }
  143. else
  144. {
  145. dynamicEvents[0].GetComponent<RawImage>().material = null;
  146. }
  147. dynamicEvents[1].GetComponent<RawImage>().material = outlineRL;
  148. StartCoroutine("SetToOrigin", 21);
  149. }
  150. else if (eventType == HandEventType.Dynamic_Flip)
  151. {
  152. if (dynamicEvents[0].GetComponent<RawImage>().material == outlineRB ||
  153. dynamicEvents[0].GetComponent<RawImage>().material == outlineRR)
  154. {
  155. dynamicEvents[0].GetComponent<RawImage>().material = outlineRR;
  156. }
  157. else
  158. {
  159. dynamicEvents[0].GetComponent<RawImage>().material = null;
  160. }
  161. dynamicEvents[2].GetComponent<RawImage>().material = outlineRL;
  162. StartCoroutine("SetToOrigin", 22);
  163. }
  164. else if (eventType == HandEventType.Null)
  165. {
  166. if (dynamicEvents[0].GetComponent<RawImage>().material == outlineRL)
  167. {
  168. dynamicEvents[0].GetComponent<RawImage>().material = null;
  169. }
  170. }
  171. }
  172. else if (inputDeviceHandPart.PartType == SC.XR.Unity.Module_InputSystem.InputDevicePartType.HandRight)
  173. {
  174. if (eventType == HandEventType.Static_Fist)
  175. {
  176. staticEvents[0].GetComponent<Image>().material = outlineR;
  177. StartCoroutine("SetToOrigin", 0);
  178. }
  179. else if (eventType == HandEventType.Static_Point)
  180. {
  181. staticEvents[1].GetComponent<Image>().material = outlineR;
  182. StartCoroutine("SetToOrigin", 1);
  183. }
  184. else if (eventType == HandEventType.Static_Peace)
  185. {
  186. staticEvents[2].GetComponent<Image>().material = outlineR;
  187. StartCoroutine("SetToOrigin", 2);
  188. }
  189. else if (eventType == HandEventType.Static_Three)
  190. {
  191. staticEvents[3].GetComponent<Image>().material = outlineR;
  192. StartCoroutine("SetToOrigin", 3);
  193. }
  194. else if (eventType == HandEventType.Static_Four)
  195. {
  196. staticEvents[4].GetComponent<Image>().material = outlineR;
  197. StartCoroutine("SetToOrigin", 4);
  198. }
  199. else if (eventType == HandEventType.Static_Five)
  200. {
  201. staticEvents[5].GetComponent<Image>().material = outlineR;
  202. StartCoroutine("SetToOrigin", 5);
  203. }
  204. else if (eventType == HandEventType.Static_Phone)
  205. {
  206. staticEvents[6].GetComponent<Image>().material = outlineR;
  207. StartCoroutine("SetToOrigin", 6);
  208. }
  209. else if (eventType == HandEventType.Static_Damn)
  210. {
  211. staticEvents[7].GetComponent<Image>().material = outlineR;
  212. StartCoroutine("SetToOrigin", 7);
  213. }
  214. else if (eventType == HandEventType.Static_Gun)
  215. {
  216. staticEvents[8].GetComponent<Image>().material = outlineR;
  217. StartCoroutine("SetToOrigin", 8);
  218. }
  219. else if (eventType == HandEventType.Static_Like)
  220. {
  221. staticEvents[9].GetComponent<Image>().material = outlineR;
  222. StartCoroutine("SetToOrigin", 9);
  223. }
  224. else if (eventType == HandEventType.Static_No_Like)
  225. {
  226. staticEvents[10].GetComponent<Image>().material = outlineR;
  227. StartCoroutine("SetToOrigin", 10);
  228. }
  229. else if (eventType == HandEventType.Static_OK)
  230. {
  231. staticEvents[11].GetComponent<Image>().material = outlineR;
  232. StartCoroutine("SetToOrigin", 11);
  233. }
  234. else if (eventType == HandEventType.Static_RockAndRoll)
  235. {
  236. staticEvents[12].GetComponent<Image>().material = outlineR;
  237. StartCoroutine("SetToOrigin", 12);
  238. }
  239. else if (eventType == HandEventType.Dynamic_Click_Down ||
  240. eventType == HandEventType.Dynamic_Click_Hold)
  241. {
  242. if (dynamicEvents[0].GetComponent<RawImage>().material == outlineRL ||
  243. dynamicEvents[0].GetComponent<RawImage>().material == outlineRB)
  244. {
  245. dynamicEvents[0].GetComponent<RawImage>().material = outlineRB;
  246. }
  247. else
  248. {
  249. dynamicEvents[0].GetComponent<RawImage>().material = outlineRR;
  250. }
  251. }
  252. else if (eventType == HandEventType.Dynamic_Click)
  253. {
  254. if (dynamicEvents[0].GetComponent<RawImage>().material == outlineRL ||
  255. dynamicEvents[0].GetComponent<RawImage>().material == outlineRB)
  256. {
  257. dynamicEvents[0].GetComponent<RawImage>().material = outlineRB;
  258. }
  259. else
  260. {
  261. dynamicEvents[0].GetComponent<RawImage>().material = outlineRR;
  262. }
  263. StartCoroutine("SetAboutClick", 1);
  264. }
  265. else if (eventType == HandEventType.Dynamic_Click_Up)
  266. {
  267. if (dynamicEvents[0].GetComponent<RawImage>().material == outlineRB)
  268. {
  269. dynamicEvents[0].GetComponent<RawImage>().material = outlineRL;
  270. }
  271. else
  272. {
  273. dynamicEvents[0].GetComponent<RawImage>().material = null;
  274. }
  275. }
  276. else if (eventType == HandEventType.Dynamic_Open)
  277. {
  278. if (dynamicEvents[0].GetComponent<RawImage>().material == outlineRB ||
  279. dynamicEvents[0].GetComponent<RawImage>().material == outlineRL)
  280. {
  281. dynamicEvents[0].GetComponent<RawImage>().material = outlineRL;
  282. }
  283. else
  284. {
  285. dynamicEvents[0].GetComponent<RawImage>().material = null;
  286. }
  287. dynamicEvents[1].GetComponent<RawImage>().material = outlineRR;
  288. StartCoroutine("SetToOrigin", 21);
  289. }
  290. else if (eventType == HandEventType.Dynamic_Flip)
  291. {
  292. if (dynamicEvents[0].GetComponent<RawImage>().material == outlineRB ||
  293. dynamicEvents[0].GetComponent<RawImage>().material == outlineRL)
  294. {
  295. dynamicEvents[0].GetComponent<RawImage>().material = outlineRL;
  296. }
  297. else
  298. {
  299. dynamicEvents[0].GetComponent<RawImage>().material = null;
  300. }
  301. dynamicEvents[2].GetComponent<RawImage>().material = outlineRR;
  302. StartCoroutine("SetToOrigin", 22);
  303. }
  304. else if (eventType == HandEventType.Null)
  305. {
  306. if (dynamicEvents[0].GetComponent<RawImage>().material == outlineRR)
  307. {
  308. dynamicEvents[0].GetComponent<RawImage>().material = null;
  309. }
  310. }
  311. }
  312. }
  313. private IEnumerator SetToOrigin(int keynumber)
  314. {
  315. yield return new WaitForSeconds(1);
  316. if (keynumber < 20)
  317. {
  318. staticEvents[keynumber].GetComponent<Image>().material = null;
  319. }
  320. else
  321. {
  322. keynumber -= 20;
  323. dynamicEvents[keynumber].GetComponent<RawImage>().material = null;
  324. }
  325. }
  326. private IEnumerator SetAboutClick(int lr)
  327. {
  328. yield return new WaitForSeconds(1);
  329. if (lr == 0)
  330. {
  331. if (dynamicEvents[0].GetComponent<RawImage>().material == outlineRL)
  332. {
  333. dynamicEvents[0].GetComponent<RawImage>().material = null;
  334. }
  335. else if (dynamicEvents[0].GetComponent<RawImage>().material == outlineRB)
  336. {
  337. dynamicEvents[0].GetComponent<RawImage>().material = outlineRR;
  338. }
  339. }
  340. else if (lr == 1)
  341. {
  342. if (dynamicEvents[0].GetComponent<RawImage>().material == outlineRR)
  343. {
  344. dynamicEvents[0].GetComponent<RawImage>().material = null;
  345. }
  346. else if (dynamicEvents[0].GetComponent<RawImage>().material == outlineRB)
  347. {
  348. dynamicEvents[0].GetComponent<RawImage>().material = outlineRL;
  349. }
  350. }
  351. }
  352. }