DragPointHead.cs 3.8 KB

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