1
0

MouseDrag2.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. using UnityEngine;
  2. public class MouseDrag2 : MonoBehaviour
  3. {
  4. public int ido;
  5. public bool isClick;
  6. public bool isIdo;
  7. public bool isOn;
  8. public bool isSelect;
  9. public Maid maid = null;
  10. public GameObject obj;
  11. public bool reset;
  12. private float doubleTapTime;
  13. private int idoOld;
  14. private Vector3 mouseIti;
  15. private Vector3 mouseIti2;
  16. private Vector3 off;
  17. private Vector3 off2;
  18. private Vector3 rotate;
  19. private float size;
  20. private Vector3 worldPoint;
  21. public void Update()
  22. {
  23. doubleTapTime += Time.deltaTime;
  24. }
  25. public void OnMouseDown()
  26. {
  27. if (!(maid != null))
  28. return;
  29. worldPoint = Camera.main.WorldToScreenPoint(transform.position);
  30. off = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z));
  31. off2 = new Vector3(obj.transform.position.x - maid.transform.position.x,
  32. obj.transform.position.y - maid.transform.position.y,
  33. obj.transform.position.z - maid.transform.position.z);
  34. mouseIti = Input.mousePosition;
  35. if (doubleTapTime < 0.300000011920929 && isClick && ido == idoOld)
  36. {
  37. if (ido == 5)
  38. maid.transform.localScale = new Vector3(1f, 1f, 1f);
  39. if (ido == 4 || ido == 6)
  40. maid.transform.eulerAngles = new Vector3(0.0f, maid.transform.eulerAngles.y, 0.0f);
  41. }
  42. if (doubleTapTime >= 0.300000011920929 && isClick)
  43. isClick = false;
  44. doubleTapTime = 0.0f;
  45. rotate = maid.transform.localEulerAngles;
  46. size = maid.transform.localScale.x;
  47. isSelect = true;
  48. isOn = true;
  49. }
  50. public void OnMouseUp()
  51. {
  52. if (maid != null)
  53. isOn = false;
  54. if (doubleTapTime >= 0.300000011920929)
  55. return;
  56. isClick = true;
  57. doubleTapTime = 0.0f;
  58. idoOld = ido;
  59. }
  60. public void OnMouseDrag()
  61. {
  62. if (!(maid != null))
  63. return;
  64. if (reset)
  65. {
  66. reset = false;
  67. worldPoint = Camera.main.WorldToScreenPoint(transform.position);
  68. off = transform.position
  69. - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z));
  70. off2 = new Vector3(obj.transform.position.x - maid.transform.position.x,
  71. obj.transform.position.y - maid.transform.position.y,
  72. obj.transform.position.z - maid.transform.position.z);
  73. rotate = maid.transform.localEulerAngles;
  74. size = maid.transform.localScale.x;
  75. mouseIti = Input.mousePosition;
  76. }
  77. if (mouseIti != Input.mousePosition)
  78. {
  79. Vector3 vector3_1 = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z))
  80. + off - off2;
  81. isIdo = false;
  82. if (ido == 1)
  83. {
  84. maid.transform.position = new Vector3(vector3_1.x, maid.transform.position.y, vector3_1.z);
  85. isIdo = true;
  86. }
  87. if (ido == 2)
  88. {
  89. maid.transform.position = new Vector3(maid.transform.position.x, vector3_1.y, maid.transform.position.z);
  90. isIdo = true;
  91. }
  92. Vector3 vector3_2;
  93. if (ido == 3)
  94. {
  95. vector3_2 = Input.mousePosition - mouseIti;
  96. maid.transform.eulerAngles =
  97. new Vector3(maid.transform.eulerAngles.x, rotate.y - vector3_2.x / 2.2f, maid.transform.eulerAngles.z);
  98. }
  99. Vector3 vector3_3;
  100. if (ido == 4)
  101. {
  102. vector3_2 = Input.mousePosition - mouseIti;
  103. Transform transform = GameMain.Instance.MainCamera.gameObject.transform;
  104. vector3_3 = transform.TransformDirection(Vector3.right);
  105. Vector3 vector3_4 = transform.TransformDirection(Vector3.forward);
  106. if (mouseIti2 != Input.mousePosition)
  107. {
  108. maid.transform.localEulerAngles = rotate;
  109. maid.transform.RotateAround(maid.transform.position, new Vector3(vector3_3.x, 0.0f, vector3_3.z), vector3_2.y / 4f);
  110. maid.transform.RotateAround(maid.transform.position,
  111. new Vector3(vector3_4.x, 0.0f, vector3_4.z),
  112. (float) (-(double) vector3_2.x / 6.0));
  113. }
  114. isIdo = true;
  115. mouseIti2 = Input.mousePosition;
  116. }
  117. if (ido == 6)
  118. {
  119. vector3_2 = Input.mousePosition - mouseIti;
  120. Transform transform = GameMain.Instance.MainCamera.gameObject.transform;
  121. vector3_3 = transform.TransformDirection(Vector3.right);
  122. transform.TransformDirection(Vector3.forward);
  123. if (mouseIti2 != Input.mousePosition)
  124. {
  125. maid.transform.localEulerAngles = rotate;
  126. maid.body0.transform.localRotation = Quaternion.Euler(maid.body0.transform.localEulerAngles)
  127. * Quaternion.AngleAxis((float) (-(double) vector3_2.x / 2.20000004768372),
  128. Vector3.up);
  129. }
  130. isIdo = true;
  131. mouseIti2 = Input.mousePosition;
  132. }
  133. if (ido == 5)
  134. {
  135. vector3_2 = Input.mousePosition - mouseIti;
  136. float num = size + vector3_2.y / 200f;
  137. if (num < 0.100000001490116)
  138. num = 0.1f;
  139. maid.transform.localScale = new Vector3(num, num, num);
  140. }
  141. }
  142. }
  143. }