HandDetector.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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.InputDeviceHand {
  8. public class HandDetector : DetectorBase {
  9. private IPointer handPointer;
  10. public InputDeviceHandPart inputDeviceHandPart {
  11. get {
  12. return inputDevicePartBase as InputDeviceHandPart;
  13. }
  14. }
  15. public FarPointer farPointer {
  16. get {
  17. return Transition<FarPointer>(pointerBase);
  18. }
  19. }
  20. [SerializeField]
  21. TouchPointer mTouchPointer;
  22. public TouchPointer touchPointer {
  23. get {
  24. if(mTouchPointer == null) {
  25. mTouchPointer = GetComponentInChildren<TouchPointer>(true);
  26. }
  27. return mTouchPointer;
  28. }
  29. set {
  30. mTouchPointer = value;
  31. }
  32. }
  33. [SerializeField]
  34. GrabPointer mGrabPointer;
  35. public GrabPointer grabPointer {
  36. get {
  37. if(mGrabPointer == null) {
  38. mGrabPointer = GetComponentInChildren<GrabPointer>(true);
  39. }
  40. return mGrabPointer;
  41. }
  42. set {
  43. mGrabPointer = value;
  44. }
  45. }
  46. public override void OnSCAwake() {
  47. base.OnSCAwake();
  48. AddModule(touchPointer);
  49. AddModule(grabPointer);
  50. }
  51. public override void OnSCStart() {
  52. //base.OnSCStart();
  53. //touchPointer?.ModuleStart();
  54. //grabPointer?.ModuleStart();
  55. }
  56. public override void OnSCLateUpdate() {
  57. base.OnSCLateUpdate();
  58. if(touchPointer.IsFocusLocked || grabPointer.IsFocusLocked || farPointer.IsFocusLocked) {
  59. } else {
  60. if(touchPointer.FindClosestTouchableForLayerMask()) {
  61. if(touchPointer.IsModuleStarted == false) {
  62. touchPointer.ModuleStart();
  63. handPointer = touchPointer;
  64. }
  65. if(grabPointer.IsModuleStarted) {
  66. grabPointer.ModuleStop();
  67. }
  68. if(farPointer.IsModuleStarted) {
  69. farPointer.ModuleStop();
  70. }
  71. } else if(grabPointer.FindClosestGrabbableForLayerMask()) {
  72. if(touchPointer.IsModuleStarted ) {
  73. touchPointer.ModuleStop();
  74. }
  75. if(grabPointer.IsModuleStarted == false) {
  76. grabPointer.ModuleStart();
  77. handPointer = grabPointer;
  78. }
  79. if(farPointer.IsModuleStarted) {
  80. farPointer.ModuleStop();
  81. }
  82. } else {
  83. if(touchPointer.IsModuleStarted) {
  84. touchPointer.ModuleStop();
  85. }
  86. if(grabPointer.IsModuleStarted ) {
  87. grabPointer.ModuleStop();
  88. }
  89. if(farPointer.IsModuleStarted == false) {
  90. farPointer.ModuleStart();
  91. handPointer = farPointer;
  92. }
  93. }
  94. }
  95. currentPointer = handPointer;
  96. }
  97. public override void OnSCDestroy() {
  98. base.OnSCDestroy();
  99. touchPointer = null;
  100. grabPointer = null;
  101. }
  102. }
  103. }