Auxiliary.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  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. ManaSign.SignIndex = 21;
  97. }
  98. //if (Input.GetKeyDown(KeyCode.P))
  99. //{
  100. // ManaData.Level += 20;
  101. //}
  102. //if (Input.GetKeyDown(KeyCode.O))
  103. //{
  104. // for (int i = 0; i < ManaData.SkillList.Count; i++)
  105. // {
  106. // ManaData.SkillList[i].ReceiveCool(1, true, true);
  107. // }
  108. //}
  109. //if (Input.GetKeyDown(KeyCode.I))
  110. //{
  111. // ManaData.Coin += 1000;
  112. // ManaData.Diamond += 1000;
  113. //}
  114. //if (Input.GetKeyDown(KeyCode.U))
  115. //{
  116. // Data.SavePlayerConfig();
  117. // Data.SaveXml();
  118. //}
  119. //if (Input.GetKeyDown(KeyCode.Y))
  120. //{
  121. // Data.ResetPlayerConfig();
  122. // Data.SaveXml();
  123. //}
  124. //if (Input.GetKeyDown(KeyCode.T))
  125. //{
  126. // ManaData.Pause = !ManaData.Pause;
  127. //}
  128. if (Input.GetKeyDown(KeyCode.Escape))
  129. {
  130. ManaMiniGame.Pause = true;
  131. Bubble.Show(Language.GetStr("Common", "QuitGame"), null, null, Application.Quit, ()=>{ ManaMiniGame.Pause = false; });
  132. }
  133. #endregion
  134. #region 输入检测
  135. if (AnyKeyUp)
  136. {
  137. if (Input.anyKey == false)
  138. {
  139. AnyKeyUp = false;
  140. }
  141. }
  142. if (Input.anyKeyDown)
  143. {
  144. AnyKeyDown = true;
  145. }
  146. if (AnyKeyDown)
  147. {
  148. if (Input.anyKey == false)
  149. {
  150. AnyKeyUp = true;
  151. AnyKeyDown = false;
  152. }
  153. }
  154. #endregion
  155. }
  156. public static byte[] GetMD5(object obj)
  157. {
  158. MemoryStream memoryStream = new MemoryStream();
  159. BinaryFormatter binaryFormatter = new BinaryFormatter();
  160. binaryFormatter.Serialize(memoryStream, obj);
  161. byte[] bytes = memoryStream.GetBuffer();
  162. memoryStream.Dispose();
  163. return MD5.ComputeHash(bytes);
  164. }
  165. public static byte[] Encrypt(string str)
  166. {
  167. byte[] bytes = Encoding.UTF8.GetBytes(str);
  168. byte[] encryptBytes = Des.CreateEncryptor().TransformFinalBlock(bytes, 0, bytes.Length);
  169. return encryptBytes;
  170. }
  171. public static byte[] ToBytes(string str)
  172. {
  173. string[] strings = str.Split(' ');
  174. byte[] bytes = new byte[strings.Length];
  175. for (int i = 0; i < bytes.Length; i++)
  176. {
  177. bytes[i] = byte.Parse(strings[i]);
  178. }
  179. return bytes;
  180. }
  181. public static string Decrypt(string str)
  182. {
  183. byte[] encryptBytes = ToBytes(str);
  184. byte[] decryptBytes = Des.CreateDecryptor().TransformFinalBlock(encryptBytes, 0, encryptBytes.Length);
  185. return Encoding.UTF8.GetString(decryptBytes);
  186. }
  187. public static string ToString(byte[] bytes)
  188. {
  189. StringBuilder strB = new StringBuilder();
  190. for (int i = 0; i < bytes.Length; i++)
  191. {
  192. if (i == bytes.Length - 1)
  193. {
  194. strB.Append(bytes[i]);
  195. }
  196. else
  197. {
  198. strB.Append(bytes[i] + " ");
  199. }
  200. }
  201. return strB.ToString();
  202. }
  203. public static void CompileDic(Transform tra, Dictionary<string, Transform> dic)
  204. {
  205. Transform[] transforms = tra.GetComponentsInChildren<Transform>(true);
  206. for (int i = 0; i < transforms.Length; i++)
  207. {
  208. if (dic.ContainsKey(transforms[i].name))
  209. {
  210. throw new Exception(transforms[i].name);
  211. }
  212. else
  213. {
  214. dic.Add(transforms[i].name, transforms[i]);
  215. }
  216. }
  217. }
  218. public void DelayCall(UnityAction function, int frame)
  219. {
  220. StartCoroutine(IDelayCall(function, frame));
  221. }
  222. public void DelayCall(UnityAction function, float time)
  223. {
  224. StartCoroutine(IDelayCall(function, time));
  225. }
  226. public static IEnumerator IDelayCall(UnityAction function, int frame)
  227. {
  228. int count = 0;
  229. while (count < frame)
  230. {
  231. count++;
  232. yield return null;
  233. }
  234. function.Invoke();
  235. }
  236. public static IEnumerator IDelayCall(UnityAction function, float time)
  237. {
  238. yield return new WaitForSeconds(time);
  239. function.Invoke();
  240. }
  241. public static string FmlParse1(string str)
  242. {
  243. int index = 0;
  244. int openIndex = 0;
  245. bool flag = false;
  246. bool group = false;
  247. for (int i = 0; i < str.Length; i++)
  248. {
  249. if (group)
  250. {
  251. if (str[i] == '+' || str[i] == '-' || str[i] == '*' || str[i] == '/')
  252. {
  253. str = str.Replace(openIndex, i - 1, FmlParse2(str[index], str.Between(openIndex, index - 1), str.Between(index + 1, i - 1)));
  254. i = 0;
  255. group = false;
  256. }
  257. else if (i == str.Length - 1)
  258. {
  259. str = str.Replace(openIndex, i, FmlParse2(str[index], str.Between(openIndex, index - 1), str.Between(index + 1, i)));
  260. break;
  261. }
  262. }
  263. else
  264. {
  265. if (str[i] == '+' || str[i] == '-')
  266. {
  267. flag = true;
  268. openIndex = i + 1;
  269. }
  270. else if (str[i] == '*' || str[i] == '/')
  271. {
  272. index = i;
  273. group = true;
  274. if (!flag)
  275. {
  276. openIndex = 0;
  277. }
  278. }
  279. }
  280. }
  281. group = false;
  282. for (int i = 0; i < str.Length; i++)
  283. {
  284. if (group)
  285. {
  286. if (str[i] == '+' || str[i] == '-')
  287. {
  288. str = str.Replace(0, i - 1, FmlParse2(str[index], str.Between(0, index - 1), str.Between(index + 1, i - 1)));
  289. i = -1;
  290. group = false;
  291. }
  292. else if (i == str.Length - 1)
  293. {
  294. return FmlParse2(str[index], str.Between(0, index - 1), str.Between(index + 1, i));
  295. }
  296. }
  297. else
  298. {
  299. if (str[i] == '+' || str[i] == '-')
  300. {
  301. index = i;
  302. group = true;
  303. }
  304. }
  305. }
  306. return str;
  307. }
  308. public static string FmlParse2(char op, string str1, string str2)
  309. {
  310. double var1 = double.Parse(str1);
  311. double var2 = double.Parse(str2);
  312. 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 if (op == '/')
  325. {
  326. return (var1 / var2).ToString();
  327. }
  328. else
  329. {
  330. throw new Exception(op.ToString());
  331. }
  332. }
  333. public static double FmlParse(string str, params string[] strings)
  334. {
  335. for (int i = 0; i < strings.Length; i += 2)
  336. {
  337. str = str.Replace(strings[i], strings[i + 1]);
  338. }
  339. int openIndex = 0;
  340. for (int i = 0; i < str.Length; i++)
  341. {
  342. if (str[i] == '(')
  343. {
  344. openIndex = i;
  345. }
  346. else if (str[i] == ')')
  347. {
  348. str = str.Replace(openIndex, i, FmlParse1(str.Between(openIndex + 1, i - 1)));
  349. i = -1;
  350. }
  351. }
  352. return double.Parse(FmlParse1(str));
  353. }
  354. public static string OmitNumberStr(int accuray, string str)
  355. {
  356. int index = str.IndexOf('.');
  357. if (index == -1)
  358. {
  359. return str;
  360. }
  361. if (accuray == 0)
  362. {
  363. return str.Substring(0, index);
  364. }
  365. else
  366. {
  367. return str.Substring(0, index + accuray + 1);
  368. }
  369. }
  370. public static long ShrinkNumber(double value, int accuracy = 1)
  371. {
  372. long longValue = (long) value;
  373. if (ManaLan.CurrentLan == Lan.English)
  374. {
  375. if (longValue < Amount.千)
  376. {
  377. return longValue;
  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. else if (longValue < Amount.千万亿)
  395. {
  396. long temp = (long)Amount.千亿;
  397. return (longValue / temp) * temp;
  398. }
  399. }
  400. else if (ManaLan.CurrentLan == Lan.ChineseSimplified || ManaLan.CurrentLan == Lan.ChineseTraditional)
  401. {
  402. if (longValue < Amount.万)
  403. {
  404. return longValue;
  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. else if (longValue < Amount.万万亿)
  417. {
  418. long temp = (long)Amount.千亿;
  419. return (longValue / temp) * temp;
  420. }
  421. }
  422. throw new Exception();
  423. }
  424. public static string ShrinkNumberStr(double value, int accuracy = 1)
  425. {
  426. long longValue = (long) value;
  427. if (ManaLan.CurrentLan == Lan.English)
  428. {
  429. if (longValue < Amount.千)
  430. {
  431. return longValue.ToString();
  432. }
  433. else if (longValue < Amount.百万)
  434. {
  435. string str = (longValue / Amount.千).ToString();
  436. return OmitNumberStr(accuracy, str) + "K";
  437. }
  438. else if (longValue < Amount.十亿)
  439. {
  440. string str = (longValue / Amount.百万).ToString();
  441. return OmitNumberStr(accuracy, str) + "M";
  442. }
  443. else if (longValue < Amount.万亿)
  444. {
  445. string str = (longValue / Amount.十亿).ToString();
  446. return OmitNumberStr(accuracy, str) + "B";
  447. }
  448. else if (longValue < Amount.千万亿)
  449. {
  450. string str = (longValue / Amount.万亿).ToString();
  451. return OmitNumberStr(accuracy, str) + "T";
  452. }
  453. }
  454. else if (ManaLan.CurrentLan == Lan.ChineseSimplified)
  455. {
  456. if (longValue < Amount.万)
  457. {
  458. return longValue.ToString();
  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. else if (longValue < Amount.万万亿)
  471. {
  472. string str = (longValue / Amount.万亿).ToString();
  473. return OmitNumberStr(accuracy, str) + "万亿";
  474. }
  475. }
  476. else if (ManaLan.CurrentLan == Lan.ChineseTraditional)
  477. {
  478. if (longValue < Amount.万)
  479. {
  480. return longValue.ToString();
  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. else if (longValue < Amount.万万亿)
  493. {
  494. string str = (longValue / Amount.万亿).ToString();
  495. return OmitNumberStr(accuracy, str) + "萬億";
  496. }
  497. }
  498. throw new Exception();
  499. }
  500. public static int IntParse(string str, int defaultValue)
  501. {
  502. if (string.IsNullOrEmpty(str))
  503. {
  504. return defaultValue;
  505. }
  506. else
  507. {
  508. return int.Parse(str);
  509. }
  510. }
  511. public static long LongParse(string str, long defaultValue)
  512. {
  513. if (string.IsNullOrEmpty(str))
  514. {
  515. return defaultValue;
  516. }
  517. else
  518. {
  519. return long.Parse(str);
  520. }
  521. }
  522. public static bool BoolParse(string str, bool defaultValue)
  523. {
  524. if (string.IsNullOrEmpty(str))
  525. {
  526. return defaultValue;
  527. }
  528. else
  529. {
  530. return Convert.ToBoolean(int.Parse(str));
  531. }
  532. }
  533. public static float FloatParse(string str, float defaultValue)
  534. {
  535. if (string.IsNullOrEmpty(str))
  536. {
  537. return defaultValue;
  538. }
  539. else
  540. {
  541. return float.Parse(str);
  542. }
  543. }
  544. public static double DoubleParse(string str, double defaultValue)
  545. {
  546. if (string.IsNullOrEmpty(str))
  547. {
  548. return defaultValue;
  549. }
  550. else
  551. {
  552. return float.Parse(str);
  553. }
  554. }
  555. public static List<int> IntListParse(char cah, string str, List<int> defaultValue)
  556. {
  557. if (string.IsNullOrEmpty(str))
  558. {
  559. return defaultValue;
  560. }
  561. else
  562. {
  563. string[] strings = str.Split(cah);
  564. List<int> list = new List<int>();
  565. for (int i = 0; i < strings.Length; i++)
  566. {
  567. list.Add(int.Parse(strings[i]));
  568. }
  569. return list;
  570. }
  571. }
  572. public static List<string> StringListParse(char cah, string str, List<string> defaultValue)
  573. {
  574. if (string.IsNullOrEmpty(str))
  575. {
  576. return defaultValue;
  577. }
  578. else
  579. {
  580. string[] strings = str.Split(cah);
  581. List<string> list = new List<string>();
  582. for (int i = 0; i < strings.Length; i++)
  583. {
  584. list.Add(strings[i]);
  585. }
  586. return list;
  587. }
  588. }
  589. public static List<double> DoubleListParse(char cah, string str, List<double> defaultValue)
  590. {
  591. if (string.IsNullOrEmpty(str))
  592. {
  593. return defaultValue;
  594. }
  595. else
  596. {
  597. string[] strings = str.Split(cah);
  598. List<double> list = new List<double>();
  599. for (int i = 0; i < strings.Length; i++)
  600. {
  601. list.Add(double.Parse(strings[i]));
  602. }
  603. return list;
  604. }
  605. }
  606. }