Auxiliary.cs 19 KB

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