DragPointHead.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using System;
  2. using UnityEngine;
  3. using Input = MeidoPhotoStudio.Plugin.InputManager;
  4. namespace MeidoPhotoStudio.Plugin;
  5. public class DragPointHead : DragPointMeido
  6. {
  7. private Quaternion headRotation;
  8. private Vector3 eyeRotationL;
  9. private Vector3 eyeRotationR;
  10. public event EventHandler Select;
  11. public bool IsIK { get; set; }
  12. protected override void ApplyDragType()
  13. {
  14. if (IsBone)
  15. {
  16. var current = CurrentDragType;
  17. var active = current is DragType.MoveY or DragType.MoveXZ or DragType.Select;
  18. ApplyProperties(active, false, false);
  19. }
  20. else
  21. {
  22. ApplyProperties(CurrentDragType is not DragType.None, false, false);
  23. }
  24. }
  25. protected override void UpdateDragType()
  26. {
  27. var shift = Input.Shift;
  28. var alt = Input.Alt;
  29. if (alt && Input.Control)
  30. {
  31. // eyes
  32. CurrentDragType = shift
  33. ? DragType.MoveY
  34. : DragType.MoveXZ;
  35. }
  36. else if (alt)
  37. {
  38. // head
  39. CurrentDragType = shift
  40. ? DragType.RotLocalY
  41. : DragType.RotLocalXZ;
  42. }
  43. else
  44. {
  45. CurrentDragType = Input.GetKey(MpsKey.DragSelect)
  46. ? DragType.Select
  47. : DragType.None;
  48. }
  49. }
  50. protected override void OnMouseDown()
  51. {
  52. base.OnMouseDown();
  53. if (CurrentDragType is DragType.Select)
  54. Select?.Invoke(this, EventArgs.Empty);
  55. headRotation = MyObject.rotation;
  56. eyeRotationL = meido.Body.quaDefEyeL.eulerAngles;
  57. eyeRotationR = meido.Body.quaDefEyeR.eulerAngles;
  58. }
  59. protected override void OnDoubleClick()
  60. {
  61. if (CurrentDragType is DragType.MoveXZ or DragType.MoveY)
  62. {
  63. meido.Body.quaDefEyeL = meido.DefaultEyeRotL;
  64. meido.Body.quaDefEyeR = meido.DefaultEyeRotR;
  65. }
  66. else if (CurrentDragType is DragType.RotLocalY or DragType.RotLocalXZ)
  67. {
  68. meido.FreeLook = !meido.FreeLook;
  69. }
  70. }
  71. protected override void Drag()
  72. {
  73. if (IsIK || CurrentDragType is DragType.Select)
  74. return;
  75. if (CurrentDragType is not DragType.MoveXZ and not DragType.MoveY && isPlaying)
  76. meido.Stop = true;
  77. var mouseDelta = MouseDelta();
  78. if (CurrentDragType is DragType.RotLocalXZ)
  79. {
  80. MyObject.rotation = headRotation;
  81. MyObject.Rotate(camera.transform.forward, -mouseDelta.x / 3f, Space.World);
  82. MyObject.Rotate(camera.transform.right, mouseDelta.y / 3f, Space.World);
  83. }
  84. if (CurrentDragType is DragType.RotLocalY)
  85. {
  86. MyObject.rotation = headRotation;
  87. MyObject.Rotate(Vector3.right * mouseDelta.x / 3f);
  88. }
  89. if (CurrentDragType is DragType.MoveXZ or DragType.MoveY)
  90. {
  91. var inv = CurrentDragType is DragType.MoveY ? -1 : 1;
  92. meido.Body.quaDefEyeL.eulerAngles =
  93. new(eyeRotationL.x, eyeRotationL.y - mouseDelta.x / 10f, eyeRotationL.z - mouseDelta.y / 10f);
  94. meido.Body.quaDefEyeR.eulerAngles =
  95. new(eyeRotationR.x, eyeRotationR.y + inv * mouseDelta.x / 10f, eyeRotationR.z + mouseDelta.y / 10f);
  96. }
  97. }
  98. }