1
0

MouseDrag.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. using UnityEngine;
  2. public class MouseDrag : MonoBehaviour
  3. {
  4. public Transform ForearmL;
  5. public Transform HandL;
  6. public Vector3 HandLangles;
  7. public int ido;
  8. public bool initFlg;
  9. public bool initFlg2;
  10. public bool isIdo;
  11. public bool isMouseDown;
  12. public bool isMouseDrag;
  13. public bool isMouseUp;
  14. public bool isPlay;
  15. public bool isSelect;
  16. public bool isStop;
  17. public Maid maid;
  18. public GameObject obj;
  19. public Vector3 off;
  20. public Vector3 off2;
  21. public bool onFlg;
  22. public bool onFlg2;
  23. public bool reset;
  24. public float shoki = -1000f;
  25. public Transform UpperArmL;
  26. public Vector3 UpperArmLangles;
  27. private readonly GameObject ForearmL2 = new GameObject();
  28. private readonly GameObject HandL2 = new GameObject();
  29. private readonly TBody.IKCMO IK = new TBody.IKCMO();
  30. private Vector3 mouseIti;
  31. private Vector3 mouseIti2;
  32. private Vector3 rotate;
  33. private Vector3 rotate2;
  34. private readonly GameObject UpperArmL2 = new GameObject();
  35. private Vector3 worldPoint;
  36. public void OnMouseDown()
  37. {
  38. if (!(maid != null))
  39. return;
  40. IKCtrlData ikData = maid.body0.IKCtrl.GetIKData("左手", false);
  41. worldPoint = Camera.main.WorldToScreenPoint(transform.position);
  42. off = transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z));
  43. off2 = new Vector3(obj.transform.position.x - HandL.position.x,
  44. obj.transform.position.y - HandL.position.y,
  45. obj.transform.position.z - HandL.position.z);
  46. if (!initFlg)
  47. {
  48. IK.Init(UpperArmL, ForearmL, HandL, maid.body0);
  49. initFlg = true;
  50. if (!initFlg2)
  51. {
  52. initFlg2 = true;
  53. HandL2.transform.position = HandL.position;
  54. UpperArmL2.transform.position = UpperArmL.position;
  55. ForearmL2.transform.position = ForearmL.position;
  56. HandL2.transform.localRotation = HandL.localRotation;
  57. UpperArmL2.transform.localRotation = UpperArmL.localRotation;
  58. ForearmL2.transform.localRotation = ForearmL.localRotation;
  59. }
  60. }
  61. if (onFlg)
  62. {
  63. onFlg2 = true;
  64. IK.Init(UpperArmL, ForearmL, HandL, maid.body0);
  65. }
  66. mouseIti = Input.mousePosition;
  67. isPlay = maid.body0.m_Bones.GetComponent<Animation>().isPlaying;
  68. isSelect = true;
  69. rotate = HandL.localEulerAngles;
  70. rotate2 = UpperArmL.localEulerAngles;
  71. isMouseUp = false;
  72. isMouseDown = true;
  73. if (ido == 10)
  74. {
  75. Vector3 tgt = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z)) + off
  76. - off2;
  77. IK.Init(UpperArmL2.transform, ForearmL2.transform, HandL2.transform, maid.body0);
  78. for (int index = 0; index < 10; ++index)
  79. {
  80. IK.Porc(UpperArmL, ForearmL, HandL, tgt, new Vector3(), ikData);
  81. IK.Porc(UpperArmL, ForearmL, HandL, tgt + (tgt - HandL.position), new Vector3(), ikData);
  82. }
  83. }
  84. if (shoki != -1000.0)
  85. return;
  86. shoki = UpperArmL.localEulerAngles.x;
  87. if (shoki <= 300.0)
  88. return;
  89. shoki -= 360f;
  90. }
  91. public void OnMouseUp()
  92. {
  93. isMouseUp = true;
  94. isMouseDown = false;
  95. }
  96. public void OnMouseDrag()
  97. {
  98. if (!(maid != null))
  99. return;
  100. if (isPlay && mouseIti != Input.mousePosition)
  101. {
  102. maid.body0.m_Bones.GetComponent<Animation>().Stop();
  103. isStop = true;
  104. isPlay = false;
  105. }
  106. if (reset)
  107. {
  108. reset = false;
  109. worldPoint = Camera.main.WorldToScreenPoint(transform.position);
  110. off = transform.position
  111. - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z));
  112. off2 = new Vector3(obj.transform.position.x - HandL.position.x,
  113. obj.transform.position.y - HandL.position.y,
  114. obj.transform.position.z - HandL.position.z);
  115. rotate = HandL.localEulerAngles;
  116. rotate2 = UpperArmL.localEulerAngles;
  117. mouseIti = Input.mousePosition;
  118. if (onFlg)
  119. IK.Init(UpperArmL, ForearmL, HandL, maid.body0);
  120. }
  121. if (mouseIti != Input.mousePosition)
  122. {
  123. Vector3 tgt = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, worldPoint.z)) + off
  124. - off2;
  125. IKCtrlData ikData = maid.body0.IKCtrl.GetIKData("左手", false);
  126. isMouseDrag = true;
  127. if (!isPlay)
  128. isStop = true;
  129. isIdo = false;
  130. if (ido == 0)
  131. {
  132. isIdo = true;
  133. IK.Porc(UpperArmL, ForearmL, HandL, tgt, new Vector3(), ikData);
  134. if (!onFlg)
  135. IK.Porc(UpperArmL, ForearmL, HandL, tgt + (tgt - HandL.position), new Vector3(), ikData);
  136. HandLangles = new Vector3(HandL.localEulerAngles.x, HandL.localEulerAngles.y, HandL.localEulerAngles.z);
  137. UpperArmLangles = new Vector3(UpperArmL.localEulerAngles.x, UpperArmL.localEulerAngles.y, UpperArmL.localEulerAngles.z);
  138. }
  139. else if (ido == 11)
  140. {
  141. IK.Porc(UpperArmL, ForearmL, HandL, tgt, new Vector3(), ikData);
  142. if (!onFlg)
  143. IK.Porc(UpperArmL, ForearmL, HandL, tgt + (tgt - HandL.position), new Vector3(), ikData);
  144. float x = UpperArmL.localEulerAngles.x;
  145. if (x > 250.0 + shoki && x < 352.0 + shoki)
  146. x = 352f + shoki;
  147. if (x < 100.0 + shoki && x > 8.0 + shoki)
  148. x = 8f + shoki;
  149. float z = UpperArmL.localEulerAngles.z;
  150. if (z > 140.0 && z < 240.0)
  151. z = 240f;
  152. if (z <= 140.0 && z > 7.0)
  153. z = 7f;
  154. HandL.localEulerAngles = new Vector3(rotate.x, rotate.y, HandL.localEulerAngles.z);
  155. UpperArmL.localEulerAngles = new Vector3(x, rotate2.y, z);
  156. }
  157. else if (ido == 12)
  158. {
  159. IK.Porc(UpperArmL, ForearmL, HandL, tgt, new Vector3(), ikData);
  160. if (!onFlg)
  161. IK.Porc(UpperArmL, ForearmL, HandL, tgt + (tgt - HandL.position), new Vector3(), ikData);
  162. float x = UpperArmL.localEulerAngles.x;
  163. if (x > 250.0 + shoki && x < 357.0 + shoki)
  164. x = 357f + shoki;
  165. if (x < 100.0 + shoki && x > 3.0 + shoki)
  166. x = 3f + shoki;
  167. float z = UpperArmL.localEulerAngles.z;
  168. if (z > 140.0 && z < 270.0)
  169. z = 270f;
  170. if (z <= 140.0 && z > 15.0)
  171. z = 15f;
  172. HandL.localEulerAngles = new Vector3(rotate.x, rotate.y, HandL.localEulerAngles.z);
  173. UpperArmL.localEulerAngles = new Vector3(x, rotate2.y, z);
  174. }
  175. else if (ido == 17)
  176. {
  177. IK.Porc(UpperArmL, ForearmL, HandL, tgt, new Vector3(), ikData);
  178. if (!onFlg)
  179. IK.Porc(UpperArmL, ForearmL, HandL, tgt + (tgt - HandL.position), new Vector3(), ikData);
  180. float x = UpperArmL.localEulerAngles.x;
  181. if (x > 250.0 + shoki && x < 357.0 + shoki)
  182. x = 357f + shoki;
  183. if (x < 100.0 + shoki && x > 3.0 + shoki)
  184. x = 3f + shoki;
  185. float z = UpperArmL.localEulerAngles.z;
  186. if (z > 220.0 && z < 345.0)
  187. z = 345f;
  188. if (z <= 220.0 && z > 90.0)
  189. z = 90f;
  190. HandL.localEulerAngles = new Vector3(rotate.x, rotate.y, HandL.localEulerAngles.z);
  191. UpperArmL.localEulerAngles = new Vector3(x, rotate2.y, z);
  192. }
  193. else if (ido == 13)
  194. {
  195. IK.Porc(UpperArmL, ForearmL, HandL, tgt, new Vector3(), ikData);
  196. if (!onFlg)
  197. IK.Porc(UpperArmL, ForearmL, HandL, tgt + (tgt - HandL.position), new Vector3(), ikData);
  198. float num1 = UpperArmL.localEulerAngles.x;
  199. if (num1 > 250.0 && num1 < 345.0)
  200. num1 = 345f;
  201. if (num1 <= 250.0)
  202. ;
  203. float z = UpperArmL.localEulerAngles.z;
  204. if (z > 160.0 && z < 275.0)
  205. z = 275f;
  206. if (z <= 160.0 && z > 60.0)
  207. z = 60f;
  208. float num2 = UpperArmL.localEulerAngles.y;
  209. if (num2 > 250.0 && num2 < 345.0)
  210. num2 = 345f;
  211. if (num2 <= 250.0)
  212. ;
  213. HandL.localEulerAngles = new Vector3(rotate.x, HandL.localEulerAngles.y, HandL.localEulerAngles.z);
  214. UpperArmL.localEulerAngles = new Vector3(UpperArmL.localEulerAngles.x, UpperArmL.localEulerAngles.y, z);
  215. }
  216. else if (ido == 14)
  217. {
  218. IK.Porc(UpperArmL, ForearmL, HandL, tgt, new Vector3(), ikData);
  219. if (!onFlg)
  220. IK.Porc(UpperArmL, ForearmL, HandL, tgt + (tgt - HandL.position), new Vector3(), ikData);
  221. float x = UpperArmL.localEulerAngles.x;
  222. if (x > 250.0 + shoki && x < 345.0 + shoki)
  223. x = 345f + shoki;
  224. if (x < 100.0 + shoki && x > 15.0 + shoki)
  225. x = 15f + shoki;
  226. float z = UpperArmL.localEulerAngles.z;
  227. if (z > 150.0 && z < 240.0)
  228. z = 240f;
  229. if (z <= 150.0 && z > 30.0)
  230. z = 30f;
  231. HandL.localEulerAngles = new Vector3(rotate.x, rotate.y, HandL.localEulerAngles.z);
  232. UpperArmL.localEulerAngles = new Vector3(x, rotate2.y, z);
  233. }
  234. else if (ido == 15)
  235. {
  236. IK.Porc(UpperArmL, ForearmL, HandL, tgt, new Vector3(), ikData);
  237. if (!onFlg)
  238. IK.Porc(UpperArmL, ForearmL, HandL, tgt + (tgt - HandL.position), new Vector3(), ikData);
  239. float x = UpperArmL.localEulerAngles.x;
  240. if (x > 250.0 + shoki && x < 357.0 + shoki)
  241. x = 357f + shoki;
  242. if (x < 100.0 + shoki && x > 3.0 + shoki)
  243. x = 3f + shoki;
  244. float z = UpperArmL.localEulerAngles.z;
  245. if (z > 150.0 && z < 270.0)
  246. z = 270f;
  247. if (z <= 150.0 && z > 30.0)
  248. z = 30f;
  249. HandL.localEulerAngles = new Vector3(rotate.x, rotate.y, HandL.localEulerAngles.z);
  250. UpperArmL.localEulerAngles = new Vector3(x, rotate2.y, z);
  251. }
  252. else if (ido == 16)
  253. {
  254. Vector3 vector3 = Input.mousePosition - mouseIti;
  255. Transform transform = GameMain.Instance.MainCamera.gameObject.transform;
  256. transform.TransformDirection(Vector3.right);
  257. transform.TransformDirection(Vector3.forward);
  258. if (mouseIti2 != Input.mousePosition)
  259. {
  260. UpperArmL.localEulerAngles = rotate2;
  261. UpperArmL.localRotation = Quaternion.Euler(UpperArmL.localEulerAngles)
  262. * Quaternion.AngleAxis(vector3.x / 2.2f, Vector3.right);
  263. }
  264. }
  265. else
  266. {
  267. Vector3 vector3_1 = Input.mousePosition - mouseIti;
  268. Transform transform = GameMain.Instance.MainCamera.gameObject.transform;
  269. Vector3 vector3_2 = transform.TransformDirection(Vector3.right);
  270. Vector3 vector3_3 = transform.TransformDirection(Vector3.forward);
  271. if (mouseIti2 != Input.mousePosition)
  272. {
  273. if (ido <= 4)
  274. HandL.localEulerAngles = rotate;
  275. else
  276. UpperArmL.localEulerAngles = rotate2;
  277. if (ido == 1)
  278. {
  279. HandL.localRotation = Quaternion.Euler(HandL.localEulerAngles)
  280. * Quaternion.AngleAxis(vector3_1.x / 1.5f, Vector3.up);
  281. HandL.localRotation = Quaternion.Euler(HandL.localEulerAngles)
  282. * Quaternion.AngleAxis(vector3_1.y / 1.5f, Vector3.forward);
  283. }
  284. if (ido == 2)
  285. HandL.localRotation = Quaternion.Euler(HandL.localEulerAngles)
  286. * Quaternion.AngleAxis(vector3_1.x / 1.5f, Vector3.right);
  287. if (ido == 3)
  288. {
  289. HandL.RotateAround(HandL.position, new Vector3(vector3_2.x, 0.0f, vector3_2.z), vector3_1.y / 1f);
  290. HandL.RotateAround(HandL.position, new Vector3(vector3_3.x, 0.0f, vector3_3.z), vector3_1.x / 1.5f);
  291. }
  292. if (ido == 4)
  293. HandL.localRotation = Quaternion.Euler(HandL.localEulerAngles)
  294. * Quaternion.AngleAxis((float) (-(double) vector3_1.x / 1.5), Vector3.right);
  295. if (ido == 5)
  296. UpperArmL.localRotation = Quaternion.Euler(UpperArmL.localEulerAngles)
  297. * Quaternion.AngleAxis((float) (-(double) vector3_1.x / 1.5), Vector3.right);
  298. }
  299. }
  300. }
  301. mouseIti2 = Input.mousePosition;
  302. }
  303. }