Auxiliary.cs 17 KB

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