DragSpine.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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(
  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. dragType = DragType.MoveY;
  28. if (GizmoActive) SetGizmo(GizmoType.Rotate);
  29. }
  30. else
  31. {
  32. dragType = DragType.None;
  33. if (GizmoActive) SetGizmo(GizmoType.Rotate);
  34. }
  35. }
  36. protected override void InitializeDrag()
  37. {
  38. base.InitializeDrag();
  39. rotate = spine.localEulerAngles;
  40. if (isHip)
  41. {
  42. off = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z));
  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 (dragType == 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 (dragType == DragType.MoveY)
  64. {
  65. Vector3 pos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z)) + off - off2;
  66. spine.position = new Vector3(spine.position.x, pos.y, spine.position.z);
  67. }
  68. }
  69. }
  70. }