InputDevicePartBase.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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(inputDevicePartUIBase);
  82. AddModule(detectorBase);
  83. //Must after detectorBase ,detectorBase will fill part.scpointerdata,inputDevicePartDispatchEventBase will use it
  84. AddModule(inputDevicePartDispatchEventBase);
  85. }
  86. protected abstract void ModuleCreater();
  87. public override void OnSCStart() {
  88. base.OnSCStart();
  89. if(inputDataBase != null)
  90. inputDataBase.ModuleStart();
  91. if(inputDataGetBase != null)
  92. inputDataGetBase.ModuleStart();
  93. if(inputDevicePartStatusBase != null)
  94. inputDevicePartStatusBase.ModuleStart();
  95. //if(inputDevicePartDispatchEventBase != null)
  96. // inputDevicePartDispatchEventBase.ModuleStart();
  97. //if(inputDevicePartUIBase != null)
  98. // inputDevicePartUIBase.ModuleStart();
  99. //if(pointerBase != null)
  100. // pointerBase.ModuleStart();
  101. }
  102. public override void OnSCLateUpdate() {
  103. base.OnSCLateUpdate();
  104. if(inputDataBase.isVaild == false) {
  105. if(inputDevicePartUIBase != null && inputDevicePartUIBase.IsModuleStarted)
  106. inputDevicePartUIBase.ModuleStop();
  107. if(detectorBase != null && detectorBase.IsModuleStarted)
  108. detectorBase.ModuleStop();
  109. if(inputDevicePartDispatchEventBase != null && inputDevicePartDispatchEventBase.IsModuleStarted)
  110. inputDevicePartDispatchEventBase.ModuleStop();
  111. } else {
  112. if(inputDevicePartUIBase != null && !inputDevicePartUIBase.IsModuleStarted)
  113. inputDevicePartUIBase.ModuleStart();
  114. if(detectorBase != null && !detectorBase.IsModuleStarted)
  115. detectorBase.ModuleStart();
  116. if(inputDevicePartDispatchEventBase != null && !inputDevicePartDispatchEventBase.IsModuleStarted)
  117. inputDevicePartDispatchEventBase.ModuleStart();
  118. }
  119. }
  120. public override void OnSCDestroy() {
  121. base.OnSCDestroy();
  122. inputDataBase = null;
  123. inputDataGetBase = null;
  124. inputDevicePartStatusBase = null;
  125. inputDevicePartDispatchEventBase = null;
  126. inputDevicePartUIBase = null;
  127. detectorBase = null;
  128. }
  129. }
  130. }