DragTorso.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System;
  2. using UnityEngine;
  3. namespace COM3D2.MeidoPhotoStudio.Plugin
  4. {
  5. public class DragTorso : BaseDrag
  6. {
  7. private Transform[] spine;
  8. private Vector3[] spineRotation = new Vector3[4];
  9. public void Initialize(Maid maid, Transform[] spine, Func<Vector3> position, Func<Vector3> rotation)
  10. {
  11. base.Initialize(maid, position, rotation);
  12. this.spine = spine;
  13. }
  14. protected override void GetDragType()
  15. {
  16. bool shift = Input.GetKey(KeyCode.LeftShift);
  17. if (Input.GetKey(KeyCode.LeftAlt))
  18. {
  19. dragType = shift ? DragType.RotLocalY : DragType.RotLocalXZ;
  20. }
  21. else
  22. {
  23. dragType = DragType.None;
  24. }
  25. }
  26. protected override void InitializeDrag()
  27. {
  28. base.InitializeDrag();
  29. for (int i = 0; i < spine.Length; i++)
  30. {
  31. spineRotation[i] = spine[i].localEulerAngles;
  32. }
  33. }
  34. protected override void Drag()
  35. {
  36. if (dragType == DragType.None) return;
  37. if (isPlaying)
  38. {
  39. maid.GetAnimation().Stop();
  40. }
  41. Vector3 pos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z);
  42. Vector3 vec31 = Input.mousePosition - mousePos;
  43. Transform t = GameMain.Instance.MainCamera.gameObject.transform;
  44. Vector3 vec32 = t.TransformDirection(Vector3.right);
  45. Vector3 vec33 = t.TransformDirection(Vector3.forward);
  46. if (dragType == DragType.RotLocalXZ)
  47. {
  48. for (int i = 0; i < 4; i++)
  49. {
  50. spine[i].localEulerAngles = spineRotation[i];
  51. }
  52. float num1 = 1.5f;
  53. float num2 = 1f;
  54. float num3 = 0.03f;
  55. float num4 = 0.1f;
  56. float num5 = 0.09f;
  57. float num6 = 0.07f;
  58. spine[0].RotateAround(spine[0].position, new Vector3(vec32.x, 0f, vec32.z), vec31.y / num2 * num3);
  59. spine[0].RotateAround(spine[0].position, new Vector3(vec33.x, 0f, vec33.z), -vec31.x / num1 * num3);
  60. spine[1].RotateAround(spine[1].position, new Vector3(vec32.x, 0f, vec32.z), vec31.y / num2 * num4);
  61. spine[1].RotateAround(spine[1].position, new Vector3(vec33.x, 0f, vec33.z), -vec31.x / num1 * num4);
  62. spine[2].RotateAround(spine[2].position, new Vector3(vec32.x, 0f, vec32.z), vec31.y / num2 * num5);
  63. spine[2].RotateAround(spine[2].position, new Vector3(vec33.x, 0f, vec33.z), -vec31.x / num1 * num5);
  64. spine[3].RotateAround(spine[3].position, new Vector3(vec32.x, 0f, vec32.z), vec31.y / num2 * num6);
  65. spine[3].RotateAround(spine[3].position, new Vector3(vec33.x, 0f, vec33.z), -vec31.x / num1 * num6);
  66. }
  67. if (dragType == DragType.RotLocalY)
  68. {
  69. for (int i = 0; i < 4; i++)
  70. {
  71. spine[i].localEulerAngles = spineRotation[i];
  72. }
  73. spine[0].localRotation = Quaternion.Euler(spine[0].localEulerAngles)
  74. * Quaternion.AngleAxis(vec31.x / 1.5f * 0.08f, Vector3.right);
  75. spine[2].localRotation = Quaternion.Euler(spine[2].localEulerAngles)
  76. * Quaternion.AngleAxis(vec31.x / 1.5f * 0.15f, Vector3.right);
  77. spine[3].localRotation = Quaternion.Euler(spine[3].localEulerAngles)
  78. * Quaternion.AngleAxis(vec31.x / 1.5f * 0.15f, Vector3.right);
  79. }
  80. }
  81. }
  82. }