DragPointSpine.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using UnityEngine;
  2. namespace COM3D2.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 (isThigh && alt && shift)
  40. {
  41. // gizmo thigh rotation
  42. CurrentDragType = DragType.RotLocalXZ;
  43. }
  44. else if (alt)
  45. {
  46. CurrentDragType = DragType.Ignore;
  47. }
  48. else if (shift)
  49. {
  50. CurrentDragType = DragType.RotLocalY;
  51. }
  52. else if (Input.Control)
  53. {
  54. // hip y transform and spine gizmo rotation
  55. CurrentDragType = DragType.MoveY;
  56. }
  57. else
  58. {
  59. CurrentDragType = OtherDragType() ? DragType.Ignore : DragType.None;
  60. }
  61. }
  62. protected override void OnMouseDown()
  63. {
  64. base.OnMouseDown();
  65. spineRotation = MyObject.rotation;
  66. }
  67. protected override void Drag()
  68. {
  69. if (isPlaying) meido.Stop = true;
  70. Vector3 mouseDelta = MouseDelta();
  71. if (CurrentDragType == DragType.None)
  72. {
  73. if (isHead) 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 == DragType.RotLocalY)
  79. {
  80. if (isHead) meido.HeadToCam = false;
  81. MyObject.rotation = spineRotation;
  82. MyObject.Rotate(Vector3.right * mouseDelta.x / 4f);
  83. }
  84. if (CurrentDragType == DragType.MoveY)
  85. {
  86. Vector3 cursorPosition = CursorPosition();
  87. MyObject.position = new Vector3(MyObject.position.x, cursorPosition.y, MyObject.position.z);
  88. }
  89. }
  90. }
  91. }