DragPointTorso.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using UnityEngine;
  2. namespace COM3D2.MeidoPhotoStudio.Plugin
  3. {
  4. internal class DragPointTorso : DragPointMeido
  5. {
  6. private static readonly float[] blah = new[] { 0.03f, 0.1f, 0.09f, 0.07f };
  7. private static readonly float[] something = new[] { 0.08f, 0.15f };
  8. private Transform[] spine = new Transform[4];
  9. private Quaternion[] spineRotation = new Quaternion[4];
  10. public override void Set(Transform spine1a)
  11. {
  12. base.Set(spine1a);
  13. Transform spine = spine1a;
  14. for (int i = 0; i < this.spine.Length; i++)
  15. {
  16. this.spine[i] = spine;
  17. spine = spine.parent;
  18. }
  19. }
  20. protected override void ApplyDragType()
  21. {
  22. if (CurrentDragType == DragType.Ignore) ApplyProperties();
  23. else if (IsBone) ApplyProperties(false, false, false);
  24. else ApplyProperties(CurrentDragType != DragType.None, false, false);
  25. }
  26. protected override void UpdateDragType()
  27. {
  28. if (Input.GetKey(KeyCode.Space) || OtherDragType())
  29. {
  30. CurrentDragType = DragType.Ignore;
  31. }
  32. else if (Utility.GetModKey(Utility.ModKey.Alt) && !Utility.GetModKey(Utility.ModKey.Control))
  33. {
  34. bool shift = Utility.GetModKey(Utility.ModKey.Shift);
  35. CurrentDragType = shift ? DragType.RotLocalY : DragType.RotLocalXZ;
  36. }
  37. else
  38. {
  39. CurrentDragType = DragType.None;
  40. }
  41. }
  42. protected override void OnMouseDown()
  43. {
  44. base.OnMouseDown();
  45. for (int i = 0; i < spine.Length; i++)
  46. {
  47. spineRotation[i] = spine[i].localRotation;
  48. }
  49. }
  50. protected override void Drag()
  51. {
  52. if (CurrentDragType == DragType.None) return;
  53. if (isPlaying) meido.Stop = true;
  54. Vector3 mouseDelta = MouseDelta();
  55. if (CurrentDragType == DragType.RotLocalXZ)
  56. {
  57. for (int i = 0; i < spine.Length; i++)
  58. {
  59. spine[i].localRotation = spineRotation[i];
  60. spine[i].Rotate(
  61. camera.transform.forward, -mouseDelta.x / 1.5f * blah[i], Space.World
  62. );
  63. spine[i].Rotate(camera.transform.right, mouseDelta.y * blah[i], Space.World);
  64. }
  65. }
  66. if (CurrentDragType == DragType.RotLocalY)
  67. {
  68. for (int i = 0; i < spine.Length; i++)
  69. {
  70. spine[i].localRotation = spineRotation[i];
  71. spine[i].Rotate(Vector3.right * (mouseDelta.x / 1.5f * something[i / 2]));
  72. }
  73. }
  74. }
  75. }
  76. }