DragPointTorso.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using UnityEngine;
  2. namespace COM3D2.MeidoPhotoStudio.Plugin
  3. {
  4. using Input = InputManager;
  5. public class DragPointTorso : DragPointMeido
  6. {
  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. Transform spine = myObject;
  15. for (int 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 == DragType.Ignore) ApplyProperties();
  24. else if (IsBone) ApplyProperties(false, false, false);
  25. else ApplyProperties(CurrentDragType != DragType.None, false, false);
  26. }
  27. protected override void UpdateDragType()
  28. {
  29. CurrentDragType = Input.Alt && !Input.Control
  30. ? Input.Shift ? DragType.RotLocalY : DragType.RotLocalXZ
  31. : OtherDragType() ? DragType.Ignore : DragType.None;
  32. }
  33. protected override void OnMouseDown()
  34. {
  35. base.OnMouseDown();
  36. for (int i = 0; i < spine.Length; i++)
  37. {
  38. spineRotation[i] = spine[i].localRotation;
  39. }
  40. }
  41. protected override void Drag()
  42. {
  43. if (CurrentDragType == DragType.None) return;
  44. if (isPlaying) meido.Stop = true;
  45. Vector3 mouseDelta = MouseDelta();
  46. if (CurrentDragType == DragType.RotLocalXZ)
  47. {
  48. for (int i = 0; i < spine.Length; i++)
  49. {
  50. spine[i].localRotation = spineRotation[i];
  51. spine[i].Rotate(
  52. camera.transform.forward, -mouseDelta.x / 1.5f * blah[i], Space.World
  53. );
  54. spine[i].Rotate(camera.transform.right, mouseDelta.y * blah[i], Space.World);
  55. }
  56. }
  57. if (CurrentDragType == DragType.RotLocalY)
  58. {
  59. for (int i = 0; i < spine.Length; i++)
  60. {
  61. spine[i].localRotation = spineRotation[i];
  62. spine[i].Rotate(Vector3.right * (mouseDelta.x / 1.5f * something[i / 2]));
  63. }
  64. }
  65. }
  66. }
  67. }