DragManager.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using SC.XR.Unity.Module_InputSystem;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. /// <summary>
  6. /// 编辑移动场景
  7. /// </summary>
  8. public class DragManager : MonoSingleton<DragManager>
  9. {
  10. public TriggerState triggerState;
  11. public Transform rightKS;
  12. public Transform leftKS;
  13. private Transform selectTrigger;
  14. private Vector3 selectTOldPos;
  15. private Vector3 selectTOldRot;
  16. /// <summary>
  17. /// 编辑状态
  18. /// </summary>
  19. public bool state;
  20. // Start is called before the first frame update
  21. void Start()
  22. {
  23. triggerState = TriggerState.No;
  24. DispatcherBase.KeyDownDelegateRegister(AnyDown);
  25. DispatcherBase.KeyUpDelegateRegister(AnyUp);
  26. rightKS = OpenXRCamera.Instance.rightKs;
  27. leftKS = OpenXRCamera.Instance.leftKs;
  28. }
  29. // Update is called once per frame
  30. void Update()
  31. {
  32. if (state)
  33. {
  34. if (triggerState != TriggerState.No && selectTrigger != null)
  35. {
  36. MachineRoomManager.Instance.transform.eulerAngles -= new Vector3(0, selectTOldRot.y - selectTrigger.eulerAngles.y, 0);
  37. selectTOldRot = selectTrigger.eulerAngles;
  38. //MachineRoomManager.Instance.transform.position -= new Vector3(selectTOldPos.x - selectTrigger.position.x, 0, selectTOldPos.z - selectTrigger.position.z);
  39. //selectTOldPos = selectTrigger.position;
  40. MachineRoomManager.Instance.transform.position -= new Vector3(selectTOldPos.x - selectTrigger.position.x, selectTOldPos.y - selectTrigger.position.y, selectTOldPos.z - selectTrigger.position.z);
  41. selectTOldPos = selectTrigger.position;
  42. }
  43. }
  44. }
  45. private void AnyUp(InputKeyCode keyCode, InputDevicePartBase part)
  46. {
  47. // UILogManager.Instance.SendLogText(3, part.PartType.ToString());
  48. if (part.PartType == InputDevicePartType.KSRight && triggerState == TriggerState.RTrigger)
  49. {
  50. // UILogManager.Instance.SendLogText(3, "RTriggerUp");
  51. triggerState = TriggerState.No;
  52. selectTrigger = null;
  53. selectTOldPos = Vector3.zero;
  54. selectTOldRot = Vector3.zero;
  55. }
  56. if (part.PartType == InputDevicePartType.KSLeft && triggerState == TriggerState.LTrigger)
  57. {
  58. // UILogManager.Instance.SendLogText(3, "LTriggerUp");
  59. triggerState = TriggerState.No;
  60. selectTrigger = null;
  61. selectTOldPos = Vector3.zero;
  62. selectTOldRot = Vector3.zero;
  63. }
  64. }
  65. private void AnyDown(InputKeyCode keyCode, InputDevicePartBase part)
  66. {
  67. // UILogManager.Instance.SendLogText(3, part.PartType.ToString());
  68. if (part.PartType == InputDevicePartType.KSRight && triggerState == TriggerState.No)
  69. {
  70. // UILogManager.Instance.SendLogText(3, "RTriggerDown");
  71. triggerState = TriggerState.RTrigger;
  72. selectTrigger = rightKS;
  73. selectTOldPos = selectTrigger.position;
  74. selectTOldRot = selectTrigger.eulerAngles;
  75. }
  76. if (part.PartType == InputDevicePartType.KSLeft && triggerState == TriggerState.No)
  77. {
  78. triggerState = TriggerState.LTrigger;
  79. selectTrigger = leftKS;
  80. selectTOldPos = selectTrigger.position;
  81. selectTOldRot = selectTrigger.eulerAngles;
  82. }
  83. }
  84. }
  85. public enum TriggerState
  86. {
  87. No,
  88. RTrigger,
  89. LTrigger
  90. }