DragPelvis.cs 2.1 KB

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