Auxiliary.cs 19 KB

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