Auxiliary.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900
  1. using LitJson;
  2. using DragonBones;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.Events;
  6. using UnityEngine.Advertisements;
  7. using System;
  8. using System.IO;
  9. using System.Xml;
  10. using System.Linq;
  11. using System.Net.Mail;
  12. using System.Net;
  13. using System.Text;
  14. using System.Collections;
  15. using System.Collections.Generic;
  16. using System.Security.Cryptography;
  17. using System.Runtime.Serialization.Formatters.Binary;
  18. using System.Security;
  19. using System.Security.Cryptography.Xml;
  20. using Random = UnityEngine.Random;
  21. using Transform = UnityEngine.Transform;
  22. public enum Unit
  23. {
  24. Second
  25. }
  26. public class Amount
  27. {
  28. public static double 百 = 100;
  29. public static double 千 = 1000;
  30. public static double 万 = 10000;
  31. public static double 十万 = 100000;
  32. public static double 百万 = 1000000;
  33. public static double 千万 = 10000000;
  34. public static double 亿 = 100000000;
  35. public static double 十亿 = 1000000000;
  36. public static double 千亿 = 100000000000;
  37. public static double 万亿 = 1000000000000;
  38. public static double 千万亿 = 1000000000000000;
  39. public static double 万万亿 = 10000000000000000;
  40. }
  41. public class Auxiliary : Regist
  42. {
  43. #region 变量
  44. public string String;
  45. public Font Font;
  46. public GameObject Go;
  47. public List<GameObject> GoList;
  48. public List<SpriteRenderer> SrList;
  49. public static bool AnyKeyUp;
  50. public static bool AnyKeyDown;
  51. public static Auxiliary Instance;
  52. public static MD5 MD5
  53. {
  54. get
  55. {
  56. if (_MD5 == null)
  57. {
  58. _MD5 = new MD5CryptoServiceProvider();
  59. }
  60. return _MD5;
  61. }
  62. set { _MD5 = value; }
  63. }
  64. public static DESCryptoServiceProvider Des
  65. {
  66. get
  67. {
  68. if (_Des == null)
  69. {
  70. _Des = new DESCryptoServiceProvider();
  71. _Des.IV = Encoding.UTF8.GetBytes("19283740");
  72. _Des.Key = Encoding.UTF8.GetBytes("93287123");
  73. }
  74. return _Des;
  75. }
  76. set { _Des = value; }
  77. }
  78. private static MD5 _MD5;
  79. private static DESCryptoServiceProvider _Des;
  80. #endregion
  81. public override bool RegistImmed()
  82. {
  83. if (base.RegistImmed())
  84. {
  85. return true;
  86. }
  87. enabled = true;
  88. return false;
  89. }
  90. private void Awake()
  91. {
  92. Instance = this;
  93. }
  94. private void Update()
  95. {
  96. #region 调试
  97. if (Input.GetKeyDown(KeyCode.Escape))
  98. {
  99. }
  100. if (Input.GetKeyDown(KeyCode.Z))
  101. {
  102. //foreach (var kv in ManaGarden.FlowerInfoDic)
  103. //{
  104. // if (kv.Value.Unlock == false)
  105. // {
  106. // kv.Value.Unlock = true;
  107. // }
  108. //}
  109. }
  110. if (Input.GetKeyDown(KeyCode.X))
  111. {
  112. //Application.targetFrameRate = 30;
  113. }
  114. if (Input.GetKeyDown(KeyCode.C))
  115. {
  116. //ManaCenter.MiniTimer = 0;
  117. }
  118. if (Input.GetKeyDown(KeyCode.V))
  119. {
  120. //ManaReso.Get("C_MiniGame").TweenBacRect();
  121. }
  122. //if (Input.GetKeyDown(KeyCode.P))
  123. //{
  124. // ManaData.Level += 20;
  125. //}
  126. //if (Input.GetKeyDown(KeyCode.O))
  127. //{
  128. // for (int i = 0; i < ManaData.SkillList.Count; i++)
  129. // {
  130. // ManaData.SkillList[i].ReceiveCool(1, true, true);
  131. // }
  132. //}
  133. //if (Input.GetKeyDown(KeyCode.I))
  134. //{
  135. // ManaCenter.Coin += 1000;
  136. // ManaCenter.Diamond += 1000;
  137. //}
  138. //if (Input.GetKeyDown(KeyCode.U))
  139. //{
  140. // Data.SavePlayerConfig();
  141. // Data.SaveXml();
  142. //}
  143. //if (Input.GetKeyDown(KeyCode.Y))
  144. //{
  145. // Data.ResetPlayerConfig();
  146. // Data.SaveXml();
  147. //}
  148. //if (Input.GetKeyDown(KeyCode.T))
  149. //{
  150. // ManaData.Pause = !ManaData.Pause;
  151. //}
  152. #endregion
  153. #region 输入检测
  154. if (Input.GetKeyDown(KeyCode.Escape))
  155. {
  156. ManaMiniGame.Pause = true;
  157. Bubble.Show(Language.GetStr("Common", "QuitGame"), null, null, Application.Quit, () => { ManaMiniGame.Pause = false; });
  158. }
  159. if (AnyKeyUp)
  160. {
  161. if (Input.anyKey == false)
  162. {
  163. AnyKeyUp = false;
  164. }
  165. }
  166. if (Input.anyKeyDown)
  167. {
  168. AnyKeyDown = true;
  169. }
  170. if (AnyKeyDown)
  171. {
  172. if (Input.anyKey == false)
  173. {
  174. AnyKeyUp = true;
  175. AnyKeyDown = false;
  176. }
  177. }
  178. #endregion
  179. }
  180. public static byte[] GetMD5(object obj)
  181. {
  182. MemoryStream memoryStream = new MemoryStream();
  183. BinaryFormatter binaryFormatter = new BinaryFormatter();
  184. binaryFormatter.Serialize(memoryStream, obj);
  185. byte[] bytes = memoryStream.GetBuffer();
  186. memoryStream.Dispose();
  187. return MD5.ComputeHash(bytes);
  188. }
  189. public static void EncryptXml(XmlDocument doc)
  190. {
  191. EncryptedXml encryptedXml = new EncryptedXml();
  192. XmlElement xmlElement = doc.DocumentElement;
  193. byte[] bytes = encryptedXml.EncryptData(xmlElement, Des, false);
  194. EncryptedData encryptedData = new EncryptedData();
  195. encryptedData.Type = EncryptedXml.XmlEncElementUrl;
  196. encryptedData.EncryptionMethod = new EncryptionMethod(EncryptedXml.XmlEncDESUrl);
  197. encryptedData.CipherData.CipherValue = bytes;
  198. EncryptedXml.ReplaceElement(xmlElement, encryptedData, false);
  199. }
  200. public static void DecryptXml(XmlDocument doc)
  201. {
  202. EncryptedXml encryptedXml = new EncryptedXml();
  203. XmlElement encryptXmlElement = (XmlElement)doc.GetElementsByTagName("EncryptedData")[0];
  204. EncryptedData encryptedData = new EncryptedData();
  205. encryptedData.LoadXml(encryptXmlElement);
  206. byte[] bytes = encryptedXml.DecryptData(encryptedData, Des);
  207. encryptedXml.ReplaceData(encryptXmlElement, bytes);
  208. }
  209. public static byte[] Encrypt(string str)
  210. {
  211. byte[] bytes = Encoding.UTF8.GetBytes(str);
  212. byte[] encryptBytes = Des.CreateEncryptor().TransformFinalBlock(bytes, 0, bytes.Length);
  213. return encryptBytes;
  214. }
  215. public static byte[] ToBytes(string str)
  216. {
  217. string[] strings = str.Split(' ');
  218. byte[] bytes = new byte[strings.Length];
  219. for (int i = 0; i < bytes.Length; i++)
  220. {
  221. bytes[i] = byte.Parse(strings[i]);
  222. }
  223. return bytes;
  224. }
  225. public static string Decrypt(string str)
  226. {
  227. byte[] encryptBytes = ToBytes(str);
  228. byte[] decryptBytes = Des.CreateDecryptor().TransformFinalBlock(encryptBytes, 0, encryptBytes.Length);
  229. return Encoding.UTF8.GetString(decryptBytes);
  230. }
  231. public static string ToString(byte[] bytes)
  232. {
  233. StringBuilder strB = new StringBuilder();
  234. for (int i = 0; i < bytes.Length; i++)
  235. {
  236. if (i == bytes.Length - 1)
  237. {
  238. strB.Append(bytes[i]);
  239. }
  240. else
  241. {
  242. strB.Append(bytes[i] + " ");
  243. }
  244. }
  245. return strB.ToString();
  246. }
  247. public static void CompileDic(Transform tra, Dictionary<string, Transform> dic)
  248. {
  249. Transform[] transforms = tra.GetComponentsInChildren<Transform>(true);
  250. for (int i = 0; i < transforms.Length; i++)
  251. {
  252. if (dic.ContainsKey(transforms[i].name))
  253. {
  254. throw new Exception(transforms[i].name);
  255. }
  256. else
  257. {
  258. dic.Add(transforms[i].name, transforms[i]);
  259. }
  260. }
  261. }
  262. public static string GetUnit(int value, Unit unit)
  263. {
  264. if (unit == Unit.Second)
  265. {
  266. if (ManaLan.CurrentLan == Lan.English)
  267. {
  268. if (value == 0 || value == 1)
  269. {
  270. return " Second";
  271. }
  272. else
  273. {
  274. return " Seconds";
  275. }
  276. }
  277. else if (ManaLan.CurrentLan == Lan.ChineseSimplified)
  278. {
  279. return "秒";
  280. }
  281. else if (ManaLan.CurrentLan == Lan.ChineseTraditional)
  282. {
  283. return "秒";
  284. }
  285. else
  286. {
  287. throw new Exception();
  288. }
  289. }
  290. else
  291. {
  292. throw new Exception();
  293. }
  294. }
  295. public static string GetStreamPath()
  296. {
  297. if (Application.isEditor)
  298. {
  299. return "file://" + Application.streamingAssetsPath;
  300. }
  301. else if (Application.platform == RuntimePlatform.IPhonePlayer)
  302. {
  303. return "file://" + Application.streamingAssetsPath;
  304. }
  305. else if (Application.isMobilePlatform)
  306. {
  307. return Application.streamingAssetsPath;
  308. }
  309. else
  310. {
  311. throw new Exception();
  312. }
  313. }
  314. public void DelayCall(UnityAction function, int frame)
  315. {
  316. StartCoroutine(IDelayCall(function, frame));
  317. }
  318. public void DelayCall(UnityAction function, float time)
  319. {
  320. StartCoroutine(IDelayCall(function, time));
  321. }
  322. public static IEnumerator IDelayCall(UnityAction function, int frame)
  323. {
  324. int count = 0;
  325. while (count < frame)
  326. {
  327. count++;
  328. yield return null;
  329. }
  330. function.Invoke();
  331. }
  332. public static IEnumerator IDelayCall(UnityAction function, float time)
  333. {
  334. yield return new WaitForSeconds(time);
  335. function.Invoke();
  336. }
  337. public static string FmlParse1(string str)
  338. {
  339. int index = 0;
  340. int openIndex = 0;
  341. bool flag = false;
  342. bool group = false;
  343. for (int i = 0; i < str.Length; i++)
  344. {
  345. if (group)
  346. {
  347. if (str[i] == '+' || str[i] == '-' || str[i] == '*' || str[i] == '/')
  348. {
  349. str = str.Replace(openIndex, i - 1, FmlParse2(str[index], str.Between(openIndex, index - 1), str.Between(index + 1, i - 1)));
  350. i = 0;
  351. group = false;
  352. }
  353. else if (i == str.Length - 1)
  354. {
  355. str = str.Replace(openIndex, i, FmlParse2(str[index], str.Between(openIndex, index - 1), str.Between(index + 1, i)));
  356. break;
  357. }
  358. }
  359. else
  360. {
  361. if (str[i] == '+' || str[i] == '-')
  362. {
  363. flag = true;
  364. openIndex = i + 1;
  365. }
  366. else if (str[i] == '*' || str[i] == '/')
  367. {
  368. index = i;
  369. group = true;
  370. if (!flag)
  371. {
  372. openIndex = 0;
  373. }
  374. }
  375. }
  376. }
  377. group = false;
  378. for (int i = 0; i < str.Length; i++)
  379. {
  380. if (group)
  381. {
  382. if (str[i] == '+' || str[i] == '-')
  383. {
  384. str = str.Replace(0, i - 1, FmlParse2(str[index], str.Between(0, index - 1), str.Between(index + 1, i - 1)));
  385. i = -1;
  386. group = false;
  387. }
  388. else if (i == str.Length - 1)
  389. {
  390. return FmlParse2(str[index], str.Between(0, index - 1), str.Between(index + 1, i));
  391. }
  392. }
  393. else
  394. {
  395. if (str[i] == '+' || str[i] == '-')
  396. {
  397. index = i;
  398. group = true;
  399. }
  400. }
  401. }
  402. return str;
  403. }
  404. public static string FmlParse2(char op, string str1, string str2)
  405. {
  406. double var1 = double.Parse(str1);
  407. double var2 = double.Parse(str2);
  408. if (op == '+')
  409. {
  410. return (var1 + var2).ToString();
  411. }
  412. else if (op == '-')
  413. {
  414. return (var1 - var2).ToString();
  415. }
  416. else if (op == '*')
  417. {
  418. return (var1 * var2).ToString();
  419. }
  420. else if (op == '/')
  421. {
  422. return (var1 / var2).ToString();
  423. }
  424. else
  425. {
  426. throw new Exception(op.ToString());
  427. }
  428. }
  429. public static double FmlParse(string str, params string[] strings)
  430. {
  431. for (int i = 0; i < strings.Length; i += 2)
  432. {
  433. if (str.Contains(strings[i]))
  434. {
  435. str = str.Replace(strings[i], strings[i + 1]);
  436. }
  437. else
  438. {
  439. //Debug.Log("No such var " + strings[i + 1]);
  440. }
  441. }
  442. int openIndex = 0;
  443. for (int i = 0; i < str.Length; i++)
  444. {
  445. if (str[i] == '(')
  446. {
  447. openIndex = i;
  448. }
  449. else if (str[i] == ')')
  450. {
  451. str = str.Replace(openIndex, i, FmlParse1(str.Between(openIndex + 1, i - 1)));
  452. i = -1;
  453. }
  454. }
  455. return double.Parse(FmlParse1(str));
  456. }
  457. public static string OmitNumberStr(int accuray, string str)
  458. {
  459. int index = str.IndexOf('.');
  460. if (index == -1)
  461. {
  462. return str;
  463. }
  464. if (accuray == 0)
  465. {
  466. return str.Substring(0, index);
  467. }
  468. else
  469. {
  470. return str.Substring(0, index + accuray + 1);
  471. }
  472. }
  473. public static long ShrinkNumber(double value, int accuracy = 1)
  474. {
  475. long longValue = (long) value;
  476. if (ManaLan.CurrentLan == Lan.English)
  477. {
  478. if (longValue < Amount.千)
  479. {
  480. return longValue;
  481. }
  482. else if (longValue < Amount.百万)
  483. {
  484. long temp = (long) Amount.百;
  485. return (longValue/ temp) * temp;
  486. }
  487. else if (longValue < Amount.十亿)
  488. {
  489. long temp = (long)Amount.十万;
  490. return (longValue / temp) * temp;
  491. }
  492. else if (longValue < Amount.万亿)
  493. {
  494. long temp = (long)Amount.亿;
  495. return (longValue / temp) * temp;
  496. }
  497. else if (longValue < Amount.千万亿)
  498. {
  499. long temp = (long)Amount.千亿;
  500. return (longValue / temp) * temp;
  501. }
  502. else
  503. {
  504. long temp = (long)Amount.千亿;
  505. return (longValue / temp) * temp;
  506. }
  507. }
  508. else if (ManaLan.CurrentLan == Lan.ChineseSimplified || ManaLan.CurrentLan == Lan.ChineseTraditional)
  509. {
  510. if (longValue < Amount.万)
  511. {
  512. return longValue;
  513. }
  514. else if (longValue < Amount.亿)
  515. {
  516. long temp = (long)Amount.千;
  517. return (longValue / temp) * temp;
  518. }
  519. else if (longValue < Amount.万亿)
  520. {
  521. long temp = (long)Amount.千万;
  522. return (longValue / temp) * temp;
  523. }
  524. else if (longValue < Amount.万万亿)
  525. {
  526. long temp = (long)Amount.千亿;
  527. return (longValue / temp) * temp;
  528. }
  529. else
  530. {
  531. long temp = (long)Amount.千亿;
  532. return (longValue / temp) * temp;
  533. }
  534. }
  535. else
  536. {
  537. throw new Exception();
  538. }
  539. }
  540. public static string ShrinkNumberStr(double value, int accuracy = 1)
  541. {
  542. long longValue = (long) value;
  543. if (ManaLan.CurrentLan == Lan.English)
  544. {
  545. if (longValue < Amount.千)
  546. {
  547. return longValue.ToString();
  548. }
  549. else if (longValue < Amount.百万)
  550. {
  551. string str = (longValue / Amount.千).ToString();
  552. return OmitNumberStr(accuracy, str) + "K";
  553. }
  554. else if (longValue < Amount.十亿)
  555. {
  556. string str = (longValue / Amount.百万).ToString();
  557. return OmitNumberStr(accuracy, str) + "M";
  558. }
  559. else if (longValue < Amount.万亿)
  560. {
  561. string str = (longValue / Amount.十亿).ToString();
  562. return OmitNumberStr(accuracy, str) + "B";
  563. }
  564. else if (longValue < Amount.千万亿)
  565. {
  566. string str = (longValue / Amount.万亿).ToString();
  567. return OmitNumberStr(accuracy, str) + "T";
  568. }
  569. else
  570. {
  571. string str = (longValue / Amount.万亿).ToString();
  572. return OmitNumberStr(accuracy, str) + "T";
  573. }
  574. }
  575. else if (ManaLan.CurrentLan == Lan.ChineseSimplified)
  576. {
  577. if (longValue < Amount.万)
  578. {
  579. return longValue.ToString();
  580. }
  581. else if (longValue < Amount.亿)
  582. {
  583. string str = (longValue/Amount.万).ToString();
  584. return OmitNumberStr(accuracy, str) + "万";
  585. }
  586. else if (longValue < Amount.万亿)
  587. {
  588. string str = (longValue / Amount.亿).ToString();
  589. return OmitNumberStr(accuracy, str) + "亿";
  590. }
  591. else if (longValue < Amount.万万亿)
  592. {
  593. string str = (longValue / Amount.万亿).ToString();
  594. return OmitNumberStr(accuracy, str) + "万亿";
  595. }
  596. else
  597. {
  598. string str = (longValue / Amount.万亿).ToString();
  599. return OmitNumberStr(accuracy, str) + "万亿";
  600. }
  601. }
  602. else if (ManaLan.CurrentLan == Lan.ChineseTraditional)
  603. {
  604. if (longValue < Amount.万)
  605. {
  606. return longValue.ToString();
  607. }
  608. else if (longValue < Amount.亿)
  609. {
  610. string str = (longValue / Amount.万).ToString();
  611. return OmitNumberStr(accuracy, str) + "萬";
  612. }
  613. else if (longValue < Amount.万亿)
  614. {
  615. string str = (longValue / Amount.亿).ToString();
  616. return OmitNumberStr(accuracy, str) + "億";
  617. }
  618. else if (longValue < Amount.万万亿)
  619. {
  620. string str = (longValue / Amount.万亿).ToString();
  621. return OmitNumberStr(accuracy, str) + "萬億";
  622. }
  623. else
  624. {
  625. string str = (longValue / Amount.万亿).ToString();
  626. return OmitNumberStr(accuracy, str) + "萬億";
  627. }
  628. }
  629. else
  630. {
  631. throw new Exception();
  632. }
  633. }
  634. public static int IntParse(string str, int defaultValue)
  635. {
  636. if (string.IsNullOrEmpty(str))
  637. {
  638. return defaultValue;
  639. }
  640. else
  641. {
  642. return int.Parse(str);
  643. }
  644. }
  645. public static long LongParse(string str, long defaultValue)
  646. {
  647. if (string.IsNullOrEmpty(str))
  648. {
  649. return defaultValue;
  650. }
  651. else
  652. {
  653. return long.Parse(str);
  654. }
  655. }
  656. public static bool BoolParse(string str, bool defaultValue)
  657. {
  658. if (string.IsNullOrEmpty(str))
  659. {
  660. return defaultValue;
  661. }
  662. else
  663. {
  664. return Convert.ToBoolean(int.Parse(str));
  665. }
  666. }
  667. public static float FloatParse(string str, float defaultValue)
  668. {
  669. if (string.IsNullOrEmpty(str))
  670. {
  671. return defaultValue;
  672. }
  673. else
  674. {
  675. return float.Parse(str);
  676. }
  677. }
  678. public static double DoubleParse(string str, double defaultValue)
  679. {
  680. if (string.IsNullOrEmpty(str))
  681. {
  682. return defaultValue;
  683. }
  684. else
  685. {
  686. return float.Parse(str);
  687. }
  688. }
  689. public static List<int> IntListParse(char cah, string str, List<int> defaultValue)
  690. {
  691. if (string.IsNullOrEmpty(str))
  692. {
  693. return defaultValue;
  694. }
  695. else
  696. {
  697. string[] strings = str.Split(cah);
  698. List<int> list = new List<int>();
  699. for (int i = 0; i < strings.Length; i++)
  700. {
  701. list.Add(int.Parse(strings[i]));
  702. }
  703. return list;
  704. }
  705. }
  706. public static List<string> StringListParse(char cah, string str, List<string> defaultValue)
  707. {
  708. if (string.IsNullOrEmpty(str))
  709. {
  710. return defaultValue;
  711. }
  712. else
  713. {
  714. string[] strings = str.Split(cah);
  715. List<string> list = new List<string>();
  716. for (int i = 0; i < strings.Length; i++)
  717. {
  718. list.Add(strings[i]);
  719. }
  720. return list;
  721. }
  722. }
  723. public static List<double> DoubleListParse(char cah, string str, List<double> defaultValue)
  724. {
  725. if (string.IsNullOrEmpty(str))
  726. {
  727. return defaultValue;
  728. }
  729. else
  730. {
  731. string[] strings = str.Split(cah);
  732. List<double> list = new List<double>();
  733. for (int i = 0; i < strings.Length; i++)
  734. {
  735. list.Add(double.Parse(strings[i]));
  736. }
  737. return list;
  738. }
  739. }
  740. }