Auxiliary.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. using LitJson;
  2. using DragonBones;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.Events;
  6. using System;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Collections;
  11. using System.Collections.Generic;
  12. using System.Security.Cryptography;
  13. using System.Runtime.Serialization.Formatters.Binary;
  14. using Random = UnityEngine.Random;
  15. using Transform = UnityEngine.Transform;
  16. public class Amount
  17. {
  18. public static double 百 = 100;
  19. public static double 千 = 1000;
  20. public static double 万 = 10000;
  21. public static double 十万 = 100000;
  22. public static double 百万 = 1000000;
  23. public static double 千万 = 10000000;
  24. public static double 亿 = 100000000;
  25. public static double 十亿 = 1000000000;
  26. public static double 千亿 = 100000000000;
  27. public static double 万亿 = 1000000000000;
  28. public static double 千万亿 = 1000000000000000;
  29. public static double 万万亿 = 10000000000000000;
  30. }
  31. public class Auxiliary : Regist
  32. {
  33. #region 变量
  34. public string String;
  35. public Font Font;
  36. public GameObject Go;
  37. public List<GameObject> GoList;
  38. public List<SpriteRenderer> SrList;
  39. public static bool AnyKeyUp;
  40. public static bool AnyKeyDown;
  41. public static Auxiliary Instance;
  42. public static MD5 MD5
  43. {
  44. get
  45. {
  46. if (_MD5 == null)
  47. {
  48. _MD5 = new MD5CryptoServiceProvider();
  49. }
  50. return _MD5;
  51. }
  52. set { _MD5 = value; }
  53. }
  54. public static DESCryptoServiceProvider Des
  55. {
  56. get
  57. {
  58. if (_Des == null)
  59. {
  60. _Des = new DESCryptoServiceProvider();
  61. _Des.IV = Encoding.UTF8.GetBytes("12345678");
  62. _Des.Key = Encoding.UTF8.GetBytes("12345678");
  63. }
  64. return _Des;
  65. }
  66. set { _Des = value; }
  67. }
  68. private static MD5 _MD5;
  69. private static DESCryptoServiceProvider _Des;
  70. #endregion
  71. public override void RegistImmed()
  72. {
  73. if (RegistFlag)
  74. {
  75. return;
  76. }
  77. else
  78. {
  79. RegistFlag = true;
  80. }
  81. enabled = true;
  82. }
  83. private void Awake()
  84. {
  85. Instance = this;
  86. }
  87. private void Update()
  88. {
  89. #region 调试
  90. //if (Input.GetKeyDown(KeyCode.P))
  91. //{
  92. // ManaData.Level += 20;
  93. //}
  94. //if (Input.GetKeyDown(KeyCode.O))
  95. //{
  96. // for (int i = 0; i < ManaData.SkillList.Count; i++)
  97. // {
  98. // ManaData.SkillList[i].ReceiveCool(1, true, true);
  99. // }
  100. //}
  101. //if (Input.GetKeyDown(KeyCode.I))
  102. //{
  103. // ManaData.Coin += 100000;
  104. // ManaData.Diamond += 1000;
  105. //}
  106. //if (Input.GetKeyDown(KeyCode.U))
  107. //{
  108. // Data.SavePlayerConfig();
  109. // Data.SaveXml();
  110. //}
  111. //if (Input.GetKeyDown(KeyCode.Y))
  112. //{
  113. // Data.ResetPlayerConfig();
  114. // Data.SaveXml();
  115. //}
  116. //if (Input.GetKeyDown(KeyCode.T))
  117. //{
  118. // ManaData.Pause = !ManaData.Pause;
  119. //}
  120. if (Input.GetKeyDown(KeyCode.Escape))
  121. {
  122. ManaReso.Get("K_QuitGame").TweenForCG();
  123. }
  124. #endregion
  125. #region 输入检测
  126. if (AnyKeyUp)
  127. {
  128. if (Input.anyKey == false)
  129. {
  130. AnyKeyUp = false;
  131. }
  132. }
  133. if (Input.anyKeyDown)
  134. {
  135. AnyKeyDown = true;
  136. }
  137. if (AnyKeyDown)
  138. {
  139. if (Input.anyKey == false)
  140. {
  141. AnyKeyUp = true;
  142. AnyKeyDown = false;
  143. }
  144. }
  145. #endregion
  146. }
  147. public static byte[] GetMD5(object obj)
  148. {
  149. MemoryStream memoryStream = new MemoryStream();
  150. BinaryFormatter binaryFormatter = new BinaryFormatter();
  151. binaryFormatter.Serialize(memoryStream, obj);
  152. byte[] bytes = memoryStream.GetBuffer();
  153. memoryStream.Dispose();
  154. return MD5.ComputeHash(bytes);
  155. }
  156. public static byte[] Encrypt(string str)
  157. {
  158. byte[] bytes = Encoding.UTF8.GetBytes(str);
  159. byte[] encryptBytes = Des.CreateEncryptor().TransformFinalBlock(bytes, 0, bytes.Length);
  160. return encryptBytes;
  161. }
  162. public static byte[] ToBytes(string str)
  163. {
  164. string[] strings = str.Split(' ');
  165. byte[] bytes = new byte[strings.Length];
  166. for (int i = 0; i < bytes.Length; i++)
  167. {
  168. bytes[i] = byte.Parse(strings[i]);
  169. }
  170. return bytes;
  171. }
  172. public static string Decrypt(string str)
  173. {
  174. byte[] encryptBytes = ToBytes(str);
  175. byte[] decryptBytes = Des.CreateDecryptor().TransformFinalBlock(encryptBytes, 0, encryptBytes.Length);
  176. return Encoding.UTF8.GetString(decryptBytes);
  177. }
  178. public static string ToString(byte[] bytes)
  179. {
  180. StringBuilder strB = new StringBuilder();
  181. for (int i = 0; i < bytes.Length; i++)
  182. {
  183. if (i == bytes.Length - 1)
  184. {
  185. strB.Append(bytes[i]);
  186. }
  187. else
  188. {
  189. strB.Append(bytes[i] + " ");
  190. }
  191. }
  192. return strB.ToString();
  193. }
  194. public static void CompileDic(Transform tra, Dictionary<string, Transform> dic)
  195. {
  196. Transform[] transforms = tra.GetComponentsInChildren<Transform>(true);
  197. for (int i = 0; i < transforms.Length; i++)
  198. {
  199. if (dic.ContainsKey(transforms[i].name))
  200. {
  201. throw new Exception(transforms[i].name);
  202. }
  203. else
  204. {
  205. dic.Add(transforms[i].name, transforms[i]);
  206. }
  207. }
  208. }
  209. public void DelayCall(UnityAction function, int frame)
  210. {
  211. StartCoroutine(IDelayCall(function, frame));
  212. }
  213. public void DelayCall(UnityAction function, float time)
  214. {
  215. StartCoroutine(IDelayCall(function, time));
  216. }
  217. public static IEnumerator IDelayCall(UnityAction function, int frame)
  218. {
  219. int count = 0;
  220. if (count++ < frame)
  221. {
  222. yield return null;
  223. }
  224. function.Invoke();
  225. }
  226. public static IEnumerator IDelayCall(UnityAction function, float time)
  227. {
  228. yield return new WaitForSeconds(time);
  229. function.Invoke();
  230. }
  231. public static string FmlParse1(string str)
  232. {
  233. int index = 0;
  234. int openIndex = 0;
  235. bool flag = false;
  236. bool group = false;
  237. for (int i = 0; i < str.Length; i++)
  238. {
  239. if (group)
  240. {
  241. if (str[i] == '+' || str[i] == '-' || str[i] == '*' || str[i] == '/')
  242. {
  243. str = str.Replace(openIndex, i - 1, FmlParse2(str[index], str.Between(openIndex, index - 1), str.Between(index + 1, i - 1)));
  244. i = 0;
  245. group = false;
  246. }
  247. else if (i == str.Length - 1)
  248. {
  249. str = str.Replace(openIndex, i, FmlParse2(str[index], str.Between(openIndex, index - 1), str.Between(index + 1, i)));
  250. break;
  251. }
  252. }
  253. else
  254. {
  255. if (str[i] == '+' || str[i] == '-')
  256. {
  257. flag = true;
  258. openIndex = i + 1;
  259. }
  260. else if (str[i] == '*' || str[i] == '/')
  261. {
  262. index = i;
  263. group = true;
  264. if (!flag)
  265. {
  266. openIndex = 0;
  267. }
  268. }
  269. }
  270. }
  271. group = false;
  272. for (int i = 0; i < str.Length; i++)
  273. {
  274. if (group)
  275. {
  276. if (str[i] == '+' || str[i] == '-')
  277. {
  278. str = str.Replace(0, i - 1, FmlParse2(str[index], str.Between(0, index - 1), str.Between(index + 1, i - 1)));
  279. i = -1;
  280. group = false;
  281. }
  282. else if (i == str.Length - 1)
  283. {
  284. return FmlParse2(str[index], str.Between(0, index - 1), str.Between(index + 1, i));
  285. }
  286. }
  287. else
  288. {
  289. if (str[i] == '+' || str[i] == '-')
  290. {
  291. index = i;
  292. group = true;
  293. }
  294. }
  295. }
  296. return str;
  297. }
  298. public static string FmlParse2(char op, string str1, string str2)
  299. {
  300. double var1 = double.Parse(str1);
  301. double var2 = double.Parse(str2);
  302. if (op == '+')
  303. {
  304. return (var1 + var2).ToString();
  305. }
  306. else if (op == '-')
  307. {
  308. return (var1 - var2).ToString();
  309. }
  310. else if (op == '*')
  311. {
  312. return (var1 * var2).ToString();
  313. }
  314. else if (op == '/')
  315. {
  316. return (var1 / var2).ToString();
  317. }
  318. else
  319. {
  320. throw new Exception(op.ToString());
  321. }
  322. }
  323. public static double FmlParse(string str, params string[] strings)
  324. {
  325. for (int i = 0; i < strings.Length; i += 2)
  326. {
  327. str = str.Replace(strings[i], strings[i + 1]);
  328. }
  329. int openIndex = 0;
  330. for (int i = 0; i < str.Length; i++)
  331. {
  332. if (str[i] == '(')
  333. {
  334. openIndex = i;
  335. }
  336. else if (str[i] == ')')
  337. {
  338. str = str.Replace(openIndex, i, FmlParse1(str.Between(openIndex + 1, i - 1)));
  339. i = -1;
  340. }
  341. }
  342. return double.Parse(FmlParse1(str));
  343. }
  344. public static string OmitNumberStr(int accuray, string str)
  345. {
  346. int index = str.IndexOf('.');
  347. if (index == -1)
  348. {
  349. return str;
  350. }
  351. if (accuray == 0)
  352. {
  353. return str.Substring(0, index);
  354. }
  355. else
  356. {
  357. return str.Substring(0, index + accuray + 1);
  358. }
  359. }
  360. public static long ShrinkNumber(double value, int accuracy = 1)
  361. {
  362. long longValue = (long) value;
  363. if (ManaLan.CurrentLan == Lan.English)
  364. {
  365. if (longValue < Amount.千)
  366. {
  367. return longValue;
  368. }
  369. else if (longValue < Amount.百万)
  370. {
  371. long temp = (long) Amount.百;
  372. return (longValue/ temp) * temp;
  373. }
  374. else if (longValue < Amount.十亿)
  375. {
  376. long temp = (long)Amount.十万;
  377. return (longValue / temp) * temp;
  378. }
  379. else if (longValue < Amount.万亿)
  380. {
  381. long temp = (long)Amount.亿;
  382. return (longValue / temp) * temp;
  383. }
  384. else if (longValue < Amount.千万亿)
  385. {
  386. long temp = (long)Amount.千亿;
  387. return (longValue / temp) * temp;
  388. }
  389. }
  390. else if (ManaLan.CurrentLan == Lan.ChineseSimplified)
  391. {
  392. if (longValue < Amount.万)
  393. {
  394. return longValue;
  395. }
  396. else if (longValue < Amount.亿)
  397. {
  398. long temp = (long)Amount.千;
  399. return (longValue / temp) * temp;
  400. }
  401. else if (longValue < Amount.万亿)
  402. {
  403. long temp = (long)Amount.千万;
  404. return (longValue / temp) * temp;
  405. }
  406. else if (longValue < Amount.万万亿)
  407. {
  408. long temp = (long)Amount.千亿;
  409. return (longValue / temp) * temp;
  410. }
  411. }
  412. throw new Exception();
  413. }
  414. public static string ShrinkNumberStr(double value, int accuracy = 1)
  415. {
  416. long longValue = (long) value;
  417. if (ManaLan.CurrentLan == Lan.English)
  418. {
  419. if (longValue < Amount.千)
  420. {
  421. return longValue.ToString();
  422. }
  423. else if (longValue < Amount.百万)
  424. {
  425. string str = (longValue / Amount.千).ToString();
  426. return OmitNumberStr(accuracy, str) + "K";
  427. }
  428. else if (longValue < Amount.十亿)
  429. {
  430. string str = (longValue / Amount.百万).ToString();
  431. return OmitNumberStr(accuracy, str) + "M";
  432. }
  433. else if (longValue < Amount.万亿)
  434. {
  435. string str = (longValue / Amount.十亿).ToString();
  436. return OmitNumberStr(accuracy, str) + "B";
  437. }
  438. else if (longValue < Amount.千万亿)
  439. {
  440. string str = (longValue / Amount.万亿).ToString();
  441. return OmitNumberStr(accuracy, str) + "T";
  442. }
  443. }
  444. else if (ManaLan.CurrentLan == Lan.ChineseSimplified)
  445. {
  446. if (longValue < Amount.万)
  447. {
  448. return longValue.ToString();
  449. }
  450. else if (longValue < Amount.亿)
  451. {
  452. string str = (longValue/Amount.万).ToString();
  453. return OmitNumberStr(accuracy, str) + "万";
  454. }
  455. else if (longValue < Amount.万亿)
  456. {
  457. string str = (longValue / Amount.亿).ToString();
  458. return OmitNumberStr(accuracy, str) + "亿";
  459. }
  460. else if (longValue < Amount.万万亿)
  461. {
  462. string str = (longValue / Amount.万亿).ToString();
  463. return OmitNumberStr(accuracy, str) + "万亿";
  464. }
  465. }
  466. throw new Exception();
  467. }
  468. public static int IntParse(string str, int defaultValue)
  469. {
  470. if (string.IsNullOrEmpty(str))
  471. {
  472. return defaultValue;
  473. }
  474. else
  475. {
  476. return int.Parse(str);
  477. }
  478. }
  479. public static bool BoolParse(string str, bool defaultValue)
  480. {
  481. if (string.IsNullOrEmpty(str))
  482. {
  483. return defaultValue;
  484. }
  485. else
  486. {
  487. return Convert.ToBoolean(int.Parse(str));
  488. }
  489. }
  490. public static float FloatParse(string str, float defaultValue)
  491. {
  492. if (string.IsNullOrEmpty(str))
  493. {
  494. return defaultValue;
  495. }
  496. else
  497. {
  498. return float.Parse(str);
  499. }
  500. }
  501. public static double DoubleParse(string str, double defaultValue)
  502. {
  503. if (string.IsNullOrEmpty(str))
  504. {
  505. return defaultValue;
  506. }
  507. else
  508. {
  509. return float.Parse(str);
  510. }
  511. }
  512. public static List<int> IntListParse(char cah, string str, List<int> defaultValue)
  513. {
  514. if (string.IsNullOrEmpty(str))
  515. {
  516. return defaultValue;
  517. }
  518. else
  519. {
  520. string[] strings = str.Split(cah);
  521. List<int> list = new List<int>();
  522. for (int i = 0; i < strings.Length; i++)
  523. {
  524. list.Add(int.Parse(strings[i]));
  525. }
  526. return list;
  527. }
  528. }
  529. public static List<string> StringListParse(char cah, string str, List<string> defaultValue)
  530. {
  531. if (string.IsNullOrEmpty(str))
  532. {
  533. return defaultValue;
  534. }
  535. else
  536. {
  537. string[] strings = str.Split(cah);
  538. List<string> list = new List<string>();
  539. for (int i = 0; i < strings.Length; i++)
  540. {
  541. list.Add(strings[i]);
  542. }
  543. return list;
  544. }
  545. }
  546. public static List<double> DoubleListParse(char cah, string str, List<double> defaultValue)
  547. {
  548. if (string.IsNullOrEmpty(str))
  549. {
  550. return defaultValue;
  551. }
  552. else
  553. {
  554. string[] strings = str.Split(cah);
  555. List<double> list = new List<double>();
  556. for (int i = 0; i < strings.Length; i++)
  557. {
  558. list.Add(double.Parse(strings[i]));
  559. }
  560. return list;
  561. }
  562. }
  563. }