Auxiliary.cs 19 KB

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