DragPointHead.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using System;
  2. using UnityEngine;
  3. namespace MeidoPhotoStudio.Plugin
  4. {
  5. using Input = InputManager;
  6. public class DragPointHead : DragPointMeido
  7. {
  8. private Quaternion headRotation;
  9. private Vector3 eyeRotationL;
  10. private Vector3 eyeRotationR;
  11. public event EventHandler Select;
  12. public bool IsIK { get; set; }
  13. protected override void ApplyDragType()
  14. {
  15. if (IsBone)
  16. {
  17. DragType current = CurrentDragType;
  18. bool active = current == DragType.MoveY || current == DragType.MoveXZ || current == DragType.Select;
  19. ApplyProperties(active, false, false);
  20. }
  21. else ApplyProperties(CurrentDragType != DragType.None, false, false);
  22. }
  23. protected override void UpdateDragType()
  24. {
  25. bool shift = Input.Shift;
  26. bool alt = Input.Alt;
  27. if (alt && Input.Control)
  28. {
  29. // eyes
  30. CurrentDragType = shift ? DragType.MoveY : DragType.MoveXZ;
  31. }
  32. else if (alt)
  33. {
  34. // head
  35. CurrentDragType = shift ? DragType.RotLocalY : DragType.RotLocalXZ;
  36. }
  37. else if (Input.GetKey(MpsKey.DragSelect))
  38. {
  39. CurrentDragType = DragType.Select;
  40. }
  41. else
  42. {
  43. CurrentDragType = DragType.None;
  44. }
  45. }
  46. protected override void OnMouseDown()
  47. {
  48. base.OnMouseDown();
  49. if (CurrentDragType == DragType.Select) Select?.Invoke(this, EventArgs.Empty);
  50. headRotation = MyObject.rotation;
  51. eyeRotationL = meido.Body.quaDefEyeL.eulerAngles;
  52. eyeRotationR = meido.Body.quaDefEyeR.eulerAngles;
  53. }
  54. protected override void OnDoubleClick()
  55. {
  56. if (CurrentDragType == DragType.MoveXZ || CurrentDragType == DragType.MoveY)
  57. {
  58. meido.Body.quaDefEyeL = meido.DefaultEyeRotL;
  59. meido.Body.quaDefEyeR = meido.DefaultEyeRotR;
  60. }
  61. else if (CurrentDragType == DragType.RotLocalY || CurrentDragType == DragType.RotLocalXZ)
  62. {
  63. meido.FreeLook = !meido.FreeLook;
  64. }
  65. }
  66. protected override void Drag()
  67. {
  68. if (IsIK || CurrentDragType == DragType.Select) return;
  69. if (!(CurrentDragType == DragType.MoveXZ || CurrentDragType == DragType.MoveY) && isPlaying)
  70. {
  71. meido.Stop = true;
  72. }
  73. Vector3 mouseDelta = MouseDelta();
  74. if (CurrentDragType == DragType.RotLocalXZ)
  75. {
  76. MyObject.rotation = headRotation;
  77. MyObject.Rotate(camera.transform.forward, -mouseDelta.x / 3f, Space.World);
  78. MyObject.Rotate(camera.transform.right, mouseDelta.y / 3f, Space.World);
  79. }
  80. if (CurrentDragType == DragType.RotLocalY)
  81. {
  82. MyObject.rotation = headRotation;
  83. MyObject.Rotate(Vector3.right * mouseDelta.x / 3f);
  84. }
  85. if (CurrentDragType == DragType.MoveXZ || CurrentDragType == DragType.MoveY)
  86. {
  87. int inv = CurrentDragType == DragType.MoveY ? -1 : 1;
  88. meido.Body.quaDefEyeL.eulerAngles = new Vector3(
  89. eyeRotationL.x, eyeRotationL.y - (mouseDelta.x / 10f), eyeRotationL.z - (mouseDelta.y / 10f)
  90. );
  91. meido.Body.quaDefEyeR.eulerAngles = new Vector3(
  92. eyeRotationR.x, eyeRotationR.y + (inv * mouseDelta.x / 10f), eyeRotationR.z + (mouseDelta.y / 10f)
  93. );
  94. }
  95. }
  96. }
  97. }