DragPelvis.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. }
  38. Vector3 pos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z);
  39. Vector3 vec31 = Input.mousePosition - mousePos;
  40. Transform t = GameMain.Instance.MainCamera.gameObject.transform;
  41. Vector3 vec32 = t.TransformDirection(Vector3.right);
  42. Vector3 vec33 = t.TransformDirection(Vector3.forward);
  43. if (dragType == DragType.RotLocalXZ)
  44. {
  45. pelvis.localEulerAngles = pelvisRotation;
  46. pelvis.RotateAround(pelvis.position, new Vector3(vec32.x, 0.0f, vec32.z), vec31.y / 4f);
  47. pelvis.RotateAround(pelvis.position, new Vector3(vec33.x, 0.0f, vec33.z), vec31.x / 6f);
  48. }
  49. if (dragType == DragType.RotLocalY)
  50. {
  51. pelvis.localEulerAngles = pelvisRotation;
  52. pelvis.localRotation = Quaternion.Euler(pelvis.localEulerAngles)
  53. * Quaternion.AngleAxis(vec31.x / 3f, Vector3.right);
  54. }
  55. }
  56. }
  57. }