Auxiliary.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  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 += 100000;
  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. if (count++ < frame)
  226. {
  227. yield return null;
  228. }
  229. function.Invoke();
  230. }
  231. public static IEnumerator IDelayCall(UnityAction function, float time)
  232. {
  233. yield return new WaitForSeconds(time);
  234. function.Invoke();
  235. }
  236. public static string FmlParse1(string str)
  237. {
  238. int index = 0;
  239. int openIndex = 0;
  240. bool flag = false;
  241. bool group = false;
  242. for (int i = 0; i < str.Length; i++)
  243. {
  244. if (group)
  245. {
  246. if (str[i] == '+' || str[i] == '-' || str[i] == '*' || str[i] == '/')
  247. {
  248. str = str.Replace(openIndex, i - 1, FmlParse2(str[index], str.Between(openIndex, index - 1), str.Between(index + 1, i - 1)));
  249. i = 0;
  250. group = false;
  251. }
  252. else if (i == str.Length - 1)
  253. {
  254. str = str.Replace(openIndex, i, FmlParse2(str[index], str.Between(openIndex, index - 1), str.Between(index + 1, i)));
  255. break;
  256. }
  257. }
  258. else
  259. {
  260. if (str[i] == '+' || str[i] == '-')
  261. {
  262. flag = true;
  263. openIndex = i + 1;
  264. }
  265. else if (str[i] == '*' || str[i] == '/')
  266. {
  267. index = i;
  268. group = true;
  269. if (!flag)
  270. {
  271. openIndex = 0;
  272. }
  273. }
  274. }
  275. }
  276. group = false;
  277. for (int i = 0; i < str.Length; i++)
  278. {
  279. if (group)
  280. {
  281. if (str[i] == '+' || str[i] == '-')
  282. {
  283. str = str.Replace(0, i - 1, FmlParse2(str[index], str.Between(0, index - 1), str.Between(index + 1, i - 1)));
  284. i = -1;
  285. group = false;
  286. }
  287. else if (i == str.Length - 1)
  288. {
  289. return FmlParse2(str[index], str.Between(0, index - 1), str.Between(index + 1, i));
  290. }
  291. }
  292. else
  293. {
  294. if (str[i] == '+' || str[i] == '-')
  295. {
  296. index = i;
  297. group = true;
  298. }
  299. }
  300. }
  301. return str;
  302. }
  303. public static string FmlParse2(char op, string str1, string str2)
  304. {
  305. double var1 = double.Parse(str1);
  306. double var2 = double.Parse(str2);
  307. if (op == '+')
  308. {
  309. return (var1 + var2).ToString();
  310. }
  311. else if (op == '-')
  312. {
  313. return (var1 - var2).ToString();
  314. }
  315. else if (op == '*')
  316. {
  317. return (var1 * var2).ToString();
  318. }
  319. else if (op == '/')
  320. {
  321. return (var1 / var2).ToString();
  322. }
  323. else
  324. {
  325. throw new Exception(op.ToString());
  326. }
  327. }
  328. public static double FmlParse(string str, params string[] strings)
  329. {
  330. for (int i = 0; i < strings.Length; i += 2)
  331. {
  332. str = str.Replace(strings[i], strings[i + 1]);
  333. }
  334. int openIndex = 0;
  335. for (int i = 0; i < str.Length; i++)
  336. {
  337. if (str[i] == '(')
  338. {
  339. openIndex = i;
  340. }
  341. else if (str[i] == ')')
  342. {
  343. str = str.Replace(openIndex, i, FmlParse1(str.Between(openIndex + 1, i - 1)));
  344. i = -1;
  345. }
  346. }
  347. return double.Parse(FmlParse1(str));
  348. }
  349. public static string OmitNumberStr(int accuray, string str)
  350. {
  351. int index = str.IndexOf('.');
  352. if (index == -1)
  353. {
  354. return str;
  355. }
  356. if (accuray == 0)
  357. {
  358. return str.Substring(0, index);
  359. }
  360. else
  361. {
  362. return str.Substring(0, index + accuray + 1);
  363. }
  364. }
  365. public static long ShrinkNumber(double value, int accuracy = 1)
  366. {
  367. long longValue = (long) value;
  368. if (ManaLan.CurrentLan == Lan.English)
  369. {
  370. if (longValue < Amount.千)
  371. {
  372. return longValue;
  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. else if (longValue < Amount.千万亿)
  390. {
  391. long temp = (long)Amount.千亿;
  392. return (longValue / temp) * temp;
  393. }
  394. }
  395. else if (ManaLan.CurrentLan == Lan.ChineseSimplified || ManaLan.CurrentLan == Lan.ChineseTraditional)
  396. {
  397. if (longValue < Amount.万)
  398. {
  399. return longValue;
  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. else if (longValue < Amount.万万亿)
  412. {
  413. long temp = (long)Amount.千亿;
  414. return (longValue / temp) * temp;
  415. }
  416. }
  417. throw new Exception();
  418. }
  419. public static string ShrinkNumberStr(double value, int accuracy = 1)
  420. {
  421. long longValue = (long) value;
  422. if (ManaLan.CurrentLan == Lan.English)
  423. {
  424. if (longValue < Amount.千)
  425. {
  426. return longValue.ToString();
  427. }
  428. else if (longValue < Amount.百万)
  429. {
  430. string str = (longValue / Amount.千).ToString();
  431. return OmitNumberStr(accuracy, str) + "K";
  432. }
  433. else if (longValue < Amount.十亿)
  434. {
  435. string str = (longValue / Amount.百万).ToString();
  436. return OmitNumberStr(accuracy, str) + "M";
  437. }
  438. else if (longValue < Amount.万亿)
  439. {
  440. string str = (longValue / Amount.十亿).ToString();
  441. return OmitNumberStr(accuracy, str) + "B";
  442. }
  443. else if (longValue < Amount.千万亿)
  444. {
  445. string str = (longValue / Amount.万亿).ToString();
  446. return OmitNumberStr(accuracy, str) + "T";
  447. }
  448. }
  449. else if (ManaLan.CurrentLan == Lan.ChineseSimplified)
  450. {
  451. if (longValue < Amount.万)
  452. {
  453. return longValue.ToString();
  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. else if (longValue < Amount.万万亿)
  466. {
  467. string str = (longValue / Amount.万亿).ToString();
  468. return OmitNumberStr(accuracy, str) + "万亿";
  469. }
  470. }
  471. else if (ManaLan.CurrentLan == Lan.ChineseTraditional)
  472. {
  473. if (longValue < Amount.万)
  474. {
  475. return longValue.ToString();
  476. }
  477. else if (longValue < Amount.亿)
  478. {
  479. string str = (longValue / Amount.万).ToString();
  480. return OmitNumberStr(accuracy, str) + "萬";
  481. }
  482. else if (longValue < Amount.万亿)
  483. {
  484. string str = (longValue / Amount.亿).ToString();
  485. return OmitNumberStr(accuracy, str) + "億";
  486. }
  487. else if (longValue < Amount.万万亿)
  488. {
  489. string str = (longValue / Amount.万亿).ToString();
  490. return OmitNumberStr(accuracy, str) + "萬億";
  491. }
  492. }
  493. throw new Exception();
  494. }
  495. public static int IntParse(string str, int defaultValue)
  496. {
  497. if (string.IsNullOrEmpty(str))
  498. {
  499. return defaultValue;
  500. }
  501. else
  502. {
  503. return int.Parse(str);
  504. }
  505. }
  506. public static long LongParse(string str, long defaultValue)
  507. {
  508. if (string.IsNullOrEmpty(str))
  509. {
  510. return defaultValue;
  511. }
  512. else
  513. {
  514. return long.Parse(str);
  515. }
  516. }
  517. public static bool BoolParse(string str, bool defaultValue)
  518. {
  519. if (string.IsNullOrEmpty(str))
  520. {
  521. return defaultValue;
  522. }
  523. else
  524. {
  525. return Convert.ToBoolean(int.Parse(str));
  526. }
  527. }
  528. public static float FloatParse(string str, float defaultValue)
  529. {
  530. if (string.IsNullOrEmpty(str))
  531. {
  532. return defaultValue;
  533. }
  534. else
  535. {
  536. return float.Parse(str);
  537. }
  538. }
  539. public static double DoubleParse(string str, double defaultValue)
  540. {
  541. if (string.IsNullOrEmpty(str))
  542. {
  543. return defaultValue;
  544. }
  545. else
  546. {
  547. return float.Parse(str);
  548. }
  549. }
  550. public static List<int> IntListParse(char cah, string str, List<int> defaultValue)
  551. {
  552. if (string.IsNullOrEmpty(str))
  553. {
  554. return defaultValue;
  555. }
  556. else
  557. {
  558. string[] strings = str.Split(cah);
  559. List<int> list = new List<int>();
  560. for (int i = 0; i < strings.Length; i++)
  561. {
  562. list.Add(int.Parse(strings[i]));
  563. }
  564. return list;
  565. }
  566. }
  567. public static List<string> StringListParse(char cah, string str, List<string> defaultValue)
  568. {
  569. if (string.IsNullOrEmpty(str))
  570. {
  571. return defaultValue;
  572. }
  573. else
  574. {
  575. string[] strings = str.Split(cah);
  576. List<string> list = new List<string>();
  577. for (int i = 0; i < strings.Length; i++)
  578. {
  579. list.Add(strings[i]);
  580. }
  581. return list;
  582. }
  583. }
  584. public static List<double> DoubleListParse(char cah, string str, List<double> defaultValue)
  585. {
  586. if (string.IsNullOrEmpty(str))
  587. {
  588. return defaultValue;
  589. }
  590. else
  591. {
  592. string[] strings = str.Split(cah);
  593. List<double> list = new List<double>();
  594. for (int i = 0; i < strings.Length; i++)
  595. {
  596. list.Add(double.Parse(strings[i]));
  597. }
  598. return list;
  599. }
  600. }
  601. }