Auxiliary.cs 7.9 KB

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