Auxiliary.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  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 bool RegistImmed()
  79. {
  80. if (base.RegistImmed())
  81. {
  82. return true;
  83. }
  84. enabled = true;
  85. return false;
  86. }
  87. private void Awake()
  88. {
  89. Instance = this;
  90. }
  91. private void Update()
  92. {
  93. #region 调试
  94. if (Input.GetKeyDown(KeyCode.Escape))
  95. {
  96. }
  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. if (str.Contains(strings[i]))
  388. {
  389. str = str.Replace(strings[i], strings[i + 1]);
  390. }
  391. else
  392. {
  393. //Debug.Log("No such var " + strings[i + 1]);
  394. }
  395. }
  396. int openIndex = 0;
  397. for (int i = 0; i < str.Length; i++)
  398. {
  399. if (str[i] == '(')
  400. {
  401. openIndex = i;
  402. }
  403. else if (str[i] == ')')
  404. {
  405. str = str.Replace(openIndex, i, FmlParse1(str.Between(openIndex + 1, i - 1)));
  406. i = -1;
  407. }
  408. }
  409. return double.Parse(FmlParse1(str));
  410. }
  411. public static string OmitNumberStr(int accuray, string str)
  412. {
  413. int index = str.IndexOf('.');
  414. if (index == -1)
  415. {
  416. return str;
  417. }
  418. if (accuray == 0)
  419. {
  420. return str.Substring(0, index);
  421. }
  422. else
  423. {
  424. return str.Substring(0, index + accuray + 1);
  425. }
  426. }
  427. public static long ShrinkNumber(double value, int accuracy = 1)
  428. {
  429. long longValue = (long) value;
  430. if (ManaLan.CurrentLan == Lan.English)
  431. {
  432. if (longValue < Amount.千)
  433. {
  434. return longValue;
  435. }
  436. else if (longValue < Amount.百万)
  437. {
  438. long temp = (long) Amount.百;
  439. return (longValue/ temp) * temp;
  440. }
  441. else if (longValue < Amount.十亿)
  442. {
  443. long temp = (long)Amount.十万;
  444. return (longValue / temp) * temp;
  445. }
  446. else if (longValue < Amount.万亿)
  447. {
  448. long temp = (long)Amount.亿;
  449. return (longValue / temp) * temp;
  450. }
  451. else if (longValue < Amount.千万亿)
  452. {
  453. long temp = (long)Amount.千亿;
  454. return (longValue / temp) * temp;
  455. }
  456. }
  457. else if (ManaLan.CurrentLan == Lan.ChineseSimplified || ManaLan.CurrentLan == Lan.ChineseTraditional)
  458. {
  459. if (longValue < Amount.万)
  460. {
  461. return longValue;
  462. }
  463. else if (longValue < Amount.亿)
  464. {
  465. long temp = (long)Amount.千;
  466. return (longValue / temp) * temp;
  467. }
  468. else if (longValue < Amount.万亿)
  469. {
  470. long temp = (long)Amount.千万;
  471. return (longValue / temp) * temp;
  472. }
  473. else if (longValue < Amount.万万亿)
  474. {
  475. long temp = (long)Amount.千亿;
  476. return (longValue / temp) * temp;
  477. }
  478. }
  479. throw new Exception();
  480. }
  481. public static string ShrinkNumberStr(double value, int accuracy = 1)
  482. {
  483. long longValue = (long) value;
  484. if (ManaLan.CurrentLan == Lan.English)
  485. {
  486. if (longValue < Amount.千)
  487. {
  488. return longValue.ToString();
  489. }
  490. else if (longValue < Amount.百万)
  491. {
  492. string str = (longValue / Amount.千).ToString();
  493. return OmitNumberStr(accuracy, str) + "K";
  494. }
  495. else if (longValue < Amount.十亿)
  496. {
  497. string str = (longValue / Amount.百万).ToString();
  498. return OmitNumberStr(accuracy, str) + "M";
  499. }
  500. else if (longValue < Amount.万亿)
  501. {
  502. string str = (longValue / Amount.十亿).ToString();
  503. return OmitNumberStr(accuracy, str) + "B";
  504. }
  505. else if (longValue < Amount.千万亿)
  506. {
  507. string str = (longValue / Amount.万亿).ToString();
  508. return OmitNumberStr(accuracy, str) + "T";
  509. }
  510. }
  511. else if (ManaLan.CurrentLan == Lan.ChineseSimplified)
  512. {
  513. if (longValue < Amount.万)
  514. {
  515. return longValue.ToString();
  516. }
  517. else if (longValue < Amount.亿)
  518. {
  519. string str = (longValue/Amount.万).ToString();
  520. return OmitNumberStr(accuracy, str) + "万";
  521. }
  522. else if (longValue < Amount.万亿)
  523. {
  524. string str = (longValue / Amount.亿).ToString();
  525. return OmitNumberStr(accuracy, str) + "亿";
  526. }
  527. else if (longValue < Amount.万万亿)
  528. {
  529. string str = (longValue / Amount.万亿).ToString();
  530. return OmitNumberStr(accuracy, str) + "万亿";
  531. }
  532. }
  533. else if (ManaLan.CurrentLan == Lan.ChineseTraditional)
  534. {
  535. if (longValue < Amount.万)
  536. {
  537. return longValue.ToString();
  538. }
  539. else if (longValue < Amount.亿)
  540. {
  541. string str = (longValue / Amount.万).ToString();
  542. return OmitNumberStr(accuracy, str) + "萬";
  543. }
  544. else if (longValue < Amount.万亿)
  545. {
  546. string str = (longValue / Amount.亿).ToString();
  547. return OmitNumberStr(accuracy, str) + "億";
  548. }
  549. else if (longValue < Amount.万万亿)
  550. {
  551. string str = (longValue / Amount.万亿).ToString();
  552. return OmitNumberStr(accuracy, str) + "萬億";
  553. }
  554. }
  555. throw new Exception();
  556. }
  557. public static int IntParse(string str, int defaultValue)
  558. {
  559. if (string.IsNullOrEmpty(str))
  560. {
  561. return defaultValue;
  562. }
  563. else
  564. {
  565. return int.Parse(str);
  566. }
  567. }
  568. public static long LongParse(string str, long defaultValue)
  569. {
  570. if (string.IsNullOrEmpty(str))
  571. {
  572. return defaultValue;
  573. }
  574. else
  575. {
  576. return long.Parse(str);
  577. }
  578. }
  579. public static bool BoolParse(string str, bool defaultValue)
  580. {
  581. if (string.IsNullOrEmpty(str))
  582. {
  583. return defaultValue;
  584. }
  585. else
  586. {
  587. return Convert.ToBoolean(int.Parse(str));
  588. }
  589. }
  590. public static float FloatParse(string str, float defaultValue)
  591. {
  592. if (string.IsNullOrEmpty(str))
  593. {
  594. return defaultValue;
  595. }
  596. else
  597. {
  598. return float.Parse(str);
  599. }
  600. }
  601. public static double DoubleParse(string str, double defaultValue)
  602. {
  603. if (string.IsNullOrEmpty(str))
  604. {
  605. return defaultValue;
  606. }
  607. else
  608. {
  609. return float.Parse(str);
  610. }
  611. }
  612. public static List<int> IntListParse(char cah, string str, List<int> defaultValue)
  613. {
  614. if (string.IsNullOrEmpty(str))
  615. {
  616. return defaultValue;
  617. }
  618. else
  619. {
  620. string[] strings = str.Split(cah);
  621. List<int> list = new List<int>();
  622. for (int i = 0; i < strings.Length; i++)
  623. {
  624. list.Add(int.Parse(strings[i]));
  625. }
  626. return list;
  627. }
  628. }
  629. public static List<string> StringListParse(char cah, string str, List<string> defaultValue)
  630. {
  631. if (string.IsNullOrEmpty(str))
  632. {
  633. return defaultValue;
  634. }
  635. else
  636. {
  637. string[] strings = str.Split(cah);
  638. List<string> list = new List<string>();
  639. for (int i = 0; i < strings.Length; i++)
  640. {
  641. list.Add(strings[i]);
  642. }
  643. return list;
  644. }
  645. }
  646. public static List<double> DoubleListParse(char cah, string str, List<double> defaultValue)
  647. {
  648. if (string.IsNullOrEmpty(str))
  649. {
  650. return defaultValue;
  651. }
  652. else
  653. {
  654. string[] strings = str.Split(cah);
  655. List<double> list = new List<double>();
  656. for (int i = 0; i < strings.Length; i++)
  657. {
  658. list.Add(double.Parse(strings[i]));
  659. }
  660. return list;
  661. }
  662. }
  663. }