DragSpine.cs 2.6 KB

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