DragPointHead.cs 4.0 KB

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