Auxiliary.cs 17 KB

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