DragPointTorso.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using UnityEngine;
  2. namespace COM3D2.MeidoPhotoStudio.Plugin
  3. {
  4. using Input = InputManager;
  5. internal 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 Transform[] spine = new Transform[4];
  10. private Quaternion[] spineRotation = new Quaternion[4];
  11. public override void Set(Transform spine1a)
  12. {
  13. base.Set(spine1a);
  14. Transform spine = spine1a;
  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. if (Input.Alt && !Input.Control)
  30. {
  31. CurrentDragType = Input.Shift ? DragType.RotLocalY : DragType.RotLocalXZ;
  32. }
  33. else
  34. {
  35. CurrentDragType = OtherDragType() ? DragType.Ignore : DragType.None;
  36. }
  37. }
  38. protected override void OnMouseDown()
  39. {
  40. base.OnMouseDown();
  41. for (int i = 0; i < spine.Length; i++)
  42. {
  43. spineRotation[i] = spine[i].localRotation;
  44. }
  45. }
  46. protected override void Drag()
  47. {
  48. if (CurrentDragType == DragType.None) return;
  49. if (isPlaying) meido.Stop = true;
  50. Vector3 mouseDelta = MouseDelta();
  51. if (CurrentDragType == DragType.RotLocalXZ)
  52. {
  53. for (int i = 0; i < spine.Length; i++)
  54. {
  55. spine[i].localRotation = spineRotation[i];
  56. spine[i].Rotate(
  57. camera.transform.forward, -mouseDelta.x / 1.5f * blah[i], Space.World
  58. );
  59. spine[i].Rotate(camera.transform.right, mouseDelta.y * blah[i], Space.World);
  60. }
  61. }
  62. if (CurrentDragType == DragType.RotLocalY)
  63. {
  64. for (int i = 0; i < spine.Length; i++)
  65. {
  66. spine[i].localRotation = spineRotation[i];
  67. spine[i].Rotate(Vector3.right * (mouseDelta.x / 1.5f * something[i / 2]));
  68. }
  69. }
  70. }
  71. }
  72. }