DragBody.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. using System;
  2. using UnityEngine;
  3. namespace COM3D2.MeidoPhotoStudio.Plugin
  4. {
  5. public class DragBody : BaseDrag
  6. {
  7. private Vector3 off;
  8. private Vector3 off2;
  9. private Vector3 mousePos2;
  10. private float maidScale;
  11. private Vector3 maidRot;
  12. public bool renderBody = true;
  13. public event EventHandler Select;
  14. protected override void GetDragType()
  15. {
  16. bool holdShift = Utility.GetModKey(Utility.ModKey.Shift);
  17. if (Input.GetKey(KeyCode.A))
  18. {
  19. dragType = DragType.Select;
  20. }
  21. else if (Input.GetKey(KeyCode.Z))
  22. {
  23. if (Utility.GetModKey(Utility.ModKey.Control)) dragType = DragType.MoveY;
  24. else dragType = holdShift ? DragType.RotY : DragType.MoveXZ;
  25. }
  26. else if (Input.GetKey(KeyCode.X))
  27. {
  28. dragType = holdShift ? DragType.RotLocalY : DragType.RotLocalXZ;
  29. }
  30. else if (Input.GetKey(KeyCode.C))
  31. {
  32. dragType = DragType.Scale;
  33. }
  34. else
  35. {
  36. dragType = DragType.None;
  37. }
  38. }
  39. protected override void InitializeDrag()
  40. {
  41. if (dragType == DragType.Select)
  42. {
  43. Select?.Invoke(this, EventArgs.Empty);
  44. return;
  45. }
  46. base.InitializeDrag();
  47. maidScale = maid.transform.localScale.x;
  48. maidRot = maid.transform.localEulerAngles;
  49. off = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z));
  50. off2 = new Vector3(
  51. transform.position.x - maid.transform.position.x,
  52. transform.position.y - maid.transform.position.y,
  53. transform.position.z - maid.transform.position.z);
  54. }
  55. protected override void DoubleClick()
  56. {
  57. if (dragType == DragType.Scale) maid.transform.localScale = new Vector3(1f, 1f, 1f);
  58. if (dragType == DragType.RotLocalY || dragType == DragType.RotLocalXZ)
  59. maid.transform.eulerAngles = new Vector3(0f, maid.transform.eulerAngles.y, 0f);
  60. }
  61. protected override void Drag()
  62. {
  63. Vector3 pos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z)) + off - off2;
  64. if (dragType == DragType.MoveXZ)
  65. {
  66. maid.transform.position = new Vector3(pos.x, maid.transform.position.y, pos.z);
  67. }
  68. if (dragType == DragType.MoveY)
  69. {
  70. maid.transform.position = new Vector3(maid.transform.position.x, pos.y, maid.transform.position.z);
  71. }
  72. if (dragType == DragType.RotY)
  73. {
  74. Vector3 posOther = Input.mousePosition - mousePos;
  75. maid.transform.eulerAngles =
  76. new Vector3(maid.transform.eulerAngles.x, maidRot.y - posOther.x / 3f, maid.transform.eulerAngles.z);
  77. }
  78. if (dragType == DragType.RotLocalXZ)
  79. {
  80. Vector3 posOther = Input.mousePosition - mousePos;
  81. Transform transform = Camera.main.transform;
  82. Vector3 vector3_3 = transform.TransformDirection(Vector3.right);
  83. Vector3 vector3_4 = transform.TransformDirection(Vector3.forward);
  84. transform.TransformDirection(Vector3.forward);
  85. if (mousePos2 != Input.mousePosition)
  86. {
  87. maid.transform.localEulerAngles = maidRot;
  88. maid.transform.RotateAround(maid.transform.position, new Vector3(vector3_3.x, 0.0f, vector3_3.z), posOther.y / 4f);
  89. maid.transform.RotateAround(maid.transform.position, new Vector3(vector3_4.x, 0.0f, vector3_4.z), (-posOther.x / 6.0f));
  90. }
  91. mousePos2 = Input.mousePosition;
  92. }
  93. if (dragType == DragType.RotLocalY)
  94. {
  95. Vector3 posOther = Input.mousePosition - mousePos;
  96. Transform transform = Camera.main.transform;
  97. Vector3 vector3_3 = transform.TransformDirection(Vector3.right);
  98. transform.TransformDirection(Vector3.forward);
  99. if (mousePos2 != Input.mousePosition)
  100. {
  101. maid.transform.localEulerAngles = maidRot;
  102. maid.body0.transform.localRotation = Quaternion.Euler(maid.transform.localEulerAngles)
  103. * Quaternion.AngleAxis((-posOther.x / 2.2f), Vector3.up);
  104. }
  105. mousePos2 = Input.mousePosition;
  106. }
  107. if (dragType == DragType.Scale)
  108. {
  109. Vector3 posOther = Input.mousePosition - mousePos;
  110. float scale = maidScale + posOther.y / 200f;
  111. if (scale < 0.1f) scale = 0.1f;
  112. maid.transform.localScale = new Vector3(scale, scale, scale);
  113. }
  114. }
  115. }
  116. }