DragManager.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. }
  27. // Update is called once per frame
  28. void Update()
  29. {
  30. if (state)
  31. {
  32. if (triggerState != TriggerState.No && selectTrigger != null)
  33. {
  34. MachineRoomManager.Instance.transform.eulerAngles -= new Vector3(0, selectTOldRot.y - selectTrigger.eulerAngles.y, 0);
  35. selectTOldRot = selectTrigger.eulerAngles;
  36. //MachineRoomManager.Instance.transform.position -= new Vector3(selectTOldPos.x - selectTrigger.position.x, 0, selectTOldPos.z - selectTrigger.position.z);
  37. //selectTOldPos = selectTrigger.position;
  38. MachineRoomManager.Instance.transform.position -= new Vector3(selectTOldPos.x - selectTrigger.position.x, selectTOldPos.y - selectTrigger.position.y, selectTOldPos.z - selectTrigger.position.z);
  39. selectTOldPos = selectTrigger.position;
  40. }
  41. }
  42. }
  43. private void AnyUp(InputKeyCode keyCode, InputDevicePartBase part)
  44. {
  45. // UILogManager.Instance.SendLogText(3, part.PartType.ToString());
  46. if (part.PartType == InputDevicePartType.KSRight && triggerState == TriggerState.RTrigger)
  47. {
  48. // UILogManager.Instance.SendLogText(3, "RTriggerUp");
  49. triggerState = TriggerState.No;
  50. selectTrigger = null;
  51. selectTOldPos = Vector3.zero;
  52. selectTOldRot = Vector3.zero;
  53. }
  54. if (part.PartType == InputDevicePartType.KSLeft && triggerState == TriggerState.LTrigger)
  55. {
  56. // UILogManager.Instance.SendLogText(3, "LTriggerUp");
  57. triggerState = TriggerState.No;
  58. selectTrigger = null;
  59. selectTOldPos = Vector3.zero;
  60. selectTOldRot = Vector3.zero;
  61. }
  62. }
  63. private void AnyDown(InputKeyCode keyCode, InputDevicePartBase part)
  64. {
  65. // UILogManager.Instance.SendLogText(3, part.PartType.ToString());
  66. if (part.PartType == InputDevicePartType.KSRight && triggerState == TriggerState.No)
  67. {
  68. // UILogManager.Instance.SendLogText(3, "RTriggerDown");
  69. triggerState = TriggerState.RTrigger;
  70. selectTrigger = rightKS;
  71. selectTOldPos = selectTrigger.position;
  72. selectTOldRot = selectTrigger.eulerAngles;
  73. }
  74. if (part.PartType == InputDevicePartType.KSLeft && triggerState == TriggerState.No)
  75. {
  76. triggerState = TriggerState.LTrigger;
  77. selectTrigger = leftKS;
  78. selectTOldPos = selectTrigger.position;
  79. selectTOldRot = selectTrigger.eulerAngles;
  80. }
  81. }
  82. }
  83. public enum TriggerState
  84. {
  85. No,
  86. RTrigger,
  87. LTrigger
  88. }