DragPointSpine.cs 2.9 KB

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