Auxiliary.cs 8.8 KB

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