DragPointSpine.cs 3.4 KB

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