InputModuleManager.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. using System;
  5. using UnityEngine.EventSystems;
  6. using Rokid.UXR.Utility;
  7. using Rokid.UXR.Module;
  8. namespace Rokid.UXR.Interaction
  9. {
  10. public enum InputModuleType
  11. {
  12. None = 1 << 0,
  13. ThreeDof = 1 << 1, //手机3dof 射线
  14. Gesture = 1 << 2, //手势
  15. Mouse = 1 << 3, // 蓝牙鼠标
  16. ButtonMouse = 1 << 4, // 滑鼠
  17. TouchPad = 1 << 5, // 触摸屏
  18. }
  19. [Flags]
  20. public enum ActiveModuleType
  21. {
  22. ThreeDof = 1 << 0, //手机 3dof 射线
  23. Gesture = 1 << 1, //手势
  24. Mouse = 1 << 2, // 蓝牙鼠标
  25. ButtonMouse = 1 << 3, // 滑鼠
  26. TouchPad = 1 << 4, // 触摸屏
  27. }
  28. [Flags]
  29. public enum ActiveHandType
  30. {
  31. LeftHand = 1 << 0, //左手
  32. RightHand = 1 << 1, //右手
  33. }
  34. [Flags]
  35. public enum ActiveHandOrientationType
  36. {
  37. Back = 1 << 0, //左手
  38. Palm = 1 << 1, //右手
  39. }
  40. [Flags]
  41. public enum ActiveHandInteractorType
  42. {
  43. Far = 1 << 0, //远场交互
  44. Near = 1 << 1, //进场交互
  45. }
  46. [Flags]
  47. public enum ActiveWatchType
  48. {
  49. DisableWatch = 1 << 0,
  50. EnableWatch = 1 << 1,
  51. }
  52. [Flags]
  53. public enum ActiveHeadHandType
  54. {
  55. NormalHand = 1 << 0,
  56. HeadHand = 1 << 1,
  57. }
  58. /// <summary>
  59. /// Input Module status
  60. /// </summary>
  61. [Serializable]
  62. public class ActiveModuleStatus
  63. {
  64. public InputModuleType moduleType;
  65. public ActiveHandStatus leftHandStatus;
  66. public ActiveHandStatus rightHandStatus;
  67. public ActiveHeadHandType headHandType;
  68. public override string ToString()
  69. {
  70. return $"ActiveInputModuleType: {moduleType} \r\n\r\nLeftHandStatus: {leftHandStatus.ToString()} \r\n\r\nRightHandStatus: {rightHandStatus.ToString()}";
  71. }
  72. }
  73. [Serializable]
  74. public class ActiveHandStatus
  75. {
  76. public bool active;
  77. public ActiveHandInteractorType handInteractorType;
  78. public ActiveHandOrientationType handOrientationType;
  79. public ActiveWatchType activeWatchType;
  80. public bool handDragging;
  81. public override string ToString()
  82. {
  83. return $" \r\n Active:{active} \r\n HandDragging:{handDragging}\r\n HandInteractorType:{handInteractorType.ToString()} \r\n HandOrientationType:{handOrientationType.ToString()} \r\n ActiveWatchType:{activeWatchType.ToString()}";
  84. }
  85. }
  86. /// <summary>
  87. /// This script implements the IInputModuleActive interface, which allows it to register its own activation status information to the InputModuleManager for centralized management and switching.
  88. /// </summary>
  89. public class InputModuleManager : MonoSingleton<InputModuleManager>
  90. {
  91. /// <summary>
  92. /// The default init module
  93. /// </summary>
  94. [SerializeField, Tooltip("默认初始化的模块")]
  95. private ActiveModuleType defaultInitModule;
  96. /// <summary>
  97. /// The default active module.
  98. /// </summary>
  99. [SerializeField, Tooltip("默认激活的模块")]
  100. private InputModuleType defaultActiveModule;
  101. /// <summary>
  102. /// Whether to play a module switch sound.
  103. /// </summary>
  104. [HideInInspector, SerializeField, Tooltip("是否播放模块切换提示音")]
  105. private bool muteModuleActiveSound = false;
  106. /// <summary>
  107. /// Optional TextUI for debugging purposes.
  108. /// </summary>
  109. [Optional, SerializeField, Tooltip("调试Text")]
  110. private Text logText;
  111. [SerializeField, HideInInspector, Tooltip("模块的激活状态")]
  112. private ActiveModuleStatus activeModuleStatus = new ActiveModuleStatus();
  113. private bool stateChanged;
  114. private List<IInputModuleActive> moduleActives = new List<IInputModuleActive>();
  115. public static event Action<IInputModuleActive, bool> OnObjectActive;
  116. public static event Action<InputModuleType> OnModuleActive;
  117. public bool GetMouseActive()
  118. {
  119. return activeModuleStatus.moduleType == InputModuleType.Mouse;
  120. }
  121. public bool GetGesActive()
  122. {
  123. return activeModuleStatus.moduleType == InputModuleType.Gesture;
  124. }
  125. public bool GetThreeDofActive()
  126. {
  127. return activeModuleStatus.moduleType == InputModuleType.ThreeDof;
  128. }
  129. public bool GetButtonMouseActive()
  130. {
  131. return activeModuleStatus.moduleType == InputModuleType.ButtonMouse;
  132. }
  133. public bool GetTouchPadActive()
  134. {
  135. return activeModuleStatus.moduleType == InputModuleType.TouchPad;
  136. }
  137. public bool GetWatchModuleActive(HandType hand)
  138. {
  139. if (activeModuleStatus.moduleType == InputModuleType.Gesture)
  140. {
  141. if (hand == HandType.LeftHand)
  142. {
  143. return activeModuleStatus.leftHandStatus.activeWatchType == ActiveWatchType.EnableWatch;
  144. }
  145. if (hand == HandType.RightHand)
  146. {
  147. return activeModuleStatus.rightHandStatus.activeWatchType == ActiveWatchType.EnableWatch;
  148. }
  149. }
  150. return false;
  151. }
  152. /// <summary>
  153. /// 获取当前激活的模块
  154. /// Gets the currently active module
  155. /// </summary>
  156. /// <returns></returns>
  157. public ActiveModuleStatus GetActiveModule()
  158. {
  159. return activeModuleStatus;
  160. }
  161. public void SetDefaultActiveModule(InputModuleType moduleType)
  162. {
  163. defaultActiveModule = moduleType;
  164. }
  165. public void Initialize()
  166. {
  167. RKLog.KeyInfo($"====InputModuleManager====: defaultInitModule : {defaultInitModule}, defaultActiveModule:{defaultActiveModule},transform:{transform.name}");
  168. if (HasInputModuleType(defaultInitModule, ActiveModuleType.ThreeDof))
  169. {
  170. ThreeDofEventInput.Instance.Initialize(transform);
  171. }
  172. if (HasInputModuleType(defaultInitModule, ActiveModuleType.Mouse))
  173. {
  174. MouseEventInput.Instance.Initialize(transform);
  175. }
  176. if (HasInputModuleType(defaultInitModule, ActiveModuleType.ButtonMouse))
  177. {
  178. ButtonMouseEventInput.Instance.Initialize(transform);
  179. }
  180. if (HasInputModuleType(defaultInitModule, ActiveModuleType.Gesture))
  181. {
  182. if (Utils.IsAndroidPlatfrom())
  183. {
  184. if (Utils.IsAndroidPlatfrom() && FuncDeviceCheck.CheckHandTrackingFunc())
  185. {
  186. GesEventInput.Instance.Initialize(transform);
  187. }
  188. else
  189. {
  190. ThreeDofEventInput.Instance.Initialize(transform);
  191. }
  192. }
  193. else
  194. {
  195. GesEventInput.Instance.Initialize(transform);
  196. }
  197. }
  198. if (HasInputModuleType(defaultInitModule, ActiveModuleType.TouchPad))
  199. {
  200. TouchPadEventInput.Instance.Initialize(transform);
  201. }
  202. switch (defaultActiveModule)
  203. {
  204. case InputModuleType.ThreeDof:
  205. ThreeDofEventInput.Instance.ActiveModule();
  206. break;
  207. case InputModuleType.Gesture:
  208. if (Utils.IsAndroidPlatfrom())
  209. {
  210. if (FuncDeviceCheck.CheckHandTrackingFunc())
  211. {
  212. GesEventInput.Instance.ActiveModule();
  213. }
  214. else
  215. {
  216. ThreeDofEventInput.Instance.ActiveModule();
  217. }
  218. }
  219. else
  220. {
  221. GesEventInput.Instance.ActiveModule();
  222. }
  223. break;
  224. case InputModuleType.Mouse:
  225. MouseEventInput.Instance.ActiveModule();
  226. break;
  227. case InputModuleType.ButtonMouse:
  228. ButtonMouseEventInput.Instance.ActiveModule();
  229. break;
  230. case InputModuleType.TouchPad:
  231. TouchPadEventInput.Instance.ActiveModule();
  232. break;
  233. }
  234. if (EventSystem.current == null)
  235. {
  236. GameObject go = GameObject.Instantiate(Resources.Load<GameObject>("Prefabs/Events/RKEventSystem"));
  237. go.name = "RKEventSystem";
  238. go.transform.SetParent(transform);
  239. }
  240. InitModuleChangeAudio();
  241. }
  242. private void Start()
  243. {
  244. InteractorStateChange.OnInteractorTypeChange += OnInteractorTypeChange;
  245. InteractorStateChange.OnHandDragStatusChanged += OnGestureDragStatusChanged;
  246. RKHandWatch.OnActiveWatch += OnActiveWatch;
  247. GesEventInput.OnHandOrHeadHandTypeChange += OnHandOrHeadHandTypeChange;
  248. MouseEventInput.OnActiveMouseModule += OnActiveMouseModule;
  249. ThreeDofEventInput.OnActiveThreeDofModule += OnActiveThreeDofModule;
  250. GesEventInput.OnActiveGesModule += OnActiveGesModule;
  251. ButtonMouseEventInput.OnActiveButtonMouseModule += OnActiveButtonMouseModule;
  252. TouchPadEventInput.OnActiveTouchPadModule += OnActiveTouchPadModule;
  253. MouseEventInput.OnReleaseMouseModule += OnReleaseMouseModule;
  254. ThreeDofEventInput.OnReleaseThreeDofModule += OnReleaseThreeDofModule;
  255. GesEventInput.OnReleaseGesModule += OnReleaseGesModule;
  256. ButtonMouseEventInput.OnReleaseButtonMouseModule += OnReleaseButtonMouseModule;
  257. TouchPadEventInput.OnReleaseTouchPadModule += OnReleaseTouchPadModule;
  258. GesEventInput.OnTrackedSuccess += OnTrackedSuccess;
  259. GesEventInput.OnTrackedFailed += OnTrackedFailed;
  260. GesEventInput.OnHandOrientationUpdate += OnHandOrientationUpdate;
  261. Initialize();
  262. }
  263. private void OnGestureDragStatusChanged(HandType hand, bool dragging)
  264. {
  265. if (hand == HandType.LeftHand)
  266. {
  267. if (activeModuleStatus.leftHandStatus.handDragging != dragging)
  268. {
  269. activeModuleStatus.leftHandStatus.handDragging = dragging;
  270. stateChanged = true;
  271. }
  272. }
  273. if (hand == HandType.RightHand)
  274. {
  275. if (activeModuleStatus.rightHandStatus.handDragging != dragging)
  276. {
  277. activeModuleStatus.rightHandStatus.handDragging = dragging;
  278. stateChanged = true;
  279. }
  280. }
  281. }
  282. private void OnActiveWatch(HandType hand, bool active)
  283. {
  284. if (hand == HandType.LeftHand)
  285. {
  286. activeModuleStatus.leftHandStatus.activeWatchType = active ? ActiveWatchType.EnableWatch : ActiveWatchType.DisableWatch;
  287. stateChanged = true;
  288. }
  289. if (hand == HandType.RightHand)
  290. {
  291. activeModuleStatus.rightHandStatus.activeWatchType = active ? ActiveWatchType.EnableWatch : ActiveWatchType.DisableWatch;
  292. stateChanged = true;
  293. }
  294. }
  295. private void OnHandOrientationUpdate(HandType hand, HandOrientation handOrientation)
  296. {
  297. if (hand == HandType.LeftHand)
  298. {
  299. if (activeModuleStatus.leftHandStatus.handOrientationType != ConvertType(handOrientation) && activeModuleStatus.leftHandStatus.handDragging == false)
  300. {
  301. activeModuleStatus.leftHandStatus.handOrientationType = ConvertType(handOrientation);
  302. stateChanged = true;
  303. }
  304. }
  305. if (hand == HandType.RightHand)
  306. {
  307. if (activeModuleStatus.rightHandStatus.handOrientationType != ConvertType(handOrientation) && activeModuleStatus.rightHandStatus.handDragging == false)
  308. {
  309. activeModuleStatus.rightHandStatus.handOrientationType = ConvertType(handOrientation);
  310. stateChanged = true;
  311. }
  312. }
  313. }
  314. private void OnTrackedFailed(HandType hand)
  315. {
  316. if (hand == HandType.LeftHand || hand == HandType.None)
  317. {
  318. if (activeModuleStatus.leftHandStatus.active == true)
  319. {
  320. activeModuleStatus.leftHandStatus.active = false;
  321. stateChanged = true;
  322. }
  323. }
  324. if (hand == HandType.RightHand || hand == HandType.None)
  325. {
  326. if (activeModuleStatus.rightHandStatus.active == true)
  327. {
  328. activeModuleStatus.rightHandStatus.active = false;
  329. stateChanged = true;
  330. }
  331. }
  332. }
  333. protected override void OnDestroy()
  334. {
  335. InteractorStateChange.OnInteractorTypeChange -= OnInteractorTypeChange;
  336. InteractorStateChange.OnHandDragStatusChanged -= OnGestureDragStatusChanged;
  337. RKHandWatch.OnActiveWatch -= OnActiveWatch;
  338. GesEventInput.OnHandOrHeadHandTypeChange -= OnHandOrHeadHandTypeChange;
  339. MouseEventInput.OnActiveMouseModule -= OnActiveMouseModule;
  340. ThreeDofEventInput.OnActiveThreeDofModule -= OnActiveThreeDofModule;
  341. GesEventInput.OnActiveGesModule -= OnActiveGesModule;
  342. ButtonMouseEventInput.OnActiveButtonMouseModule -= OnActiveButtonMouseModule;
  343. TouchPadEventInput.OnActiveTouchPadModule -= OnActiveTouchPadModule;
  344. MouseEventInput.OnReleaseMouseModule -= OnReleaseMouseModule;
  345. ThreeDofEventInput.OnReleaseThreeDofModule -= OnReleaseThreeDofModule;
  346. GesEventInput.OnReleaseGesModule -= OnReleaseGesModule;
  347. ButtonMouseEventInput.OnReleaseButtonMouseModule -= OnReleaseButtonMouseModule;
  348. TouchPadEventInput.OnReleaseTouchPadModule -= OnReleaseTouchPadModule;
  349. GesEventInput.OnTrackedSuccess -= OnTrackedSuccess;
  350. GesEventInput.OnTrackedFailed -= OnTrackedFailed;
  351. GesEventInput.OnHandOrientationUpdate -= OnHandOrientationUpdate;
  352. }
  353. private void OnInteractorTypeChange(HandType hand, InteractorType interactorType)
  354. {
  355. if (hand == HandType.LeftHand)
  356. {
  357. activeModuleStatus.leftHandStatus.handInteractorType = interactorType == InteractorType.Near ? ActiveHandInteractorType.Near : ActiveHandInteractorType.Far;
  358. stateChanged = true;
  359. }
  360. if (hand == HandType.RightHand)
  361. {
  362. activeModuleStatus.rightHandStatus.handInteractorType = interactorType == InteractorType.Near ? ActiveHandInteractorType.Near : ActiveHandInteractorType.Far;
  363. stateChanged = true;
  364. }
  365. }
  366. private void OnHandOrHeadHandTypeChange(HandOrHeadHandType handOrHeadHandType)
  367. {
  368. if (handOrHeadHandType == HandOrHeadHandType.NormalHand)
  369. {
  370. activeModuleStatus.headHandType = ActiveHeadHandType.NormalHand;
  371. stateChanged = true;
  372. }
  373. else
  374. {
  375. activeModuleStatus.headHandType = ActiveHeadHandType.HeadHand;
  376. stateChanged = true;
  377. }
  378. }
  379. private void OnActiveMouseModule()
  380. {
  381. if (!GetMouseActive())
  382. {
  383. activeModuleStatus.moduleType = InputModuleType.Mouse;
  384. stateChanged = true;
  385. PlayModuleChangeAudio(activeModuleStatus.moduleType);
  386. OnModuleActive?.Invoke(InputModuleType.Mouse);
  387. }
  388. }
  389. private void OnActiveThreeDofModule()
  390. {
  391. if (!GetThreeDofActive())
  392. {
  393. activeModuleStatus.moduleType = InputModuleType.ThreeDof;
  394. stateChanged = true;
  395. PlayModuleChangeAudio(activeModuleStatus.moduleType);
  396. OnModuleActive?.Invoke(InputModuleType.ThreeDof);
  397. }
  398. }
  399. private void OnActiveGesModule()
  400. {
  401. if (!GetGesActive())
  402. {
  403. activeModuleStatus.moduleType = InputModuleType.Gesture;
  404. activeModuleStatus.leftHandStatus.handInteractorType = ConvertType(GesEventInput.Instance.GetInteractorType(HandType.LeftHand));
  405. activeModuleStatus.leftHandStatus.handOrientationType = ConvertType(GesEventInput.Instance.GetHandOrientation(HandType.LeftHand));
  406. activeModuleStatus.rightHandStatus.handInteractorType = ConvertType(GesEventInput.Instance.GetInteractorType(HandType.RightHand));
  407. activeModuleStatus.rightHandStatus.handOrientationType = ConvertType(GesEventInput.Instance.GetHandOrientation(HandType.RightHand));
  408. stateChanged = true;
  409. PlayModuleChangeAudio(activeModuleStatus.moduleType);
  410. OnModuleActive?.Invoke(InputModuleType.Gesture);
  411. }
  412. }
  413. private void OnActiveButtonMouseModule()
  414. {
  415. if (!GetButtonMouseActive())
  416. {
  417. activeModuleStatus.moduleType = InputModuleType.ButtonMouse;
  418. stateChanged = true;
  419. PlayModuleChangeAudio(activeModuleStatus.moduleType);
  420. OnModuleActive?.Invoke(InputModuleType.ButtonMouse);
  421. }
  422. }
  423. private void OnActiveTouchPadModule()
  424. {
  425. if (!GetTouchPadActive())
  426. {
  427. activeModuleStatus.moduleType = InputModuleType.TouchPad;
  428. stateChanged = true;
  429. PlayModuleChangeAudio(activeModuleStatus.moduleType);
  430. OnModuleActive?.Invoke(InputModuleType.TouchPad);
  431. }
  432. }
  433. private void OnReleaseGesModule()
  434. {
  435. if (GetGesActive())
  436. {
  437. activeModuleStatus.moduleType = InputModuleType.None;
  438. stateChanged = true;
  439. }
  440. }
  441. private void OnReleaseThreeDofModule()
  442. {
  443. if (GetThreeDofActive())
  444. {
  445. activeModuleStatus.moduleType = InputModuleType.None;
  446. stateChanged = true;
  447. }
  448. }
  449. private void OnReleaseMouseModule()
  450. {
  451. if (GetMouseActive())
  452. {
  453. activeModuleStatus.moduleType = InputModuleType.None;
  454. stateChanged = true;
  455. }
  456. }
  457. private void OnReleaseButtonMouseModule()
  458. {
  459. if (GetButtonMouseActive())
  460. {
  461. activeModuleStatus.moduleType = InputModuleType.None;
  462. stateChanged = true;
  463. }
  464. }
  465. private void OnReleaseTouchPadModule()
  466. {
  467. if (GetTouchPadActive())
  468. {
  469. activeModuleStatus.moduleType = InputModuleType.None;
  470. stateChanged = true;
  471. }
  472. }
  473. private void OnTrackedSuccess(HandType hand)
  474. {
  475. if (hand == HandType.LeftHand)
  476. {
  477. if (activeModuleStatus.leftHandStatus.active == false)
  478. {
  479. activeModuleStatus.leftHandStatus.active = true;
  480. stateChanged = true;
  481. }
  482. }
  483. if (hand == HandType.RightHand)
  484. {
  485. if (activeModuleStatus.rightHandStatus.active == false)
  486. {
  487. activeModuleStatus.rightHandStatus.active = true;
  488. stateChanged = true;
  489. }
  490. }
  491. }
  492. public void RegisterActive(IInputModuleActive moudleActive)
  493. {
  494. this.moduleActives.Add(moudleActive);
  495. stateChanged = true;
  496. RKLog.KeyInfo($"====ModuleSwitchManager====: RegisterActive {moudleActive.Go.name},{this.moduleActives.Count}");
  497. }
  498. public void UnRegisterActive(IInputModuleActive moudleActive)
  499. {
  500. this.moduleActives.Remove(moudleActive);
  501. RKLog.KeyInfo($"====ModuleSwitchManager====: UnRegisterActive {moudleActive.Go.name},{this.moduleActives.Count}");
  502. }
  503. private void SetActiveEnable(IInputModuleActive active, bool enabled)
  504. {
  505. if (active.Behaviour != null)
  506. {
  507. active.Behaviour.enabled = enabled;
  508. }
  509. else
  510. {
  511. active.Go.SetActive(enabled);
  512. OnObjectActive?.Invoke(active, enabled);
  513. }
  514. }
  515. private void Update()
  516. {
  517. if (stateChanged)
  518. {
  519. RKLog.KeyInfo($"====InputModuleManager==== Current Active Status: {activeModuleStatus}");
  520. stateChanged = false;
  521. for (int i = 0; i < moduleActives.Count; i++)
  522. {
  523. IInputModuleActive active = moduleActives[i];
  524. bool enabled = false;
  525. switch (activeModuleStatus.moduleType)
  526. {
  527. case InputModuleType.Mouse:
  528. if (HasInputModuleType(active.ActiveModuleType, ActiveModuleType.Mouse))
  529. enabled = HasInputModuleType(active.ActiveModuleType, ActiveModuleType.Mouse);
  530. break;
  531. case InputModuleType.ThreeDof:
  532. if (HasInputModuleType(active.ActiveModuleType, ActiveModuleType.ThreeDof))
  533. enabled = HasInputModuleType(active.ActiveModuleType, ActiveModuleType.ThreeDof);
  534. break;
  535. case InputModuleType.Gesture:
  536. if (HasInputModuleType(active.ActiveModuleType, ActiveModuleType.Gesture))
  537. {
  538. if (JudgeHandLost(active.DisableOnHandLost, activeModuleStatus.leftHandStatus.active) && HasHandType(active.ActiveHandType, ActiveHandType.LeftHand) && HasHandInteractorType(active.ActiveHandInteractorType, activeModuleStatus.leftHandStatus.handInteractorType) && HasHandOrientationType(active.ActiveHandOrientationType, activeModuleStatus.leftHandStatus.handOrientationType) &&
  539. HasWatchType(active.ActiveWatchType, activeModuleStatus.leftHandStatus.activeWatchType) && HasHeadHandType(active.ActiveHeadHandType, activeModuleStatus.headHandType))
  540. {
  541. enabled = true;
  542. }
  543. if (JudgeHandLost(active.DisableOnHandLost, activeModuleStatus.rightHandStatus.active) && HasHandType(active.ActiveHandType, ActiveHandType.RightHand) && HasHandInteractorType(active.ActiveHandInteractorType, activeModuleStatus.rightHandStatus.handInteractorType) && HasHandOrientationType(active.ActiveHandOrientationType, activeModuleStatus.rightHandStatus.handOrientationType) &&
  544. HasWatchType(active.ActiveWatchType, activeModuleStatus.rightHandStatus.activeWatchType) && HasHeadHandType(active.ActiveHeadHandType, activeModuleStatus.headHandType))
  545. {
  546. enabled = true;
  547. }
  548. }
  549. break;
  550. case InputModuleType.ButtonMouse:
  551. if (HasInputModuleType(active.ActiveModuleType, ActiveModuleType.ButtonMouse))
  552. enabled = HasInputModuleType(active.ActiveModuleType, ActiveModuleType.ButtonMouse);
  553. break;
  554. case InputModuleType.TouchPad:
  555. if (HasInputModuleType(active.ActiveModuleType, ActiveModuleType.TouchPad))
  556. enabled = HasInputModuleType(active.ActiveModuleType, ActiveModuleType.TouchPad);
  557. break;
  558. default:
  559. enabled = false;
  560. break;
  561. }
  562. SetActiveEnable(active, enabled);
  563. }
  564. }
  565. if (logText != null)
  566. {
  567. logText.text = activeModuleStatus.ToString() + $"\r\n\r\nDragThreshold: {EventSystem.current.pixelDragThreshold}";
  568. }
  569. }
  570. #region Judge Has Type
  571. private bool HasInputModuleType(ActiveModuleType inType, ActiveModuleType targetType)
  572. {
  573. return (inType & targetType) == targetType;
  574. }
  575. private bool HasHandType(ActiveHandType inType, ActiveHandType targetType)
  576. {
  577. return (inType & targetType) == targetType;
  578. }
  579. private bool HasHandOrientationType(ActiveHandOrientationType inType, ActiveHandOrientationType targetType)
  580. {
  581. return (inType & targetType) == targetType;
  582. }
  583. private bool HasHandInteractorType(ActiveHandInteractorType inType, ActiveHandInteractorType targetType)
  584. {
  585. return (inType & targetType) == targetType;
  586. }
  587. private bool HasWatchType(ActiveWatchType inType, ActiveWatchType targetType)
  588. {
  589. return (inType & targetType) == targetType;
  590. }
  591. private bool HasHeadHandType(ActiveHeadHandType inType, ActiveHeadHandType targetType)
  592. {
  593. return (inType & targetType) == targetType;
  594. }
  595. private bool JudgeHandLost(bool disableOnHandLost, bool handLost)
  596. {
  597. if (disableOnHandLost == false)
  598. {
  599. return true;
  600. }
  601. else
  602. {
  603. return handLost;
  604. }
  605. }
  606. #endregion
  607. #region Convert
  608. private ActiveHandInteractorType ConvertType(InteractorType interactorType)
  609. {
  610. switch (interactorType)
  611. {
  612. case InteractorType.Far:
  613. return ActiveHandInteractorType.Far;
  614. case InteractorType.Near:
  615. return ActiveHandInteractorType.Near;
  616. }
  617. return default(ActiveHandInteractorType);
  618. }
  619. private ActiveHandOrientationType ConvertType(HandOrientation handOrientation)
  620. {
  621. switch (handOrientation)
  622. {
  623. case HandOrientation.Back:
  624. return ActiveHandOrientationType.Back;
  625. case HandOrientation.Palm:
  626. return ActiveHandOrientationType.Palm;
  627. }
  628. return default(ActiveHandOrientationType);
  629. }
  630. #endregion
  631. #region PlayAudio
  632. private AudioSource _audioSource;
  633. public void InitModuleChangeAudio()
  634. {
  635. if (!muteModuleActiveSound)
  636. {
  637. AudioClip audioClip = (AudioClip)Resources.Load("Audio/ModuleChangeAudio");
  638. _audioSource = gameObject.AddComponent<AudioSource>();
  639. _audioSource.clip = audioClip;
  640. _audioSource.playOnAwake = false;
  641. }
  642. }
  643. public void PlayModuleChangeAudio(InputModuleType type)
  644. {
  645. if (!muteModuleActiveSound)
  646. {
  647. _audioSource?.Play();
  648. }
  649. }
  650. #endregion
  651. }
  652. }