Auxiliary.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  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. #endregion
  125. #region 输入检测
  126. if (Input.GetKeyDown(KeyCode.Escape))
  127. {
  128. ManaMiniGame.Pause = true;
  129. Bubble.Show(Language.GetStr("Common", "QuitGame"), null, null, Application.Quit, () => { ManaMiniGame.Pause = false; });
  130. }
  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 static string GetStreamPath()
  215. {
  216. if (Application.isEditor)
  217. {
  218. return "file://" + Application.streamingAssetsPath;
  219. }
  220. else if (Application.platform == RuntimePlatform.IPhonePlayer)
  221. {
  222. return "file://" + Application.streamingAssetsPath;
  223. }
  224. else if (Application.isMobilePlatform)
  225. {
  226. return Application.streamingAssetsPath;
  227. }
  228. else
  229. {
  230. throw new Exception();
  231. }
  232. }
  233. public void DelayCall(UnityAction function, int frame)
  234. {
  235. StartCoroutine(IDelayCall(function, frame));
  236. }
  237. public void DelayCall(UnityAction function, float time)
  238. {
  239. StartCoroutine(IDelayCall(function, time));
  240. }
  241. public static IEnumerator IDelayCall(UnityAction function, int frame)
  242. {
  243. int count = 0;
  244. while (count < frame)
  245. {
  246. count++;
  247. yield return null;
  248. }
  249. function.Invoke();
  250. }
  251. public static IEnumerator IDelayCall(UnityAction function, float time)
  252. {
  253. yield return new WaitForSeconds(time);
  254. function.Invoke();
  255. }
  256. public static string FmlParse1(string str)
  257. {
  258. int index = 0;
  259. int openIndex = 0;
  260. bool flag = false;
  261. bool group = false;
  262. for (int i = 0; i < str.Length; i++)
  263. {
  264. if (group)
  265. {
  266. if (str[i] == '+' || str[i] == '-' || str[i] == '*' || str[i] == '/')
  267. {
  268. str = str.Replace(openIndex, i - 1, FmlParse2(str[index], str.Between(openIndex, index - 1), str.Between(index + 1, i - 1)));
  269. i = 0;
  270. group = false;
  271. }
  272. else if (i == str.Length - 1)
  273. {
  274. str = str.Replace(openIndex, i, FmlParse2(str[index], str.Between(openIndex, index - 1), str.Between(index + 1, i)));
  275. break;
  276. }
  277. }
  278. else
  279. {
  280. if (str[i] == '+' || str[i] == '-')
  281. {
  282. flag = true;
  283. openIndex = i + 1;
  284. }
  285. else if (str[i] == '*' || str[i] == '/')
  286. {
  287. index = i;
  288. group = true;
  289. if (!flag)
  290. {
  291. openIndex = 0;
  292. }
  293. }
  294. }
  295. }
  296. group = false;
  297. for (int i = 0; i < str.Length; i++)
  298. {
  299. if (group)
  300. {
  301. if (str[i] == '+' || str[i] == '-')
  302. {
  303. str = str.Replace(0, i - 1, FmlParse2(str[index], str.Between(0, index - 1), str.Between(index + 1, i - 1)));
  304. i = -1;
  305. group = false;
  306. }
  307. else if (i == str.Length - 1)
  308. {
  309. return FmlParse2(str[index], str.Between(0, index - 1), str.Between(index + 1, i));
  310. }
  311. }
  312. else
  313. {
  314. if (str[i] == '+' || str[i] == '-')
  315. {
  316. index = i;
  317. group = true;
  318. }
  319. }
  320. }
  321. return str;
  322. }
  323. public static string FmlParse2(char op, string str1, string str2)
  324. {
  325. double var1 = double.Parse(str1);
  326. double var2 = double.Parse(str2);
  327. if (op == '+')
  328. {
  329. return (var1 + var2).ToString();
  330. }
  331. else if (op == '-')
  332. {
  333. return (var1 - var2).ToString();
  334. }
  335. else if (op == '*')
  336. {
  337. return (var1 * var2).ToString();
  338. }
  339. else if (op == '/')
  340. {
  341. return (var1 / var2).ToString();
  342. }
  343. else
  344. {
  345. throw new Exception(op.ToString());
  346. }
  347. }
  348. public static double FmlParse(string str, params string[] strings)
  349. {
  350. for (int i = 0; i < strings.Length; i += 2)
  351. {
  352. str = str.Replace(strings[i], strings[i + 1]);
  353. }
  354. int openIndex = 0;
  355. for (int i = 0; i < str.Length; i++)
  356. {
  357. if (str[i] == '(')
  358. {
  359. openIndex = i;
  360. }
  361. else if (str[i] == ')')
  362. {
  363. str = str.Replace(openIndex, i, FmlParse1(str.Between(openIndex + 1, i - 1)));
  364. i = -1;
  365. }
  366. }
  367. return double.Parse(FmlParse1(str));
  368. }
  369. public static string OmitNumberStr(int accuray, string str)
  370. {
  371. int index = str.IndexOf('.');
  372. if (index == -1)
  373. {
  374. return str;
  375. }
  376. if (accuray == 0)
  377. {
  378. return str.Substring(0, index);
  379. }
  380. else
  381. {
  382. return str.Substring(0, index + accuray + 1);
  383. }
  384. }
  385. public static long ShrinkNumber(double value, int accuracy = 1)
  386. {
  387. long longValue = (long) value;
  388. if (ManaLan.CurrentLan == Lan.English)
  389. {
  390. if (longValue < Amount.千)
  391. {
  392. return longValue;
  393. }
  394. else if (longValue < Amount.百万)
  395. {
  396. long temp = (long) Amount.百;
  397. return (longValue/ temp) * temp;
  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. else if (ManaLan.CurrentLan == Lan.ChineseSimplified || ManaLan.CurrentLan == Lan.ChineseTraditional)
  416. {
  417. if (longValue < Amount.万)
  418. {
  419. return longValue;
  420. }
  421. else if (longValue < Amount.亿)
  422. {
  423. long temp = (long)Amount.千;
  424. return (longValue / temp) * temp;
  425. }
  426. else if (longValue < Amount.万亿)
  427. {
  428. long temp = (long)Amount.千万;
  429. return (longValue / temp) * temp;
  430. }
  431. else if (longValue < Amount.万万亿)
  432. {
  433. long temp = (long)Amount.千亿;
  434. return (longValue / temp) * temp;
  435. }
  436. }
  437. throw new Exception();
  438. }
  439. public static string ShrinkNumberStr(double value, int accuracy = 1)
  440. {
  441. long longValue = (long) value;
  442. if (ManaLan.CurrentLan == Lan.English)
  443. {
  444. if (longValue < Amount.千)
  445. {
  446. return longValue.ToString();
  447. }
  448. else if (longValue < Amount.百万)
  449. {
  450. string str = (longValue / Amount.千).ToString();
  451. return OmitNumberStr(accuracy, str) + "K";
  452. }
  453. else if (longValue < Amount.十亿)
  454. {
  455. string str = (longValue / Amount.百万).ToString();
  456. return OmitNumberStr(accuracy, str) + "M";
  457. }
  458. else if (longValue < Amount.万亿)
  459. {
  460. string str = (longValue / Amount.十亿).ToString();
  461. return OmitNumberStr(accuracy, str) + "B";
  462. }
  463. else if (longValue < Amount.千万亿)
  464. {
  465. string str = (longValue / Amount.万亿).ToString();
  466. return OmitNumberStr(accuracy, str) + "T";
  467. }
  468. }
  469. else if (ManaLan.CurrentLan == Lan.ChineseSimplified)
  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. else if (ManaLan.CurrentLan == Lan.ChineseTraditional)
  492. {
  493. if (longValue < Amount.万)
  494. {
  495. return longValue.ToString();
  496. }
  497. else if (longValue < Amount.亿)
  498. {
  499. string str = (longValue / Amount.万).ToString();
  500. return OmitNumberStr(accuracy, str) + "萬";
  501. }
  502. else if (longValue < Amount.万亿)
  503. {
  504. string str = (longValue / Amount.亿).ToString();
  505. return OmitNumberStr(accuracy, str) + "億";
  506. }
  507. else if (longValue < Amount.万万亿)
  508. {
  509. string str = (longValue / Amount.万亿).ToString();
  510. return OmitNumberStr(accuracy, str) + "萬億";
  511. }
  512. }
  513. throw new Exception();
  514. }
  515. public static int IntParse(string str, int defaultValue)
  516. {
  517. if (string.IsNullOrEmpty(str))
  518. {
  519. return defaultValue;
  520. }
  521. else
  522. {
  523. return int.Parse(str);
  524. }
  525. }
  526. public static long LongParse(string str, long defaultValue)
  527. {
  528. if (string.IsNullOrEmpty(str))
  529. {
  530. return defaultValue;
  531. }
  532. else
  533. {
  534. return long.Parse(str);
  535. }
  536. }
  537. public static bool BoolParse(string str, bool defaultValue)
  538. {
  539. if (string.IsNullOrEmpty(str))
  540. {
  541. return defaultValue;
  542. }
  543. else
  544. {
  545. return Convert.ToBoolean(int.Parse(str));
  546. }
  547. }
  548. public static float FloatParse(string str, float defaultValue)
  549. {
  550. if (string.IsNullOrEmpty(str))
  551. {
  552. return defaultValue;
  553. }
  554. else
  555. {
  556. return float.Parse(str);
  557. }
  558. }
  559. public static double DoubleParse(string str, double defaultValue)
  560. {
  561. if (string.IsNullOrEmpty(str))
  562. {
  563. return defaultValue;
  564. }
  565. else
  566. {
  567. return float.Parse(str);
  568. }
  569. }
  570. public static List<int> IntListParse(char cah, string str, List<int> defaultValue)
  571. {
  572. if (string.IsNullOrEmpty(str))
  573. {
  574. return defaultValue;
  575. }
  576. else
  577. {
  578. string[] strings = str.Split(cah);
  579. List<int> list = new List<int>();
  580. for (int i = 0; i < strings.Length; i++)
  581. {
  582. list.Add(int.Parse(strings[i]));
  583. }
  584. return list;
  585. }
  586. }
  587. public static List<string> StringListParse(char cah, string str, List<string> defaultValue)
  588. {
  589. if (string.IsNullOrEmpty(str))
  590. {
  591. return defaultValue;
  592. }
  593. else
  594. {
  595. string[] strings = str.Split(cah);
  596. List<string> list = new List<string>();
  597. for (int i = 0; i < strings.Length; i++)
  598. {
  599. list.Add(strings[i]);
  600. }
  601. return list;
  602. }
  603. }
  604. public static List<double> DoubleListParse(char cah, string str, List<double> defaultValue)
  605. {
  606. if (string.IsNullOrEmpty(str))
  607. {
  608. return defaultValue;
  609. }
  610. else
  611. {
  612. string[] strings = str.Split(cah);
  613. List<double> list = new List<double>();
  614. for (int i = 0; i < strings.Length; i++)
  615. {
  616. list.Add(double.Parse(strings[i]));
  617. }
  618. return list;
  619. }
  620. }
  621. }