Auxiliary.cs 20 KB

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