Auxiliary.cs 20 KB

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