DragSpine.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System;
  2. using UnityEngine;
  3. namespace COM3D2.MeidoPhotoStudio.Plugin
  4. {
  5. using static CustomGizmo;
  6. public class DragSpine : BaseDrag
  7. {
  8. private Transform spine;
  9. private Vector3 rotate;
  10. private Vector3 off;
  11. private Vector3 off2;
  12. private bool isHip;
  13. public DragSpine Initialize(
  14. Transform spine, bool isHip,
  15. Meido meido, Func<Vector3> position, Func<Vector3> rotation
  16. )
  17. {
  18. base.Initialize(meido, position, rotation);
  19. this.spine = spine;
  20. this.isHip = isHip;
  21. InitializeGizmo(this.spine);
  22. return this;
  23. }
  24. protected override void GetDragType()
  25. {
  26. if (isHip && Utility.GetModKey(Utility.ModKey.Control))
  27. {
  28. CurrentDragType = DragType.MoveY;
  29. }
  30. else
  31. {
  32. CurrentDragType = DragType.None;
  33. }
  34. }
  35. protected override void InitializeDrag()
  36. {
  37. base.InitializeDrag();
  38. rotate = spine.localEulerAngles;
  39. if (isHip)
  40. {
  41. off = transform.position - Camera.main.ScreenToWorldPoint(
  42. new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z)
  43. );
  44. off2 = new Vector3(
  45. transform.position.x - spine.position.x,
  46. transform.position.y - spine.position.y,
  47. transform.position.z - spine.position.z
  48. );
  49. }
  50. }
  51. protected override void Drag()
  52. {
  53. if (isPlaying) meido.IsStop = true;
  54. if (CurrentDragType == DragType.None)
  55. {
  56. Vector3 vec31 = Input.mousePosition - mousePos;
  57. Transform t = GameMain.Instance.MainCamera.gameObject.transform;
  58. Vector3 vec32 = t.TransformDirection(Vector3.right);
  59. Vector3 vec33 = t.TransformDirection(Vector3.forward);
  60. spine.localEulerAngles = rotate;
  61. spine.RotateAround(spine.position, new Vector3(vec32.x, 0.0f, vec32.z), vec31.y / 3f);
  62. spine.RotateAround(spine.position, new Vector3(vec33.x, 0.0f, vec33.z), (-vec31.x / 4.5f));
  63. }
  64. if (CurrentDragType == DragType.MoveY)
  65. {
  66. Vector3 pos = Camera.main.ScreenToWorldPoint(
  67. new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z)
  68. ) + off - off2;
  69. spine.position = new Vector3(spine.position.x, pos.y, spine.position.z);
  70. }
  71. }
  72. }
  73. }