DragPointSpine.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. {
  40. ApplyProperties(false, false, false);
  41. }
  42. }
  43. protected override void UpdateDragType()
  44. {
  45. var shift = Input.Shift;
  46. var alt = Input.Alt;
  47. if (OtherDragType())
  48. {
  49. CurrentDragType = DragType.Ignore;
  50. }
  51. else if (isThigh && !Input.Control && alt && shift)
  52. {
  53. // gizmo thigh rotation
  54. CurrentDragType = DragType.RotLocalXZ;
  55. }
  56. else if (alt)
  57. {
  58. CurrentDragType = DragType.Ignore;
  59. }
  60. else if (shift)
  61. {
  62. CurrentDragType = DragType.RotLocalY;
  63. }
  64. else if (Input.Control)
  65. {
  66. // hip y transform and spine gizmo rotation
  67. CurrentDragType = DragType.MoveY;
  68. }
  69. else
  70. {
  71. CurrentDragType = DragType.None;
  72. }
  73. }
  74. protected override void OnMouseDown()
  75. {
  76. base.OnMouseDown();
  77. spineRotation = MyObject.rotation;
  78. }
  79. protected override void Drag()
  80. {
  81. if (isPlaying)
  82. meido.Stop = true;
  83. var mouseDelta = MouseDelta();
  84. if (CurrentDragType is DragType.None)
  85. {
  86. if (isHead)
  87. meido.HeadToCam = false;
  88. MyObject.rotation = spineRotation;
  89. MyObject.Rotate(camera.transform.forward, -mouseDelta.x / 4.5f, Space.World);
  90. MyObject.Rotate(camera.transform.right, mouseDelta.y / 3f, Space.World);
  91. }
  92. if (CurrentDragType is DragType.RotLocalY)
  93. {
  94. if (isHead)
  95. meido.HeadToCam = false;
  96. MyObject.rotation = spineRotation;
  97. MyObject.Rotate(Vector3.right * mouseDelta.x / 4f);
  98. }
  99. if (CurrentDragType is DragType.MoveY)
  100. {
  101. var cursorPosition = CursorPosition();
  102. MyObject.position = new(MyObject.position.x, cursorPosition.y, MyObject.position.z);
  103. }
  104. }
  105. }