DragPelvis.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 DragPelvis Initialize(Transform pelvis, Meido meido, Func<Vector3> position, Func<Vector3> rotation)
  10. {
  11. base.Initialize(meido, position, rotation);
  12. this.pelvis = pelvis;
  13. return this;
  14. }
  15. protected override void GetDragType()
  16. {
  17. bool shift = Input.GetKey(KeyCode.LeftShift);
  18. if (Input.GetKey(KeyCode.LeftAlt))
  19. {
  20. dragType = shift ? DragType.RotLocalY : DragType.RotLocalXZ;
  21. }
  22. else
  23. {
  24. dragType = DragType.None;
  25. }
  26. }
  27. protected override void InitializeDrag()
  28. {
  29. base.InitializeDrag();
  30. pelvisRotation = pelvis.localEulerAngles;
  31. }
  32. protected override void Drag()
  33. {
  34. if (dragType == DragType.None) return;
  35. if (isPlaying) meido.IsStop = true;
  36. Vector3 pos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z);
  37. Vector3 vec31 = Input.mousePosition - mousePos;
  38. Transform t = GameMain.Instance.MainCamera.gameObject.transform;
  39. Vector3 vec32 = t.TransformDirection(Vector3.right);
  40. Vector3 vec33 = t.TransformDirection(Vector3.forward);
  41. if (dragType == DragType.RotLocalXZ)
  42. {
  43. pelvis.localEulerAngles = pelvisRotation;
  44. pelvis.RotateAround(pelvis.position, new Vector3(vec32.x, 0.0f, vec32.z), vec31.y / 4f);
  45. pelvis.RotateAround(pelvis.position, new Vector3(vec33.x, 0.0f, vec33.z), vec31.x / 6f);
  46. }
  47. if (dragType == DragType.RotLocalY)
  48. {
  49. pelvis.localEulerAngles = pelvisRotation;
  50. pelvis.localRotation = Quaternion.Euler(pelvis.localEulerAngles)
  51. * Quaternion.AngleAxis(vec31.x / 3f, Vector3.right);
  52. }
  53. }
  54. }
  55. }