Auxiliary.cs 20 KB

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