InputDevicePartBase.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using UnityEngine;
  7. namespace SC.XR.Unity.Module_InputSystem {
  8. public abstract class InputDevicePartBase : SCModuleMono {
  9. /// <summary>
  10. /// 自行赋值
  11. /// </summary>
  12. [Header("Select Right Type")]
  13. public InputDevicePartType PartType;
  14. /// <summary>
  15. /// 输入设备Part所属Device模块
  16. /// </summary>;
  17. InputDeviceBase _inputDeviceBase;
  18. public InputDeviceBase inputDeviceBase {
  19. get {
  20. if(_inputDeviceBase == null) {
  21. _inputDeviceBase = GetComponentInParent<InputDeviceBase>();
  22. }
  23. return _inputDeviceBase;
  24. }
  25. private set {
  26. _inputDeviceBase = value;
  27. }
  28. }
  29. /// <summary>
  30. /// 输入设备PartUI模块
  31. /// </summary>;
  32. InputDevicePartUIBase _inputDevicePartUIBase;
  33. public InputDevicePartUIBase inputDevicePartUIBase {
  34. get {
  35. if(_inputDevicePartUIBase == null) {
  36. _inputDevicePartUIBase = GetComponentInChildren<InputDevicePartUIBase>(true);
  37. }
  38. return _inputDevicePartUIBase;
  39. }
  40. private set {
  41. _inputDevicePartUIBase = value;
  42. }
  43. }
  44. /// <summary>
  45. /// 目标检测及Cursor显示模块
  46. /// </summary>
  47. DetectorBase mDetectorBase;
  48. public DetectorBase detectorBase {
  49. get {
  50. if(mDetectorBase == null) {
  51. mDetectorBase = GetComponentInChildren<DetectorBase>(true);
  52. }
  53. return mDetectorBase;
  54. }
  55. private set {
  56. mDetectorBase = value;
  57. }
  58. }
  59. /// <summary>
  60. /// 数据获取模块
  61. /// </summary>
  62. public InputDataBase inputDataBase { get; set; }
  63. /// <summary>
  64. /// 数据获取模块
  65. /// </summary>
  66. public InputDataGetBase inputDataGetBase { get; set; }
  67. /// <summary>
  68. /// 设备状态judge模块
  69. /// </summary>
  70. public InputDevicePartStatusBase inputDevicePartStatusBase { get; set; }
  71. /// <summary>
  72. /// 设备Dispatch Event模块
  73. /// </summary>
  74. public InputDevicePartDispatchEventBase inputDevicePartDispatchEventBase { get; set; }
  75. public override void OnSCAwake() {
  76. base.OnSCAwake();
  77. ModuleCreater();
  78. AddModule(inputDataBase);
  79. AddModule(inputDataGetBase);
  80. AddModule(inputDevicePartStatusBase);
  81. AddModule(inputDevicePartDispatchEventBase);
  82. AddModule(inputDevicePartUIBase);
  83. AddModule(detectorBase);
  84. }
  85. protected abstract void ModuleCreater();
  86. public override void OnSCStart() {
  87. base.OnSCStart();
  88. if(inputDataBase != null)
  89. inputDataBase.ModuleStart();
  90. if(inputDataGetBase != null)
  91. inputDataGetBase.ModuleStart();
  92. if(inputDevicePartStatusBase != null)
  93. inputDevicePartStatusBase.ModuleStart();
  94. //if(inputDevicePartDispatchEventBase != null)
  95. // inputDevicePartDispatchEventBase.ModuleStart();
  96. //if(inputDevicePartUIBase != null)
  97. // inputDevicePartUIBase.ModuleStart();
  98. //if(pointerBase != null)
  99. // pointerBase.ModuleStart();
  100. }
  101. public override void OnSCLateUpdate() {
  102. base.OnSCLateUpdate();
  103. if(inputDataBase.isVaild == false) {
  104. if(inputDevicePartUIBase != null && inputDevicePartUIBase.IsModuleStarted)
  105. inputDevicePartUIBase.ModuleStop();
  106. if(detectorBase != null && detectorBase.IsModuleStarted)
  107. detectorBase.ModuleStop();
  108. if(inputDevicePartDispatchEventBase != null && inputDevicePartDispatchEventBase.IsModuleStarted)
  109. inputDevicePartDispatchEventBase.ModuleStop();
  110. } else {
  111. if(inputDevicePartUIBase != null && !inputDevicePartUIBase.IsModuleStarted)
  112. inputDevicePartUIBase.ModuleStart();
  113. if(detectorBase != null && !detectorBase.IsModuleStarted)
  114. detectorBase.ModuleStart();
  115. if(inputDevicePartDispatchEventBase != null && !inputDevicePartDispatchEventBase.IsModuleStarted)
  116. inputDevicePartDispatchEventBase.ModuleStart();
  117. }
  118. }
  119. public override void OnSCDestroy() {
  120. base.OnSCDestroy();
  121. inputDataBase = null;
  122. inputDataGetBase = null;
  123. inputDevicePartStatusBase = null;
  124. inputDevicePartDispatchEventBase = null;
  125. inputDevicePartUIBase = null;
  126. detectorBase = null;
  127. }
  128. }
  129. }