DragPelvis.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. using UnityEngine;
  3. namespace COM3D2.MeidoPhotoStudio.Plugin
  4. {
  5. public class DragPelvis : BaseDrag
  6. {
  7. private Transform pelvis;
  8. private Vector3 pelvisRotation;
  9. public void Initialize(Maid maid, Transform pelvis, Func<Vector3> position, Func<Vector3> rotation)
  10. {
  11. base.Initialize(maid, position, rotation);
  12. this.pelvis = pelvis;
  13. }
  14. protected override void GetDragType()
  15. {
  16. bool shift = Input.GetKey(KeyCode.LeftShift);
  17. if (Input.GetKey(KeyCode.LeftAlt))
  18. {
  19. dragType = shift ? DragType.RotLocalY : DragType.RotLocalXZ;
  20. }
  21. else
  22. {
  23. dragType = DragType.None;
  24. }
  25. }
  26. protected override void InitializeDrag()
  27. {
  28. base.InitializeDrag();
  29. pelvisRotation = pelvis.localEulerAngles;
  30. }
  31. protected override void Drag()
  32. {
  33. if (dragType == DragType.None) return;
  34. if (isPlaying)
  35. {
  36. maid.GetAnimation().Stop();
  37. OnDragEvent();
  38. }
  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. pelvis.localEulerAngles = pelvisRotation;
  47. pelvis.RotateAround(pelvis.position, new Vector3(vec32.x, 0.0f, vec32.z), vec31.y / 4f);
  48. pelvis.RotateAround(pelvis.position, new Vector3(vec33.x, 0.0f, vec33.z), vec31.x / 6f);
  49. }
  50. if (dragType == DragType.RotLocalY)
  51. {
  52. pelvis.localEulerAngles = pelvisRotation;
  53. pelvis.localRotation = Quaternion.Euler(pelvis.localEulerAngles)
  54. * Quaternion.AngleAxis(vec31.x / 3f, Vector3.right);
  55. }
  56. }
  57. }
  58. }