MouseDrag3.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. using UnityEngine;
  2. public class MouseDrag3 : MonoBehaviour
  3. {
  4. public Transform head;
  5. public int ido;
  6. public bool isClick;
  7. public bool isClick2;
  8. public bool isHead;
  9. public bool isIdo;
  10. public bool isPlay;
  11. public bool isSelect;
  12. public bool isStop;
  13. public Maid maid;
  14. public int no;
  15. public GameObject obj;
  16. public Transform Pelvis;
  17. public bool reset;
  18. public bool shodaiFlg = false;
  19. public Transform Spine;
  20. public Transform Spine0a;
  21. public Transform Spine1;
  22. public Transform Spine1a;
  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 pos3;
  30. private Quaternion quaL;
  31. private Quaternion quaR;
  32. private Vector3 rotate;
  33. private Vector3 rotate1;
  34. private Vector3 rotate2;
  35. private Vector3 rotate3;
  36. private Vector3 rotate4;
  37. private Vector3 rotate5;
  38. private Vector3 rotateL;
  39. private Vector3 rotateR;
  40. private Vector3 worldPoint;
  41. public void Update()
  42. {
  43. doubleTapTime += Time.deltaTime;
  44. }
  45. public void OnMouseDown()
  46. {
  47. if (maid == null)
  48. return;
  49. worldPoint = Camera.main.WorldToScreenPoint(transform.position);
  50. mouseIti = Input.mousePosition;
  51. if (ido == 1 || ido == 4 || ido == 8)
  52. rotate = head.localEulerAngles;
  53. if (ido == 2 || ido == 5)
  54. {
  55. rotate1 = Spine1a.localEulerAngles;
  56. rotate2 = Spine1.localEulerAngles;
  57. rotate3 = Spine0a.localEulerAngles;
  58. rotate4 = Spine.localEulerAngles;
  59. }
  60. if (ido == 3 || ido == 6)
  61. rotate5 = Pelvis.localEulerAngles;
  62. if (ido == 7)
  63. {
  64. rotateR = maid.body0.quaDefEyeR.eulerAngles;
  65. rotateL = maid.body0.quaDefEyeL.eulerAngles;
  66. quaL = maid.body0.quaDefEyeL;
  67. quaR = maid.body0.quaDefEyeR;
  68. }
  69. if (ido == 9)
  70. {
  71. worldPoint = Camera.main.WorldToScreenPoint(transform.position);
  72. off = transform.position
  73. - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z));
  74. off2 = new Vector3(obj.transform.position.x - head.position.x,
  75. obj.transform.position.y - head.position.y,
  76. obj.transform.position.z - head.position.z);
  77. mouseIti = Input.mousePosition;
  78. }
  79. isSelect = true;
  80. isPlay = maid.body0.m_Bones.GetComponent<Animation>().isPlaying;
  81. if (!isPlay)
  82. isStop = true;
  83. if (doubleTapTime < 0.300000011920929 && isClick2 && ido == idoOld)
  84. isHead = true;
  85. if (doubleTapTime >= 0.300000011920929 && isClick)
  86. isClick = false;
  87. if (doubleTapTime >= 0.300000011920929 && isClick2)
  88. isClick2 = false;
  89. doubleTapTime = 0.0f;
  90. pos3 = Input.mousePosition - mouseIti;
  91. }
  92. public void OnMouseUp()
  93. {
  94. if (maid == null || doubleTapTime >= 0.300000011920929)
  95. return;
  96. if (ido == 7)
  97. isClick = true;
  98. isClick2 = true;
  99. doubleTapTime = 0.0f;
  100. idoOld = ido;
  101. }
  102. public void OnMouseDrag()
  103. {
  104. if (maid == null)
  105. return;
  106. if (isPlay && mouseIti != Input.mousePosition)
  107. {
  108. maid.body0.m_Bones.GetComponent<Animation>().Stop();
  109. isStop = true;
  110. isPlay = false;
  111. }
  112. if (reset)
  113. {
  114. reset = false;
  115. worldPoint = Camera.main.WorldToScreenPoint(transform.position);
  116. if (ido == 1 || ido == 4 || ido == 8)
  117. rotate = head.localEulerAngles;
  118. if (ido == 2 || ido == 5)
  119. {
  120. rotate1 = Spine1a.localEulerAngles;
  121. rotate2 = Spine1.localEulerAngles;
  122. rotate3 = Spine0a.localEulerAngles;
  123. rotate4 = Spine.localEulerAngles;
  124. }
  125. if (ido == 3 || ido == 6)
  126. rotate5 = Pelvis.localEulerAngles;
  127. if (ido == 7)
  128. {
  129. rotateR = maid.body0.quaDefEyeR.eulerAngles;
  130. rotateL = maid.body0.quaDefEyeL.eulerAngles;
  131. quaL = maid.body0.quaDefEyeL;
  132. quaR = maid.body0.quaDefEyeR;
  133. }
  134. mouseIti = Input.mousePosition;
  135. if (ido == 9)
  136. {
  137. worldPoint = Camera.main.WorldToScreenPoint(transform.position);
  138. off = transform.position
  139. - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z));
  140. off2 = new Vector3(obj.transform.position.x - head.position.x,
  141. obj.transform.position.y - head.position.y,
  142. obj.transform.position.z - head.position.z);
  143. mouseIti = Input.mousePosition;
  144. }
  145. }
  146. if (mouseIti != Input.mousePosition)
  147. {
  148. var position = new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z);
  149. Vector3 vector3_1 = Input.mousePosition - mouseIti;
  150. Transform transform = GameMain.Instance.MainCamera.gameObject.transform;
  151. Vector3 vector3_2 = transform.TransformDirection(Vector3.right);
  152. Vector3 vector3_3 = transform.TransformDirection(Vector3.forward);
  153. if (mouseIti2 != Input.mousePosition)
  154. {
  155. if (ido == 1)
  156. {
  157. isIdo = true;
  158. head.localEulerAngles = rotate;
  159. head.RotateAround(head.position, new Vector3(vector3_2.x, 0.0f, vector3_2.z), vector3_1.y / 3f);
  160. head.RotateAround(head.position, new Vector3(vector3_3.x, 0.0f, vector3_3.z), (float) (-(double) vector3_1.x / 4.5));
  161. }
  162. if (ido == 4)
  163. {
  164. isIdo = true;
  165. head.localEulerAngles = rotate;
  166. head.localRotation = Quaternion.Euler(head.localEulerAngles) * Quaternion.AngleAxis(vector3_1.x / 3f, Vector3.right);
  167. }
  168. if (ido == 8)
  169. {
  170. isIdo = true;
  171. head.localEulerAngles = rotate;
  172. head.localRotation = Quaternion.Euler(head.localEulerAngles)
  173. * Quaternion.AngleAxis((float) (-(double) vector3_1.x / 3.0), Vector3.forward);
  174. }
  175. if (ido == 9)
  176. head.transform.position = new Vector3(head.transform.position.x,
  177. (Camera.main.ScreenToWorldPoint(position) + off - off2).y,
  178. head.transform.position.z);
  179. if (ido == 2)
  180. {
  181. Spine1a.localEulerAngles = rotate1;
  182. Spine1.localEulerAngles = rotate2;
  183. Spine0a.localEulerAngles = rotate3;
  184. Spine.localEulerAngles = rotate4;
  185. float num1 = 1.5f;
  186. float num2 = 1f;
  187. float num3 = 0.03f;
  188. float num4 = 0.1f;
  189. float num5 = 0.09f;
  190. float num6 = 0.07f;
  191. Spine1a.RotateAround(Spine1a.position, new Vector3(vector3_2.x, 0.0f, vector3_2.z), vector3_1.y / num2 * num3);
  192. Spine1a.RotateAround(Spine1a.position, new Vector3(vector3_3.x, 0.0f, vector3_3.z), -vector3_1.x / num1 * num3);
  193. Spine1.RotateAround(Spine1.position, new Vector3(vector3_2.x, 0.0f, vector3_2.z), vector3_1.y / num2 * num4);
  194. Spine1.RotateAround(Spine1.position, new Vector3(vector3_3.x, 0.0f, vector3_3.z), -vector3_1.x / num1 * num4);
  195. Spine0a.RotateAround(Spine0a.position, new Vector3(vector3_2.x, 0.0f, vector3_2.z), vector3_1.y / num2 * num5);
  196. Spine0a.RotateAround(Spine0a.position, new Vector3(vector3_3.x, 0.0f, vector3_3.z), -vector3_1.x / num1 * num5);
  197. Spine.RotateAround(Spine.position, new Vector3(vector3_2.x, 0.0f, vector3_2.z), vector3_1.y / num2 * num6);
  198. Spine.RotateAround(Spine.position, new Vector3(vector3_3.x, 0.0f, vector3_3.z), -vector3_1.x / num1 * num6);
  199. }
  200. if (ido == 5)
  201. {
  202. Spine1a.localEulerAngles = rotate1;
  203. Spine1.localEulerAngles = rotate2;
  204. Spine0a.localEulerAngles = rotate3;
  205. Spine.localEulerAngles = rotate4;
  206. Spine1a.localRotation = Quaternion.Euler(Spine1a.localEulerAngles)
  207. * Quaternion.AngleAxis((float) (vector3_1.x / 1.5 * 0.0839999988675117), Vector3.right);
  208. Spine0a.localRotation = Quaternion.Euler(Spine0a.localEulerAngles)
  209. * Quaternion.AngleAxis((float) (vector3_1.x / 1.5 * 0.156000003218651), Vector3.right);
  210. Spine.localRotation = Quaternion.Euler(Spine.localEulerAngles)
  211. * Quaternion.AngleAxis((float) (vector3_1.x / 1.5 * 0.156000003218651), Vector3.right);
  212. }
  213. if (ido == 3)
  214. {
  215. Pelvis.localEulerAngles = rotate5;
  216. Pelvis.RotateAround(Pelvis.position, new Vector3(vector3_2.x, 0.0f, vector3_2.z), vector3_1.y / 4f);
  217. Pelvis.RotateAround(Pelvis.position, new Vector3(vector3_3.x, 0.0f, vector3_3.z), vector3_1.x / 6f);
  218. }
  219. if (ido == 6)
  220. {
  221. Pelvis.localEulerAngles = rotate5;
  222. Pelvis.localRotation =
  223. Quaternion.Euler(Pelvis.localEulerAngles) * Quaternion.AngleAxis(vector3_1.x / 3f, Vector3.right);
  224. }
  225. if (ido == 7)
  226. {
  227. var vector3_4 = new Vector3(rotateR.x, rotateR.y + vector3_1.x / 10f, rotateR.z + vector3_1.y / 10f);
  228. if (shodaiFlg)
  229. {
  230. if (vector3_4.z < 345.700012207031 && vector3_4.z > 335.700012207031)
  231. pos3.y = vector3_1.y;
  232. if (vector3_4.y < 347.600006103516 && vector3_4.y > 335.600006103516)
  233. pos3.x = vector3_1.x;
  234. }
  235. else
  236. {
  237. if (vector3_4.z < 354.799987792969 && vector3_4.z > 344.799987792969)
  238. pos3.y = vector3_1.y;
  239. if (vector3_4.y < 354.0 && vector3_4.y > 342.0)
  240. pos3.x = vector3_1.x;
  241. }
  242. maid.body0.quaDefEyeR.eulerAngles = new Vector3(rotateR.x, rotateR.y + pos3.x / 10f, rotateR.z + pos3.y / 10f);
  243. maid.body0.quaDefEyeL.eulerAngles = new Vector3(rotateL.x, rotateL.y - pos3.x / 10f, rotateL.z - pos3.y / 10f);
  244. }
  245. }
  246. mouseIti2 = Input.mousePosition;
  247. }
  248. }
  249. }