DragPointSpine.cs 3.6 KB

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