DragPointSpine.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using UnityEngine;
  2. using Input = MeidoPhotoStudio.Plugin.InputManager;
  3. namespace MeidoPhotoStudio.Plugin;
  4. public class DragPointSpine : DragPointMeido
  5. {
  6. private Quaternion spineRotation;
  7. private bool isHip;
  8. private bool isThigh;
  9. private bool isHead;
  10. public override void AddGizmo(float scale = 0.25f, CustomGizmo.GizmoMode mode = CustomGizmo.GizmoMode.Local)
  11. {
  12. base.AddGizmo(scale, mode);
  13. if (isHead)
  14. Gizmo.GizmoDrag += (_, _) =>
  15. meido.HeadToCam = false;
  16. }
  17. public override void Set(Transform myObject)
  18. {
  19. base.Set(myObject);
  20. isHip = myObject.name is "Bip01";
  21. isThigh = myObject.name.EndsWith("Thigh");
  22. isHead = myObject.name.EndsWith("Head");
  23. }
  24. protected override void ApplyDragType()
  25. {
  26. var current = CurrentDragType;
  27. if (IsBone && current is not DragType.Ignore)
  28. {
  29. if (!isHead && current is DragType.RotLocalXZ)
  30. ApplyProperties(false, false, isThigh);
  31. else if (!isThigh && current is DragType.MoveY)
  32. ApplyProperties(isHip, isHip, !isHip);
  33. else if (!isThigh && !isHead && current is DragType.RotLocalY)
  34. ApplyProperties(!isHip, !isHip, isHip);
  35. else
  36. ApplyProperties(!isThigh, !isThigh, false);
  37. }
  38. else
  39. ApplyProperties(false, false, false);
  40. }
  41. protected override void UpdateDragType()
  42. {
  43. var shift = Input.Shift;
  44. var alt = Input.Alt;
  45. if (OtherDragType())
  46. CurrentDragType = DragType.Ignore;
  47. else if (isThigh && !Input.Control && alt && shift)
  48. // gizmo thigh rotation
  49. CurrentDragType = DragType.RotLocalXZ;
  50. else if (alt)
  51. CurrentDragType = DragType.Ignore;
  52. else if (shift)
  53. CurrentDragType = DragType.RotLocalY;
  54. else if (Input.Control)
  55. // hip y transform and spine gizmo rotation
  56. CurrentDragType = DragType.MoveY;
  57. else
  58. CurrentDragType = DragType.None;
  59. }
  60. protected override void OnMouseDown()
  61. {
  62. base.OnMouseDown();
  63. spineRotation = MyObject.rotation;
  64. }
  65. protected override void Drag()
  66. {
  67. if (isPlaying)
  68. meido.Stop = true;
  69. var mouseDelta = MouseDelta();
  70. if (CurrentDragType is DragType.None)
  71. {
  72. if (isHead)
  73. meido.HeadToCam = false;
  74. MyObject.rotation = spineRotation;
  75. MyObject.Rotate(camera.transform.forward, -mouseDelta.x / 4.5f, Space.World);
  76. MyObject.Rotate(camera.transform.right, mouseDelta.y / 3f, Space.World);
  77. }
  78. if (CurrentDragType is DragType.RotLocalY)
  79. {
  80. if (isHead)
  81. meido.HeadToCam = false;
  82. MyObject.rotation = spineRotation;
  83. MyObject.Rotate(Vector3.right * mouseDelta.x / 4f);
  84. }
  85. if (CurrentDragType is DragType.MoveY)
  86. {
  87. var cursorPosition = CursorPosition();
  88. MyObject.position = new(MyObject.position.x, cursorPosition.y, MyObject.position.z);
  89. }
  90. }
  91. }