DragTorso.cs 3.6 KB

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