InputDeviceBase.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 InputDeviceBase : SCModuleMono {
  9. /// <summary>
  10. /// 拖拽赋值
  11. /// </summary>
  12. public List<InputDevicePartBase> _inputDevicePartList;
  13. public List<InputDevicePartBase> inputDevicePartList {
  14. get {
  15. if(_inputDevicePartList == null || _inputDevicePartList.Count == 0) {
  16. _inputDevicePartList = GetComponentsInChildren<InputDevicePartBase>(true).ToList();
  17. }
  18. return _inputDevicePartList;
  19. }
  20. private set {
  21. _inputDevicePartList = value;
  22. }
  23. }
  24. /// <summary>
  25. /// 拖拽赋值
  26. /// </summary>
  27. public InputDeviceUIBase _inputDeviceUI;
  28. public InputDeviceUIBase inputDeviceUI {
  29. get {
  30. if (_inputDeviceUI == null) {
  31. _inputDeviceUI = GetComponentInChildren<InputDeviceUIBase>(true);
  32. }
  33. return _inputDeviceUI;
  34. }
  35. private set {
  36. _inputDeviceUI = value;
  37. }
  38. }
  39. /// <summary>
  40. /// 输入设备类型
  41. /// </summary>
  42. public abstract InputDeviceType inputDeviceType { get; }
  43. public override void OnSCAwake() {
  44. base.OnSCAwake();
  45. foreach(var item in inputDevicePartList) {
  46. AddModule(item);
  47. }
  48. AddModule(inputDeviceUI);
  49. }
  50. public override void OnSCStart() {
  51. base.OnSCStart();
  52. InputDeviceStart();
  53. inputDeviceUI?.ModuleStart();
  54. }
  55. protected virtual void InputDeviceStart() {
  56. foreach(var item in inputDevicePartList) {
  57. item.ModuleStart();
  58. }
  59. }
  60. public override void OnSCDisable() {
  61. base.OnSCDisable();
  62. }
  63. public override void OnSCDestroy() {
  64. base.OnSCDestroy();
  65. inputDevicePartList = null;
  66. inputDeviceUI = null;
  67. }
  68. public void SetActiveInputDevicePart(InputDevicePartType partType, bool active) {
  69. if(active) {
  70. foreach(var devicePart in inputDevicePartList) {
  71. if(devicePart.PartType == partType) {
  72. if(false == devicePart.IsModuleStarted) {
  73. devicePart.ModuleStart();
  74. }
  75. break;
  76. }
  77. }
  78. } else {
  79. foreach(var devicePart in inputDevicePartList) {
  80. if(devicePart.PartType == partType) {
  81. if(devicePart.IsModuleStarted) {
  82. devicePart.ModuleStop();
  83. }
  84. break;
  85. }
  86. }
  87. }
  88. }
  89. public virtual bool IsAnyPartVaild {
  90. get {
  91. foreach(var part in inputDevicePartList) {
  92. if(part.inputDataBase.isVaild) {
  93. return true;
  94. }
  95. }
  96. return false;
  97. }
  98. }
  99. }
  100. }