Auxiliary.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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.Runtime.Serialization.Formatters.Binary;
  12. using System.Security.Cryptography;
  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.Space))
  61. {
  62. ManaGarden.PlantList[5].Flower.PlayAnim();
  63. }
  64. if (Input.GetKeyDown(KeyCode.P))
  65. {
  66. ManaData.Level += 20;
  67. }
  68. if (Input.GetKeyDown(KeyCode.O))
  69. {
  70. for (int i = 0; i < ManaData.SkillList.Count; i++)
  71. {
  72. ManaData.SkillList[i].ReceiveCool(1, true, true);
  73. }
  74. }
  75. if (Input.GetKeyDown(KeyCode.I))
  76. {
  77. ManaData.Coin += 100000000000000;
  78. ManaData.Diamond += 1000;
  79. }
  80. if (Input.GetKeyDown(KeyCode.U))
  81. {
  82. Data.SavePlayerConfig();
  83. }
  84. if (Input.GetKeyDown(KeyCode.Y))
  85. {
  86. Data.ResetPlayerConfig();
  87. }
  88. if (Input.GetKeyDown(KeyCode.T))
  89. {
  90. ManaData.Pause = !ManaData.Pause;
  91. }
  92. if (Input.GetKeyDown(KeyCode.Escape))
  93. {
  94. ManaReso.Get("K_QuitGame").TweenForCG();
  95. }
  96. #endregion
  97. #region 输入检测
  98. if (AnyKeyUp)
  99. {
  100. if (Input.anyKey == false)
  101. {
  102. AnyKeyUp = false;
  103. }
  104. }
  105. if (Input.anyKeyDown)
  106. {
  107. AnyKeyDown = true;
  108. }
  109. if (AnyKeyDown)
  110. {
  111. if (Input.anyKey == false)
  112. {
  113. AnyKeyUp = true;
  114. AnyKeyDown = false;
  115. }
  116. }
  117. #endregion
  118. }
  119. public static byte[] GetMD5(object obj)
  120. {
  121. MemoryStream memoryStream = new MemoryStream();
  122. BinaryFormatter binaryFormatter = new BinaryFormatter();
  123. binaryFormatter.Serialize(memoryStream, obj);
  124. byte[] bytes = memoryStream.GetBuffer();
  125. memoryStream.Dispose();
  126. return MD5.ComputeHash(bytes);
  127. }
  128. public static byte[] Encrypt(string str)
  129. {
  130. byte[] bytes = Encoding.UTF8.GetBytes(str);
  131. byte[] encryptBytes = Des.CreateEncryptor().TransformFinalBlock(bytes, 0, bytes.Length);
  132. return encryptBytes;
  133. }
  134. public static byte[] ToBytes(string str)
  135. {
  136. string[] strings = str.Split(' ');
  137. byte[] bytes = new byte[strings.Length];
  138. for (int i = 0; i < bytes.Length; i++)
  139. {
  140. bytes[i] = byte.Parse(strings[i]);
  141. }
  142. return bytes;
  143. }
  144. public static string Decrypt(string str)
  145. {
  146. byte[] encryptBytes = ToBytes(str);
  147. byte[] decryptBytes = Des.CreateDecryptor().TransformFinalBlock(encryptBytes, 0, encryptBytes.Length);
  148. return Encoding.UTF8.GetString(decryptBytes);
  149. }
  150. public static string ToString(byte[] bytes)
  151. {
  152. StringBuilder strB = new StringBuilder();
  153. for (int i = 0; i < bytes.Length; i++)
  154. {
  155. if (i == bytes.Length - 1)
  156. {
  157. strB.Append(bytes[i]);
  158. }
  159. else
  160. {
  161. strB.Append(bytes[i] + " ");
  162. }
  163. }
  164. return strB.ToString();
  165. }
  166. public static void CompileDic(Transform tra, Dictionary<string, Transform> dic)
  167. {
  168. Transform[] transforms = tra.GetComponentsInChildren<Transform>(true);
  169. for (int i = 0; i < transforms.Length; i++)
  170. {
  171. if (dic.ContainsKey(transforms[i].name))
  172. {
  173. throw new Exception(transforms[i].name);
  174. }
  175. else
  176. {
  177. dic.Add(transforms[i].name, transforms[i]);
  178. }
  179. }
  180. }
  181. public void DelayCall(UnityAction function, int frame)
  182. {
  183. StartCoroutine(IDelayCall(function, frame));
  184. }
  185. public void DelayCall(UnityAction function, float time)
  186. {
  187. StartCoroutine(IDelayCall(function, time));
  188. }
  189. public static IEnumerator IDelayCall(UnityAction function, int frame)
  190. {
  191. int count = 0;
  192. if (count++ < frame)
  193. {
  194. yield return null;
  195. }
  196. function.Invoke();
  197. }
  198. public static IEnumerator IDelayCall(UnityAction function, float time)
  199. {
  200. yield return new WaitForSeconds(time);
  201. function.Invoke();
  202. }
  203. public static string FmlParse1(string str)
  204. {
  205. int index = 0;
  206. int openIndex = 0;
  207. bool flag = false;
  208. bool group = false;
  209. for (int i = 0; i < str.Length; i++)
  210. {
  211. if (group)
  212. {
  213. if (str[i] == '+' || str[i] == '-' || str[i] == '*' || str[i] == '/')
  214. {
  215. str = str.Replace(openIndex, i - 1, FmlParse2(str[index], str.Between(openIndex, index - 1), str.Between(index + 1, i - 1)));
  216. i = 0;
  217. group = false;
  218. }
  219. else if (i == str.Length - 1)
  220. {
  221. str = str.Replace(openIndex, i, FmlParse2(str[index], str.Between(openIndex, index - 1), str.Between(index + 1, i)));
  222. break;
  223. }
  224. }
  225. else
  226. {
  227. if (str[i] == '+' || str[i] == '-')
  228. {
  229. flag = true;
  230. openIndex = i + 1;
  231. }
  232. else if (str[i] == '*' || str[i] == '/')
  233. {
  234. index = i;
  235. group = true;
  236. if (!flag)
  237. {
  238. openIndex = 0;
  239. }
  240. }
  241. }
  242. }
  243. group = false;
  244. for (int i = 0; i < str.Length; i++)
  245. {
  246. if (group)
  247. {
  248. if (str[i] == '+' || str[i] == '-')
  249. {
  250. str = str.Replace(0, i - 1, FmlParse2(str[index], str.Between(0, index - 1), str.Between(index + 1, i - 1)));
  251. i = -1;
  252. group = false;
  253. }
  254. else if (i == str.Length - 1)
  255. {
  256. return FmlParse2(str[index], str.Between(0, index - 1), str.Between(index + 1, i));
  257. }
  258. }
  259. else
  260. {
  261. if (str[i] == '+' || str[i] == '-')
  262. {
  263. index = i;
  264. group = true;
  265. }
  266. }
  267. }
  268. return str;
  269. }
  270. public static string FmlParse2(char op, string str1, string str2)
  271. {
  272. double var1 = double.Parse(str1);
  273. double var2 = double.Parse(str2);
  274. 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 if (op == '/')
  287. {
  288. return (var1 / var2).ToString();
  289. }
  290. else
  291. {
  292. throw new Exception(op.ToString());
  293. }
  294. }
  295. public static double FmlParse(string str, params string[] strings)
  296. {
  297. for (int i = 0; i < strings.Length; i += 2)
  298. {
  299. str = str.Replace(strings[i], strings[i + 1]);
  300. }
  301. int openIndex = 0;
  302. for (int i = 0; i < str.Length; i++)
  303. {
  304. if (str[i] == '(')
  305. {
  306. openIndex = i;
  307. }
  308. else if (str[i] == ')')
  309. {
  310. str = str.Replace(openIndex, i, FmlParse1(str.Between(openIndex + 1, i - 1)));
  311. i = -1;
  312. }
  313. }
  314. return double.Parse(FmlParse1(str));
  315. }
  316. }