DragPointSpine.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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
  31. {
  32. bool active = !isThigh;
  33. ApplyProperties(active, active, false);
  34. }
  35. }
  36. else ApplyProperties(false, false, false);
  37. }
  38. protected override void UpdateDragType()
  39. {
  40. bool shift = Utility.GetModKey(Utility.ModKey.Shift);
  41. bool alt = Utility.GetModKey(Utility.ModKey.Alt);
  42. bool ctrl = Utility.GetModKey(Utility.ModKey.Control);
  43. if (Input.GetKey(KeyCode.Space) || OtherDragType())
  44. {
  45. CurrentDragType = DragType.Ignore;
  46. }
  47. else if (isThigh && alt && shift)
  48. {
  49. // gizmo thigh rotation
  50. CurrentDragType = DragType.RotLocalXZ;
  51. }
  52. else if (alt)
  53. {
  54. CurrentDragType = DragType.Ignore;
  55. }
  56. else if (shift)
  57. {
  58. CurrentDragType = DragType.RotLocalY;
  59. }
  60. else if (ctrl)
  61. {
  62. // hip y transform and spine gizmo rotation
  63. CurrentDragType = DragType.MoveY;
  64. }
  65. else
  66. {
  67. CurrentDragType = DragType.None;
  68. }
  69. }
  70. protected override void OnMouseDown()
  71. {
  72. base.OnMouseDown();
  73. spineRotation = MyObject.rotation;
  74. }
  75. protected override void Drag()
  76. {
  77. if (isPlaying) meido.Stop = true;
  78. if (CurrentDragType == DragType.None)
  79. {
  80. if (isHead) meido.HeadToCam = false;
  81. Vector3 mouseDelta = MouseDelta();
  82. MyObject.rotation = spineRotation;
  83. MyObject.Rotate(camera.transform.forward, -mouseDelta.x / 4.5f, Space.World);
  84. MyObject.Rotate(camera.transform.right, mouseDelta.y / 3f, Space.World);
  85. }
  86. if (CurrentDragType == DragType.MoveY)
  87. {
  88. Vector3 cursorPosition = CursorPosition();
  89. MyObject.position = new Vector3(MyObject.position.x, cursorPosition.y, MyObject.position.z);
  90. }
  91. }
  92. }
  93. }