1
0

MouseDrag6.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. public class MouseDrag6 : MonoBehaviour
  4. {
  5. public Vector3 angles;
  6. public int count;
  7. public bool del;
  8. public int ido;
  9. public bool isAlt;
  10. public bool isClick;
  11. public bool isIdo;
  12. public bool isOn;
  13. public bool isScale = false;
  14. public bool isScale2 = false;
  15. public bool isSelect;
  16. public GameObject maid = null;
  17. public GameObject[] maidArray = null;
  18. public MouseDrag6[] mArray = null;
  19. public GameObject obj;
  20. public bool reset;
  21. public Vector3 scale;
  22. public Vector3 scale2;
  23. private float doubleTapTime;
  24. private int idoOld;
  25. private Vector3 mouseIti;
  26. private Vector3 mouseIti2;
  27. private Vector3 off;
  28. private Vector3 off2;
  29. private Vector3 rotate;
  30. private float size;
  31. private Vector3 worldPoint;
  32. private List<float> xList = new List<float>();
  33. private List<float> yList = new List<float>();
  34. private List<float> zList = new List<float>();
  35. public void Update()
  36. {
  37. doubleTapTime += Time.deltaTime;
  38. }
  39. public void OnMouseDown()
  40. {
  41. if (!(maid != null))
  42. return;
  43. worldPoint = Camera.main.WorldToScreenPoint(transform.position);
  44. off = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z));
  45. off2 = new Vector3(obj.transform.position.x - maid.transform.position.x,
  46. obj.transform.position.y - maid.transform.position.y,
  47. obj.transform.position.z - maid.transform.position.z);
  48. mouseIti = Input.mousePosition;
  49. if (doubleTapTime < 0.300000011920929 && isClick && ido == idoOld)
  50. {
  51. if (ido == 5)
  52. maid.transform.localScale = !isScale2 ? new Vector3(1f, 1f, 1f) : scale2;
  53. if (ido == 4 || ido == 6)
  54. maid.transform.eulerAngles = new Vector3(angles.x, maid.transform.eulerAngles.y, angles.z);
  55. }
  56. if (doubleTapTime >= 0.300000011920929 && isClick)
  57. isClick = false;
  58. doubleTapTime = 0.0f;
  59. rotate = maid.transform.localEulerAngles;
  60. size = maid.transform.localScale.x;
  61. isSelect = true;
  62. isOn = true;
  63. if (Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt))
  64. isAlt = !isAlt;
  65. xList = new List<float>();
  66. yList = new List<float>();
  67. zList = new List<float>();
  68. if (maidArray != null)
  69. for (int index = 0; index < maidArray.Length; ++index)
  70. {
  71. xList.Add(maid.transform.position.x - maidArray[index].transform.position.x);
  72. yList.Add(maid.transform.position.y - maidArray[index].transform.position.y);
  73. zList.Add(maid.transform.position.z - maidArray[index].transform.position.z);
  74. }
  75. }
  76. public void OnMouseUp()
  77. {
  78. if (!(maid != null))
  79. return;
  80. isOn = false;
  81. if (doubleTapTime < 0.300000011920929)
  82. {
  83. isClick = true;
  84. doubleTapTime = 0.0f;
  85. idoOld = ido;
  86. }
  87. if (ido == 7)
  88. del = true;
  89. }
  90. public void OnMouseDrag()
  91. {
  92. if (!(maid != null))
  93. return;
  94. if (reset)
  95. {
  96. reset = false;
  97. worldPoint = Camera.main.WorldToScreenPoint(transform.position);
  98. off = transform.position
  99. - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z));
  100. off2 = new Vector3(obj.transform.position.x - maid.transform.position.x,
  101. obj.transform.position.y - maid.transform.position.y,
  102. obj.transform.position.z - maid.transform.position.z);
  103. rotate = maid.transform.localEulerAngles;
  104. size = maid.transform.localScale.x;
  105. mouseIti = Input.mousePosition;
  106. }
  107. if (mouseIti != Input.mousePosition)
  108. {
  109. Vector3 vector3_1 = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z))
  110. + off - off2;
  111. isIdo = false;
  112. if (ido == 1)
  113. {
  114. maid.transform.position = new Vector3(vector3_1.x, maid.transform.position.y, vector3_1.z);
  115. if (maidArray != null)
  116. for (int index = 0; index < maidArray.Length; ++index)
  117. if (mArray[index].isAlt)
  118. maidArray[index].transform.position = new Vector3(vector3_1.x - xList[index],
  119. maidArray[index].transform.position.y,
  120. vector3_1.z - zList[index]);
  121. isIdo = true;
  122. }
  123. if (ido == 2)
  124. {
  125. maid.transform.position = new Vector3(maid.transform.position.x, vector3_1.y, maid.transform.position.z);
  126. if (maidArray != null)
  127. for (int index = 0; index < maidArray.Length; ++index)
  128. if (mArray[index].isAlt)
  129. maidArray[index].transform.position = new Vector3(maidArray[index].transform.position.x,
  130. vector3_1.y - yList[index],
  131. maidArray[index].transform.position.z);
  132. isIdo = true;
  133. }
  134. Vector3 vector3_2;
  135. if (ido == 3)
  136. {
  137. vector3_2 = Input.mousePosition - mouseIti;
  138. maid.transform.eulerAngles =
  139. new Vector3(maid.transform.eulerAngles.x, rotate.y - vector3_2.x / 2.2f, maid.transform.eulerAngles.z);
  140. }
  141. Vector3 vector3_3;
  142. if (ido == 4)
  143. {
  144. vector3_2 = Input.mousePosition - mouseIti;
  145. Transform transform = GameMain.Instance.MainCamera.gameObject.transform;
  146. vector3_3 = transform.TransformDirection(Vector3.right);
  147. Vector3 vector3_4 = transform.TransformDirection(Vector3.forward);
  148. if (mouseIti2 != Input.mousePosition)
  149. {
  150. maid.transform.localEulerAngles = rotate;
  151. maid.transform.RotateAround(maid.transform.position, new Vector3(vector3_3.x, 0.0f, vector3_3.z), vector3_2.y / 4f);
  152. maid.transform.RotateAround(maid.transform.position,
  153. new Vector3(vector3_4.x, 0.0f, vector3_4.z),
  154. (float) (-(double) vector3_2.x / 6.0));
  155. }
  156. isIdo = true;
  157. mouseIti2 = Input.mousePosition;
  158. }
  159. if (ido == 6)
  160. {
  161. vector3_2 = Input.mousePosition - mouseIti;
  162. Transform transform = GameMain.Instance.MainCamera.gameObject.transform;
  163. vector3_3 = transform.TransformDirection(Vector3.right);
  164. transform.TransformDirection(Vector3.forward);
  165. if (mouseIti2 != Input.mousePosition)
  166. {
  167. maid.transform.localEulerAngles = rotate;
  168. maid.transform.localRotation = Quaternion.Euler(maid.transform.localEulerAngles)
  169. * Quaternion.AngleAxis((float) (-(double) vector3_2.x / 2.20000004768372), Vector3.up);
  170. }
  171. isIdo = true;
  172. mouseIti2 = Input.mousePosition;
  173. }
  174. if (ido == 5)
  175. {
  176. vector3_2 = Input.mousePosition - mouseIti;
  177. float num = size + vector3_2.y / 200f;
  178. if (num < 0.00999999977648258)
  179. num = 0.01f;
  180. maid.transform.localScale =
  181. !isScale ? new Vector3(num, num, num) : new Vector3(scale.x * num, scale.y * num, scale.z * num);
  182. }
  183. if (ido == 15)
  184. {
  185. vector3_2 = Input.mousePosition - mouseIti;
  186. float num = size + vector3_2.y / 2f;
  187. if (num < 0.00999999977648258)
  188. num = 0.01f;
  189. if (num > 150.0)
  190. num = 150f;
  191. maid.transform.localScale = new Vector3(num, num, num);
  192. }
  193. }
  194. }
  195. }