AllMoveEvent.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using SC.XR.Unity.Module_InputSystem;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. public class AllMoveEvent : MonoBehaviour
  7. {
  8. // Start is called before the first frame update
  9. void Start()
  10. {
  11. DispatcherBase.KeyDownDelegateRegister(downEvent);
  12. DispatcherBase.KeyUpDelegateRegister(upEvent);
  13. }
  14. InputDevicePartBase NowPart;
  15. GameObject pz;
  16. private void upEvent(InputKeyCode keyCode, InputDevicePartBase part)
  17. {
  18. if (part.inputDataBase.SCPointEventData.pointerCurrentRaycast.gameObject != null && (part.inputDataBase.SCPointEventData.pointerCurrentRaycast.gameObject.GetComponent<BoxCollider>() == null || part.inputDataBase.SCPointEventData.pointerCurrentRaycast.gameObject.GetComponent<ManipulationHandler>() == null))
  19. {
  20. checkMoveUp(pz, part);
  21. }
  22. pz = null;
  23. NowPart = null;
  24. }
  25. public void checkMoveUp(GameObject obj, InputDevicePartBase part)
  26. {
  27. if (obj)
  28. {
  29. ManipulationHandler m = obj.GetComponent<ManipulationHandler>();
  30. if (m != null)
  31. {
  32. if (!m.enabled)
  33. {
  34. return;
  35. }
  36. if (!m.isParentDrag && !obj.name.Contains("Root") && !obj.name.Contains("BoundingBox"))
  37. {
  38. m.OnPointerUp(part.inputDataBase.SCPointEventData);
  39. }
  40. }
  41. else
  42. {
  43. if (obj.transform.parent != null && !obj.name.Contains("Root") && !obj.name.Contains("BoundingBox"))
  44. checkMoveUp(obj.transform.parent.gameObject, part);
  45. }
  46. }
  47. }
  48. private void downEvent(InputKeyCode keyCode, InputDevicePartBase part)
  49. {
  50. if (part.inputDataBase.SCPointEventData.pointerCurrentRaycast.gameObject != null && (part.inputDataBase.SCPointEventData.pointerCurrentRaycast.gameObject.GetComponent<BoxCollider>() == null || part.inputDataBase.SCPointEventData.pointerCurrentRaycast.gameObject.GetComponent<ManipulationHandler>() == null))
  51. {
  52. checkMoveDown(part.inputDataBase.SCPointEventData.pointerCurrentRaycast.gameObject, part);
  53. }
  54. NowPart = part;
  55. }
  56. public void checkMoveDown(GameObject obj, InputDevicePartBase part)
  57. {
  58. if (obj)
  59. {
  60. ManipulationHandler m = obj.GetComponent<ManipulationHandler>();
  61. if (m != null)
  62. {
  63. if (!m.enabled)
  64. {
  65. return;
  66. }
  67. if (!m.isParentDrag && !obj.name.Contains("Root") && !obj.name.Contains("BoundingBox"))
  68. {
  69. m.OnPointerDown(part.inputDataBase.SCPointEventData);
  70. pz = obj;
  71. }
  72. }
  73. else
  74. {
  75. if (obj.transform.parent != null && !obj.name.Contains("Root") && !obj.name.Contains("BoundingBox"))
  76. checkMoveDown(obj.transform.parent.gameObject, part);
  77. }
  78. }
  79. }
  80. // Update is called once per frame
  81. void Update()
  82. {
  83. if (NowPart != null && pz != null)
  84. {
  85. checkMoveDrag(pz, NowPart);
  86. }
  87. }
  88. public void checkMoveDrag(GameObject obj, InputDevicePartBase part)
  89. {
  90. if (obj)
  91. {
  92. ManipulationHandler m = obj.GetComponent<ManipulationHandler>();
  93. if (m != null && !obj.name.Contains("Root") && !obj.name.Contains("BoundingBox"))
  94. {
  95. if (!m.enabled)
  96. {
  97. return;
  98. }
  99. if (!m.isParentDrag)
  100. m.OnDrag(part.inputDataBase.SCPointEventData);
  101. }
  102. else
  103. {
  104. if (obj.transform.parent != null && !obj.name.Contains("Root") && !obj.name.Contains("BoundingBox"))
  105. {
  106. checkMoveDrag(obj.transform.parent.gameObject, part);
  107. }
  108. }
  109. }
  110. }
  111. }