DragTorso.cs 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. OnDragEvent();
  41. }
  42. Vector3 pos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z);
  43. Vector3 vec31 = Input.mousePosition - mousePos;
  44. Transform t = GameMain.Instance.MainCamera.gameObject.transform;
  45. Vector3 vec32 = t.TransformDirection(Vector3.right);
  46. Vector3 vec33 = t.TransformDirection(Vector3.forward);
  47. if (dragType == DragType.RotLocalXZ)
  48. {
  49. for (int i = 0; i < 4; i++)
  50. {
  51. spine[i].localEulerAngles = spineRotation[i];
  52. }
  53. float num1 = 1.5f;
  54. float num2 = 1f;
  55. float num3 = 0.03f;
  56. float num4 = 0.1f;
  57. float num5 = 0.09f;
  58. float num6 = 0.07f;
  59. spine[0].RotateAround(spine[0].position, new Vector3(vec32.x, 0f, vec32.z), vec31.y / num2 * num3);
  60. spine[0].RotateAround(spine[0].position, new Vector3(vec33.x, 0f, vec33.z), -vec31.x / num1 * num3);
  61. spine[1].RotateAround(spine[1].position, new Vector3(vec32.x, 0f, vec32.z), vec31.y / num2 * num4);
  62. spine[1].RotateAround(spine[1].position, new Vector3(vec33.x, 0f, vec33.z), -vec31.x / num1 * num4);
  63. spine[2].RotateAround(spine[2].position, new Vector3(vec32.x, 0f, vec32.z), vec31.y / num2 * num5);
  64. spine[2].RotateAround(spine[2].position, new Vector3(vec33.x, 0f, vec33.z), -vec31.x / num1 * num5);
  65. spine[3].RotateAround(spine[3].position, new Vector3(vec32.x, 0f, vec32.z), vec31.y / num2 * num6);
  66. spine[3].RotateAround(spine[3].position, new Vector3(vec33.x, 0f, vec33.z), -vec31.x / num1 * num6);
  67. }
  68. if (dragType == DragType.RotLocalY)
  69. {
  70. for (int i = 0; i < 4; i++)
  71. {
  72. spine[i].localEulerAngles = spineRotation[i];
  73. }
  74. spine[0].localRotation = Quaternion.Euler(spine[0].localEulerAngles)
  75. * Quaternion.AngleAxis(vec31.x / 1.5f * 0.08f, Vector3.right);
  76. spine[2].localRotation = Quaternion.Euler(spine[2].localEulerAngles)
  77. * Quaternion.AngleAxis(vec31.x / 1.5f * 0.15f, Vector3.right);
  78. spine[3].localRotation = Quaternion.Euler(spine[3].localEulerAngles)
  79. * Quaternion.AngleAxis(vec31.x / 1.5f * 0.15f, Vector3.right);
  80. }
  81. }
  82. }
  83. }