Auxiliary.cs 8.1 KB

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