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