DragPointTorso.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using UnityEngine;
  2. using Input = MeidoPhotoStudio.Plugin.InputManager;
  3. namespace MeidoPhotoStudio.Plugin;
  4. public class DragPointTorso : DragPointMeido
  5. {
  6. // TODO: Rename these to something more descriptive
  7. private static readonly float[] Blah = new[] { 0.03f, 0.1f, 0.09f, 0.07f };
  8. private static readonly float[] Something = new[] { 0.08f, 0.15f };
  9. private readonly Quaternion[] spineRotation = new Quaternion[4];
  10. private readonly Transform[] spine = new Transform[4];
  11. public override void Set(Transform myObject)
  12. {
  13. base.Set(myObject);
  14. var spine = myObject;
  15. for (var i = 0; i < this.spine.Length; i++)
  16. {
  17. this.spine[i] = spine;
  18. spine = spine.parent;
  19. }
  20. }
  21. protected override void ApplyDragType()
  22. {
  23. if (CurrentDragType is DragType.Ignore)
  24. ApplyProperties();
  25. else if (IsBone)
  26. ApplyProperties(false, false, false);
  27. else
  28. ApplyProperties(CurrentDragType is not DragType.None, false, false);
  29. }
  30. protected override void UpdateDragType() =>
  31. // TODO: Rethink this formatting
  32. CurrentDragType = Input.Alt && !Input.Control
  33. ? Input.Shift
  34. ? DragType.RotLocalY
  35. : DragType.RotLocalXZ
  36. : OtherDragType()
  37. ? DragType.Ignore
  38. : DragType.None;
  39. protected override void OnMouseDown()
  40. {
  41. base.OnMouseDown();
  42. for (var i = 0; i < spine.Length; i++)
  43. spineRotation[i] = spine[i].localRotation;
  44. }
  45. protected override void Drag()
  46. {
  47. if (CurrentDragType is DragType.None)
  48. return;
  49. if (isPlaying)
  50. meido.Stop = true;
  51. var mouseDelta = MouseDelta();
  52. if (CurrentDragType is DragType.RotLocalXZ)
  53. for (var i = 0; i < spine.Length; i++)
  54. {
  55. spine[i].localRotation = spineRotation[i];
  56. spine[i].Rotate(camera.transform.forward, -mouseDelta.x / 1.5f * Blah[i], Space.World);
  57. spine[i].Rotate(camera.transform.right, mouseDelta.y * Blah[i], Space.World);
  58. }
  59. if (CurrentDragType is DragType.RotLocalY)
  60. for (var i = 0; i < spine.Length; i++)
  61. {
  62. spine[i].localRotation = spineRotation[i];
  63. spine[i].Rotate(Vector3.right * (mouseDelta.x / 1.5f * Something[i / 2]));
  64. }
  65. }
  66. }