Auxiliary.cs 21 KB

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