DragSpine.cs 2.6 KB

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