DragPointSpine.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. public override void Set(Transform spine)
  10. {
  11. base.Set(spine);
  12. isHip = spine.name == "Bip01";
  13. isThigh = spine.name.EndsWith("Thigh");
  14. }
  15. protected override void ApplyDragType()
  16. {
  17. DragType current = CurrentDragType;
  18. if (IsBone && current != DragType.Ignore)
  19. {
  20. if (current == DragType.RotLocalXZ) ApplyProperties(false, false, isThigh);
  21. else if (!isThigh && (current == DragType.MoveY)) ApplyProperties(isHip, isHip, !isHip);
  22. else if (!isThigh && (current == DragType.RotLocalY)) ApplyProperties(!isHip, !isHip, isHip);
  23. else ApplyProperties(!isThigh, !isThigh, false);
  24. }
  25. else ApplyProperties(false, false, false);
  26. }
  27. protected override void UpdateDragType()
  28. {
  29. bool shift = Utility.GetModKey(Utility.ModKey.Shift);
  30. bool alt = Utility.GetModKey(Utility.ModKey.Alt);
  31. if (Input.GetKey(KeyCode.Space) || OtherDragType())
  32. {
  33. CurrentDragType = DragType.Ignore;
  34. }
  35. else if (isThigh && alt && shift)
  36. {
  37. // gizmo thigh rotation
  38. CurrentDragType = DragType.RotLocalXZ;
  39. }
  40. else if (alt)
  41. {
  42. CurrentDragType = DragType.Ignore;
  43. }
  44. else if (shift)
  45. {
  46. CurrentDragType = DragType.RotLocalY;
  47. }
  48. else if (Utility.GetModKey(Utility.ModKey.Control))
  49. {
  50. // hip y transform and spine gizmo rotation
  51. CurrentDragType = DragType.MoveY;
  52. }
  53. else
  54. {
  55. CurrentDragType = DragType.None;
  56. }
  57. }
  58. protected override void OnMouseDown()
  59. {
  60. base.OnMouseDown();
  61. spineRotation = MyObject.rotation;
  62. }
  63. protected override void Drag()
  64. {
  65. if (isPlaying) meido.Stop = true;
  66. if (CurrentDragType == DragType.None)
  67. {
  68. Vector3 mouseDelta = MouseDelta();
  69. MyObject.rotation = spineRotation;
  70. MyObject.Rotate(camera.transform.forward, -mouseDelta.x / 4.5f, Space.World);
  71. MyObject.Rotate(camera.transform.right, mouseDelta.y / 3f, Space.World);
  72. }
  73. if (CurrentDragType == DragType.MoveY)
  74. {
  75. Vector3 cursorPosition = CursorPosition();
  76. MyObject.position = new Vector3(MyObject.position.x, cursorPosition.y, MyObject.position.z);
  77. }
  78. }
  79. }
  80. }