Auxiliary.cs 8.9 KB

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