Auxiliary.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. using LitJson;
  2. using DragonBones;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.Events;
  6. using System;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Collections;
  11. using System.Collections.Generic;
  12. using System.Security.Cryptography;
  13. using System.Runtime.Serialization.Formatters.Binary;
  14. using Random = UnityEngine.Random;
  15. using Transform = UnityEngine.Transform;
  16. public class Auxiliary : MonoBehaviour
  17. {
  18. #region 变量
  19. public string String;
  20. public Font Font;
  21. public GameObject Go;
  22. public List<GameObject> GoList;
  23. public List<SpriteRenderer> SrList;
  24. public static bool AnyKeyUp;
  25. public static bool AnyKeyDown;
  26. public static Auxiliary Instance;
  27. public static MD5 MD5
  28. {
  29. get
  30. {
  31. if (_MD5 == null)
  32. {
  33. _MD5 = new MD5CryptoServiceProvider();
  34. }
  35. return _MD5;
  36. }
  37. set { _MD5 = value; }
  38. }
  39. public static DESCryptoServiceProvider Des
  40. {
  41. get
  42. {
  43. if (_Des == null)
  44. {
  45. _Des = new DESCryptoServiceProvider();
  46. _Des.IV = Encoding.UTF8.GetBytes("12345678");
  47. _Des.Key = Encoding.UTF8.GetBytes("12345678");
  48. }
  49. return _Des;
  50. }
  51. set { _Des = value; }
  52. }
  53. private static MD5 _MD5;
  54. private static DESCryptoServiceProvider _Des;
  55. #endregion
  56. private void Awake()
  57. {
  58. Instance = this;
  59. }
  60. private void Update()
  61. {
  62. #region 调试
  63. //if (Input.GetKeyDown(KeyCode.Z))
  64. //{
  65. // ManaServer.Save();
  66. //}
  67. //if (Input.GetKeyDown(KeyCode.X))
  68. //{
  69. // ManaServer.Load();
  70. //}
  71. if (Input.GetKeyDown(KeyCode.P))
  72. {
  73. ManaData.Level += 20;
  74. }
  75. if (Input.GetKeyDown(KeyCode.O))
  76. {
  77. for (int i = 0; i < ManaData.SkillList.Count; i++)
  78. {
  79. ManaData.SkillList[i].ReceiveCool(1, true, true);
  80. }
  81. }
  82. if (Input.GetKeyDown(KeyCode.I))
  83. {
  84. ManaData.Coin += 1000;
  85. ManaData.Diamond += 1000;
  86. }
  87. if (Input.GetKeyDown(KeyCode.U))
  88. {
  89. Data.SavePlayerConfig();
  90. }
  91. if (Input.GetKeyDown(KeyCode.Y))
  92. {
  93. Data.ResetPlayerConfig();
  94. }
  95. if (Input.GetKeyDown(KeyCode.T))
  96. {
  97. ManaData.Pause = !ManaData.Pause;
  98. }
  99. if (Input.GetKeyDown(KeyCode.Escape))
  100. {
  101. ManaReso.Get("K_QuitGame").TweenForCG();
  102. }
  103. #endregion
  104. #region 输入检测
  105. if (AnyKeyUp)
  106. {
  107. if (Input.anyKey == false)
  108. {
  109. AnyKeyUp = false;
  110. }
  111. }
  112. if (Input.anyKeyDown)
  113. {
  114. AnyKeyDown = true;
  115. }
  116. if (AnyKeyDown)
  117. {
  118. if (Input.anyKey == false)
  119. {
  120. AnyKeyUp = true;
  121. AnyKeyDown = false;
  122. }
  123. }
  124. #endregion
  125. }
  126. public static byte[] GetMD5(object obj)
  127. {
  128. MemoryStream memoryStream = new MemoryStream();
  129. BinaryFormatter binaryFormatter = new BinaryFormatter();
  130. binaryFormatter.Serialize(memoryStream, obj);
  131. byte[] bytes = memoryStream.GetBuffer();
  132. memoryStream.Dispose();
  133. return MD5.ComputeHash(bytes);
  134. }
  135. public static byte[] Encrypt(string str)
  136. {
  137. byte[] bytes = Encoding.UTF8.GetBytes(str);
  138. byte[] encryptBytes = Des.CreateEncryptor().TransformFinalBlock(bytes, 0, bytes.Length);
  139. return encryptBytes;
  140. }
  141. public static byte[] ToBytes(string str)
  142. {
  143. string[] strings = str.Split(' ');
  144. byte[] bytes = new byte[strings.Length];
  145. for (int i = 0; i < bytes.Length; i++)
  146. {
  147. bytes[i] = byte.Parse(strings[i]);
  148. }
  149. return bytes;
  150. }
  151. public static string Decrypt(string str)
  152. {
  153. byte[] encryptBytes = ToBytes(str);
  154. byte[] decryptBytes = Des.CreateDecryptor().TransformFinalBlock(encryptBytes, 0, encryptBytes.Length);
  155. return Encoding.UTF8.GetString(decryptBytes);
  156. }
  157. public static string ToString(byte[] bytes)
  158. {
  159. StringBuilder strB = new StringBuilder();
  160. for (int i = 0; i < bytes.Length; i++)
  161. {
  162. if (i == bytes.Length - 1)
  163. {
  164. strB.Append(bytes[i]);
  165. }
  166. else
  167. {
  168. strB.Append(bytes[i] + " ");
  169. }
  170. }
  171. return strB.ToString();
  172. }
  173. public static void CompileDic(Transform tra, Dictionary<string, Transform> dic)
  174. {
  175. Transform[] transforms = tra.GetComponentsInChildren<Transform>(true);
  176. for (int i = 0; i < transforms.Length; i++)
  177. {
  178. if (dic.ContainsKey(transforms[i].name))
  179. {
  180. throw new Exception(transforms[i].name);
  181. }
  182. else
  183. {
  184. dic.Add(transforms[i].name, transforms[i]);
  185. }
  186. }
  187. }
  188. public void DelayCall(UnityAction function, int frame)
  189. {
  190. StartCoroutine(IDelayCall(function, frame));
  191. }
  192. public void DelayCall(UnityAction function, float time)
  193. {
  194. StartCoroutine(IDelayCall(function, time));
  195. }
  196. public static IEnumerator IDelayCall(UnityAction function, int frame)
  197. {
  198. int count = 0;
  199. if (count++ < frame)
  200. {
  201. yield return null;
  202. }
  203. function.Invoke();
  204. }
  205. public static IEnumerator IDelayCall(UnityAction function, float time)
  206. {
  207. yield return new WaitForSeconds(time);
  208. function.Invoke();
  209. }
  210. public static string FmlParse1(string str)
  211. {
  212. int index = 0;
  213. int openIndex = 0;
  214. bool flag = false;
  215. bool group = false;
  216. for (int i = 0; i < str.Length; i++)
  217. {
  218. if (group)
  219. {
  220. if (str[i] == '+' || str[i] == '-' || str[i] == '*' || str[i] == '/')
  221. {
  222. str = str.Replace(openIndex, i - 1, FmlParse2(str[index], str.Between(openIndex, index - 1), str.Between(index + 1, i - 1)));
  223. i = 0;
  224. group = false;
  225. }
  226. else if (i == str.Length - 1)
  227. {
  228. str = str.Replace(openIndex, i, FmlParse2(str[index], str.Between(openIndex, index - 1), str.Between(index + 1, i)));
  229. break;
  230. }
  231. }
  232. else
  233. {
  234. if (str[i] == '+' || str[i] == '-')
  235. {
  236. flag = true;
  237. openIndex = i + 1;
  238. }
  239. else if (str[i] == '*' || str[i] == '/')
  240. {
  241. index = i;
  242. group = true;
  243. if (!flag)
  244. {
  245. openIndex = 0;
  246. }
  247. }
  248. }
  249. }
  250. group = false;
  251. for (int i = 0; i < str.Length; i++)
  252. {
  253. if (group)
  254. {
  255. if (str[i] == '+' || str[i] == '-')
  256. {
  257. str = str.Replace(0, i - 1, FmlParse2(str[index], str.Between(0, index - 1), str.Between(index + 1, i - 1)));
  258. i = -1;
  259. group = false;
  260. }
  261. else if (i == str.Length - 1)
  262. {
  263. return FmlParse2(str[index], str.Between(0, index - 1), str.Between(index + 1, i));
  264. }
  265. }
  266. else
  267. {
  268. if (str[i] == '+' || str[i] == '-')
  269. {
  270. index = i;
  271. group = true;
  272. }
  273. }
  274. }
  275. return str;
  276. }
  277. public static string FmlParse2(char op, string str1, string str2)
  278. {
  279. double var1 = double.Parse(str1);
  280. double var2 = double.Parse(str2);
  281. if (op == '+')
  282. {
  283. return (var1 + var2).ToString();
  284. }
  285. else if (op == '-')
  286. {
  287. return (var1 - var2).ToString();
  288. }
  289. else if (op == '*')
  290. {
  291. return (var1 * var2).ToString();
  292. }
  293. else if (op == '/')
  294. {
  295. return (var1 / var2).ToString();
  296. }
  297. else
  298. {
  299. throw new Exception(op.ToString());
  300. }
  301. }
  302. public static double FmlParse(string str, params string[] strings)
  303. {
  304. for (int i = 0; i < strings.Length; i += 2)
  305. {
  306. str = str.Replace(strings[i], strings[i + 1]);
  307. }
  308. int openIndex = 0;
  309. for (int i = 0; i < str.Length; i++)
  310. {
  311. if (str[i] == '(')
  312. {
  313. openIndex = i;
  314. }
  315. else if (str[i] == ')')
  316. {
  317. str = str.Replace(openIndex, i, FmlParse1(str.Between(openIndex + 1, i - 1)));
  318. i = -1;
  319. }
  320. }
  321. return double.Parse(FmlParse1(str));
  322. }
  323. public static List<int> ToIntList(string str)
  324. {
  325. if (string.IsNullOrEmpty(str))
  326. {
  327. return null;
  328. }
  329. else
  330. {
  331. string[] strings = str.Split(',');
  332. List<int> list = new List<int>();
  333. for (int i = 0; i < strings.Length; i++)
  334. {
  335. list.Add(int.Parse(strings[i]));
  336. }
  337. return list;
  338. }
  339. }
  340. }