DragBody.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. EventHandler handler = Select;
  44. if (handler != null) handler(this, EventArgs.Empty);
  45. return;
  46. }
  47. base.InitializeDrag();
  48. maidScale = maid.transform.localScale.x;
  49. maidRot = maid.transform.localEulerAngles;
  50. off = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z));
  51. off2 = new Vector3(
  52. transform.position.x - maid.transform.position.x,
  53. transform.position.y - maid.transform.position.y,
  54. transform.position.z - maid.transform.position.z);
  55. }
  56. protected override void DoubleClick()
  57. {
  58. if (dragType == DragType.Scale) maid.transform.localScale = new Vector3(1f, 1f, 1f);
  59. if (dragType == DragType.RotLocalY || dragType == DragType.RotLocalXZ)
  60. maid.transform.eulerAngles = new Vector3(0f, maid.transform.eulerAngles.y, 0f);
  61. }
  62. protected override void Drag()
  63. {
  64. Vector3 pos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z)) + off - off2;
  65. if (dragType == DragType.MoveXZ)
  66. {
  67. maid.transform.position = new Vector3(pos.x, maid.transform.position.y, pos.z);
  68. }
  69. if (dragType == DragType.MoveY)
  70. {
  71. maid.transform.position = new Vector3(maid.transform.position.x, pos.y, maid.transform.position.z);
  72. }
  73. if (dragType == DragType.RotY)
  74. {
  75. Vector3 posOther = Input.mousePosition - mousePos;
  76. maid.transform.eulerAngles =
  77. new Vector3(maid.transform.eulerAngles.x, maidRot.y - posOther.x / 3f, maid.transform.eulerAngles.z);
  78. }
  79. if (dragType == DragType.RotLocalXZ)
  80. {
  81. Vector3 posOther = Input.mousePosition - mousePos;
  82. Transform transform = Camera.main.transform;
  83. Vector3 vector3_3 = transform.TransformDirection(Vector3.right);
  84. Vector3 vector3_4 = transform.TransformDirection(Vector3.forward);
  85. transform.TransformDirection(Vector3.forward);
  86. if (mousePos2 != Input.mousePosition)
  87. {
  88. maid.transform.localEulerAngles = maidRot;
  89. maid.transform.RotateAround(maid.transform.position, new Vector3(vector3_3.x, 0.0f, vector3_3.z), posOther.y / 4f);
  90. maid.transform.RotateAround(maid.transform.position, new Vector3(vector3_4.x, 0.0f, vector3_4.z), (-posOther.x / 6.0f));
  91. }
  92. mousePos2 = Input.mousePosition;
  93. }
  94. if (dragType == DragType.RotLocalY)
  95. {
  96. Vector3 posOther = Input.mousePosition - mousePos;
  97. Transform transform = Camera.main.transform;
  98. Vector3 vector3_3 = transform.TransformDirection(Vector3.right);
  99. transform.TransformDirection(Vector3.forward);
  100. if (mousePos2 != Input.mousePosition)
  101. {
  102. maid.transform.localEulerAngles = maidRot;
  103. maid.body0.transform.localRotation = Quaternion.Euler(maid.transform.localEulerAngles)
  104. * Quaternion.AngleAxis((-posOther.x / 2.2f), Vector3.up);
  105. }
  106. mousePos2 = Input.mousePosition;
  107. }
  108. if (dragType == DragType.Scale)
  109. {
  110. Vector3 posOther = Input.mousePosition - mousePos;
  111. float scale = maidScale + posOther.y / 200f;
  112. if (scale < 0.1f) scale = 0.1f;
  113. maid.transform.localScale = new Vector3(scale, scale, scale);
  114. }
  115. }
  116. }
  117. }