Auxiliary.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822
  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. public UnityAction action;
  88. private void Awake()
  89. {
  90. Instance = this;
  91. action += () => { Debug.Log("2"); };
  92. action = action.AddEventOnetime(() => Debug.Log("1"));
  93. action.SafeInvoke();
  94. action.SafeInvoke();
  95. }
  96. private void Update()
  97. {
  98. #region 调试
  99. if (Input.GetKeyDown(KeyCode.Escape))
  100. {
  101. Debug.Log(Initializer.Complete + " " + ManaServer.Complete + " " + ManaCenter.Complete);
  102. ManaDebug.Log(Initializer.Complete + " " + ManaServer.Complete + " " + ManaCenter.Complete);
  103. }
  104. if (Input.GetKeyDown(KeyCode.Z))
  105. {
  106. }
  107. if (Input.GetKeyDown(KeyCode.X))
  108. {
  109. }
  110. if (Input.GetKeyDown(KeyCode.C))
  111. {
  112. }
  113. if (Input.GetKeyDown(KeyCode.V))
  114. {
  115. }
  116. //if (Input.GetKeyDown(KeyCode.P))
  117. //{
  118. // ManaData.Level += 20;
  119. //}
  120. //if (Input.GetKeyDown(KeyCode.O))
  121. //{
  122. // for (int i = 0; i < ManaData.SkillList.Count; i++)
  123. // {
  124. // ManaData.SkillList[i].ReceiveCool(1, true, true);
  125. // }
  126. //}
  127. //if (Input.GetKeyDown(KeyCode.I))
  128. //{
  129. // ManaData.Coin += 1000;
  130. // ManaData.Diamond += 1000;
  131. //}
  132. //if (Input.GetKeyDown(KeyCode.U))
  133. //{
  134. // Data.SavePlayerConfig();
  135. // Data.SaveXml();
  136. //}
  137. //if (Input.GetKeyDown(KeyCode.Y))
  138. //{
  139. // Data.ResetPlayerConfig();
  140. // Data.SaveXml();
  141. //}
  142. //if (Input.GetKeyDown(KeyCode.T))
  143. //{
  144. // ManaData.Pause = !ManaData.Pause;
  145. //}
  146. #endregion
  147. #region 输入检测
  148. if (Input.GetKeyDown(KeyCode.Escape))
  149. {
  150. ManaMiniGame.Pause = true;
  151. Bubble.Show(Language.GetStr("Common", "QuitGame"), null, null, Application.Quit, () => { ManaMiniGame.Pause = false; });
  152. }
  153. if (AnyKeyUp)
  154. {
  155. if (Input.anyKey == false)
  156. {
  157. AnyKeyUp = false;
  158. }
  159. }
  160. if (Input.anyKeyDown)
  161. {
  162. AnyKeyDown = true;
  163. }
  164. if (AnyKeyDown)
  165. {
  166. if (Input.anyKey == false)
  167. {
  168. AnyKeyUp = true;
  169. AnyKeyDown = false;
  170. }
  171. }
  172. #endregion
  173. }
  174. public static byte[] GetMD5(object obj)
  175. {
  176. MemoryStream memoryStream = new MemoryStream();
  177. BinaryFormatter binaryFormatter = new BinaryFormatter();
  178. binaryFormatter.Serialize(memoryStream, obj);
  179. byte[] bytes = memoryStream.GetBuffer();
  180. memoryStream.Dispose();
  181. return MD5.ComputeHash(bytes);
  182. }
  183. public static void EncryptXml(XmlDocument doc)
  184. {
  185. EncryptedXml encryptedXml = new EncryptedXml();
  186. XmlElement xmlElement = doc.DocumentElement;
  187. byte[] bytes = encryptedXml.EncryptData(xmlElement, Des, false);
  188. EncryptedData encryptedData = new EncryptedData();
  189. encryptedData.Type = EncryptedXml.XmlEncElementUrl;
  190. encryptedData.EncryptionMethod = new EncryptionMethod(EncryptedXml.XmlEncDESUrl);
  191. encryptedData.CipherData.CipherValue = bytes;
  192. EncryptedXml.ReplaceElement(xmlElement, encryptedData, false);
  193. }
  194. public static void DecryptXml(XmlDocument doc)
  195. {
  196. EncryptedXml encryptedXml = new EncryptedXml();
  197. XmlElement encryptXmlElement = (XmlElement)doc.GetElementsByTagName("EncryptedData")[0];
  198. EncryptedData encryptedData = new EncryptedData();
  199. encryptedData.LoadXml(encryptXmlElement);
  200. byte[] bytes = encryptedXml.DecryptData(encryptedData, Des);
  201. encryptedXml.ReplaceData(encryptXmlElement, bytes);
  202. }
  203. public static byte[] Encrypt(string str)
  204. {
  205. byte[] bytes = Encoding.UTF8.GetBytes(str);
  206. byte[] encryptBytes = Des.CreateEncryptor().TransformFinalBlock(bytes, 0, bytes.Length);
  207. return encryptBytes;
  208. }
  209. public static byte[] ToBytes(string str)
  210. {
  211. string[] strings = str.Split(' ');
  212. byte[] bytes = new byte[strings.Length];
  213. for (int i = 0; i < bytes.Length; i++)
  214. {
  215. bytes[i] = byte.Parse(strings[i]);
  216. }
  217. return bytes;
  218. }
  219. public static string Decrypt(string str)
  220. {
  221. byte[] encryptBytes = ToBytes(str);
  222. byte[] decryptBytes = Des.CreateDecryptor().TransformFinalBlock(encryptBytes, 0, encryptBytes.Length);
  223. return Encoding.UTF8.GetString(decryptBytes);
  224. }
  225. public static string ToString(byte[] bytes)
  226. {
  227. StringBuilder strB = new StringBuilder();
  228. for (int i = 0; i < bytes.Length; i++)
  229. {
  230. if (i == bytes.Length - 1)
  231. {
  232. strB.Append(bytes[i]);
  233. }
  234. else
  235. {
  236. strB.Append(bytes[i] + " ");
  237. }
  238. }
  239. return strB.ToString();
  240. }
  241. public static void CompileDic(Transform tra, Dictionary<string, Transform> dic)
  242. {
  243. Transform[] transforms = tra.GetComponentsInChildren<Transform>(true);
  244. for (int i = 0; i < transforms.Length; i++)
  245. {
  246. if (dic.ContainsKey(transforms[i].name))
  247. {
  248. throw new Exception(transforms[i].name);
  249. }
  250. else
  251. {
  252. dic.Add(transforms[i].name, transforms[i]);
  253. }
  254. }
  255. }
  256. public static string GetStreamPath()
  257. {
  258. if (Application.isEditor)
  259. {
  260. return "file://" + Application.streamingAssetsPath;
  261. }
  262. else if (Application.platform == RuntimePlatform.IPhonePlayer)
  263. {
  264. return "file://" + Application.streamingAssetsPath;
  265. }
  266. else if (Application.isMobilePlatform)
  267. {
  268. return Application.streamingAssetsPath;
  269. }
  270. else
  271. {
  272. throw new Exception();
  273. }
  274. }
  275. public void DelayCall(UnityAction function, int frame)
  276. {
  277. StartCoroutine(IDelayCall(function, frame));
  278. }
  279. public void DelayCall(UnityAction function, float time)
  280. {
  281. StartCoroutine(IDelayCall(function, time));
  282. }
  283. public static IEnumerator IDelayCall(UnityAction function, int frame)
  284. {
  285. int count = 0;
  286. while (count < frame)
  287. {
  288. count++;
  289. yield return null;
  290. }
  291. function.Invoke();
  292. }
  293. public static IEnumerator IDelayCall(UnityAction function, float time)
  294. {
  295. yield return new WaitForSeconds(time);
  296. function.Invoke();
  297. }
  298. public static string FmlParse1(string str)
  299. {
  300. int index = 0;
  301. int openIndex = 0;
  302. bool flag = false;
  303. bool group = false;
  304. for (int i = 0; i < str.Length; i++)
  305. {
  306. if (group)
  307. {
  308. if (str[i] == '+' || str[i] == '-' || str[i] == '*' || str[i] == '/')
  309. {
  310. str = str.Replace(openIndex, i - 1, FmlParse2(str[index], str.Between(openIndex, index - 1), str.Between(index + 1, i - 1)));
  311. i = 0;
  312. group = false;
  313. }
  314. else if (i == str.Length - 1)
  315. {
  316. str = str.Replace(openIndex, i, FmlParse2(str[index], str.Between(openIndex, index - 1), str.Between(index + 1, i)));
  317. break;
  318. }
  319. }
  320. else
  321. {
  322. if (str[i] == '+' || str[i] == '-')
  323. {
  324. flag = true;
  325. openIndex = i + 1;
  326. }
  327. else if (str[i] == '*' || str[i] == '/')
  328. {
  329. index = i;
  330. group = true;
  331. if (!flag)
  332. {
  333. openIndex = 0;
  334. }
  335. }
  336. }
  337. }
  338. group = false;
  339. for (int i = 0; i < str.Length; i++)
  340. {
  341. if (group)
  342. {
  343. if (str[i] == '+' || str[i] == '-')
  344. {
  345. str = str.Replace(0, i - 1, FmlParse2(str[index], str.Between(0, index - 1), str.Between(index + 1, i - 1)));
  346. i = -1;
  347. group = false;
  348. }
  349. else if (i == str.Length - 1)
  350. {
  351. return FmlParse2(str[index], str.Between(0, index - 1), str.Between(index + 1, i));
  352. }
  353. }
  354. else
  355. {
  356. if (str[i] == '+' || str[i] == '-')
  357. {
  358. index = i;
  359. group = true;
  360. }
  361. }
  362. }
  363. return str;
  364. }
  365. public static string FmlParse2(char op, string str1, string str2)
  366. {
  367. double var1 = double.Parse(str1);
  368. double var2 = double.Parse(str2);
  369. 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 if (op == '/')
  382. {
  383. return (var1 / var2).ToString();
  384. }
  385. else
  386. {
  387. throw new Exception(op.ToString());
  388. }
  389. }
  390. public static double FmlParse(string str, params string[] strings)
  391. {
  392. for (int i = 0; i < strings.Length; i += 2)
  393. {
  394. str = str.Replace(strings[i], strings[i + 1]);
  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. }