DragPointHead.cs 3.9 KB

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