Auxiliary.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894
  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. //ManaServer.Download("hsoiv1", data => Debug.Log(data.ToJson()));
  103. }
  104. if (Input.GetKeyDown(KeyCode.X))
  105. {
  106. //ManaMiniGame.GameTimer = 45;
  107. }
  108. if (Input.GetKeyDown(KeyCode.C))
  109. {
  110. //ManaCenter.MiniTimer = 0;
  111. }
  112. if (Input.GetKeyDown(KeyCode.V))
  113. {
  114. //ManaReso.Get("C_MiniGame").TweenBacRect();
  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. // ManaCenter.Coin += 1000;
  130. // ManaCenter.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 GetUnit(int value, Unit unit)
  257. {
  258. if (unit == Unit.Second)
  259. {
  260. if (ManaLan.CurrentLan == Lan.English)
  261. {
  262. if (value == 0 || value == 1)
  263. {
  264. return " Second";
  265. }
  266. else
  267. {
  268. return " Seconds";
  269. }
  270. }
  271. else if (ManaLan.CurrentLan == Lan.ChineseSimplified)
  272. {
  273. return "秒";
  274. }
  275. else if (ManaLan.CurrentLan == Lan.ChineseTraditional)
  276. {
  277. return "秒";
  278. }
  279. else
  280. {
  281. throw new Exception();
  282. }
  283. }
  284. else
  285. {
  286. throw new Exception();
  287. }
  288. }
  289. public static string GetStreamPath()
  290. {
  291. if (Application.isEditor)
  292. {
  293. return "file://" + Application.streamingAssetsPath;
  294. }
  295. else if (Application.platform == RuntimePlatform.IPhonePlayer)
  296. {
  297. return "file://" + Application.streamingAssetsPath;
  298. }
  299. else if (Application.isMobilePlatform)
  300. {
  301. return Application.streamingAssetsPath;
  302. }
  303. else
  304. {
  305. throw new Exception();
  306. }
  307. }
  308. public void DelayCall(UnityAction function, int frame)
  309. {
  310. StartCoroutine(IDelayCall(function, frame));
  311. }
  312. public void DelayCall(UnityAction function, float time)
  313. {
  314. StartCoroutine(IDelayCall(function, time));
  315. }
  316. public static IEnumerator IDelayCall(UnityAction function, int frame)
  317. {
  318. int count = 0;
  319. while (count < frame)
  320. {
  321. count++;
  322. yield return null;
  323. }
  324. function.Invoke();
  325. }
  326. public static IEnumerator IDelayCall(UnityAction function, float time)
  327. {
  328. yield return new WaitForSeconds(time);
  329. function.Invoke();
  330. }
  331. public static string FmlParse1(string str)
  332. {
  333. int index = 0;
  334. int openIndex = 0;
  335. bool flag = false;
  336. bool group = false;
  337. for (int i = 0; i < str.Length; i++)
  338. {
  339. if (group)
  340. {
  341. if (str[i] == '+' || str[i] == '-' || str[i] == '*' || str[i] == '/')
  342. {
  343. str = str.Replace(openIndex, i - 1, FmlParse2(str[index], str.Between(openIndex, index - 1), str.Between(index + 1, i - 1)));
  344. i = 0;
  345. group = false;
  346. }
  347. else if (i == str.Length - 1)
  348. {
  349. str = str.Replace(openIndex, i, FmlParse2(str[index], str.Between(openIndex, index - 1), str.Between(index + 1, i)));
  350. break;
  351. }
  352. }
  353. else
  354. {
  355. if (str[i] == '+' || str[i] == '-')
  356. {
  357. flag = true;
  358. openIndex = i + 1;
  359. }
  360. else if (str[i] == '*' || str[i] == '/')
  361. {
  362. index = i;
  363. group = true;
  364. if (!flag)
  365. {
  366. openIndex = 0;
  367. }
  368. }
  369. }
  370. }
  371. group = false;
  372. for (int i = 0; i < str.Length; i++)
  373. {
  374. if (group)
  375. {
  376. if (str[i] == '+' || str[i] == '-')
  377. {
  378. str = str.Replace(0, i - 1, FmlParse2(str[index], str.Between(0, index - 1), str.Between(index + 1, i - 1)));
  379. i = -1;
  380. group = false;
  381. }
  382. else if (i == str.Length - 1)
  383. {
  384. return FmlParse2(str[index], str.Between(0, index - 1), str.Between(index + 1, i));
  385. }
  386. }
  387. else
  388. {
  389. if (str[i] == '+' || str[i] == '-')
  390. {
  391. index = i;
  392. group = true;
  393. }
  394. }
  395. }
  396. return str;
  397. }
  398. public static string FmlParse2(char op, string str1, string str2)
  399. {
  400. double var1 = double.Parse(str1);
  401. double var2 = double.Parse(str2);
  402. if (op == '+')
  403. {
  404. return (var1 + var2).ToString();
  405. }
  406. else 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
  419. {
  420. throw new Exception(op.ToString());
  421. }
  422. }
  423. public static double FmlParse(string str, params string[] strings)
  424. {
  425. for (int i = 0; i < strings.Length; i += 2)
  426. {
  427. if (str.Contains(strings[i]))
  428. {
  429. str = str.Replace(strings[i], strings[i + 1]);
  430. }
  431. else
  432. {
  433. //Debug.Log("No such var " + strings[i + 1]);
  434. }
  435. }
  436. int openIndex = 0;
  437. for (int i = 0; i < str.Length; i++)
  438. {
  439. if (str[i] == '(')
  440. {
  441. openIndex = i;
  442. }
  443. else if (str[i] == ')')
  444. {
  445. str = str.Replace(openIndex, i, FmlParse1(str.Between(openIndex + 1, i - 1)));
  446. i = -1;
  447. }
  448. }
  449. return double.Parse(FmlParse1(str));
  450. }
  451. public static string OmitNumberStr(int accuray, string str)
  452. {
  453. int index = str.IndexOf('.');
  454. if (index == -1)
  455. {
  456. return str;
  457. }
  458. if (accuray == 0)
  459. {
  460. return str.Substring(0, index);
  461. }
  462. else
  463. {
  464. return str.Substring(0, index + accuray + 1);
  465. }
  466. }
  467. public static long ShrinkNumber(double value, int accuracy = 1)
  468. {
  469. long longValue = (long) value;
  470. if (ManaLan.CurrentLan == Lan.English)
  471. {
  472. if (longValue < Amount.千)
  473. {
  474. return longValue;
  475. }
  476. else if (longValue < Amount.百万)
  477. {
  478. long temp = (long) Amount.百;
  479. return (longValue/ temp) * temp;
  480. }
  481. else if (longValue < Amount.十亿)
  482. {
  483. long temp = (long)Amount.十万;
  484. return (longValue / temp) * temp;
  485. }
  486. else if (longValue < Amount.万亿)
  487. {
  488. long temp = (long)Amount.亿;
  489. return (longValue / temp) * temp;
  490. }
  491. else if (longValue < Amount.千万亿)
  492. {
  493. long temp = (long)Amount.千亿;
  494. return (longValue / temp) * temp;
  495. }
  496. else
  497. {
  498. long temp = (long)Amount.千亿;
  499. return (longValue / temp) * temp;
  500. }
  501. }
  502. else if (ManaLan.CurrentLan == Lan.ChineseSimplified || ManaLan.CurrentLan == Lan.ChineseTraditional)
  503. {
  504. if (longValue < Amount.万)
  505. {
  506. return longValue;
  507. }
  508. else if (longValue < Amount.亿)
  509. {
  510. long temp = (long)Amount.千;
  511. return (longValue / temp) * temp;
  512. }
  513. else if (longValue < Amount.万亿)
  514. {
  515. long temp = (long)Amount.千万;
  516. return (longValue / temp) * temp;
  517. }
  518. else if (longValue < Amount.万万亿)
  519. {
  520. long temp = (long)Amount.千亿;
  521. return (longValue / temp) * temp;
  522. }
  523. else
  524. {
  525. long temp = (long)Amount.千亿;
  526. return (longValue / temp) * temp;
  527. }
  528. }
  529. else
  530. {
  531. throw new Exception();
  532. }
  533. }
  534. public static string ShrinkNumberStr(double value, int accuracy = 1)
  535. {
  536. long longValue = (long) value;
  537. if (ManaLan.CurrentLan == Lan.English)
  538. {
  539. if (longValue < Amount.千)
  540. {
  541. return longValue.ToString();
  542. }
  543. else if (longValue < Amount.百万)
  544. {
  545. string str = (longValue / Amount.千).ToString();
  546. return OmitNumberStr(accuracy, str) + "K";
  547. }
  548. else if (longValue < Amount.十亿)
  549. {
  550. string str = (longValue / Amount.百万).ToString();
  551. return OmitNumberStr(accuracy, str) + "M";
  552. }
  553. else if (longValue < Amount.万亿)
  554. {
  555. string str = (longValue / Amount.十亿).ToString();
  556. return OmitNumberStr(accuracy, str) + "B";
  557. }
  558. else if (longValue < Amount.千万亿)
  559. {
  560. string str = (longValue / Amount.万亿).ToString();
  561. return OmitNumberStr(accuracy, str) + "T";
  562. }
  563. else
  564. {
  565. string str = (longValue / Amount.万亿).ToString();
  566. return OmitNumberStr(accuracy, str) + "T";
  567. }
  568. }
  569. else if (ManaLan.CurrentLan == Lan.ChineseSimplified)
  570. {
  571. if (longValue < Amount.万)
  572. {
  573. return longValue.ToString();
  574. }
  575. else if (longValue < Amount.亿)
  576. {
  577. string str = (longValue/Amount.万).ToString();
  578. return OmitNumberStr(accuracy, str) + "万";
  579. }
  580. else if (longValue < Amount.万亿)
  581. {
  582. string str = (longValue / Amount.亿).ToString();
  583. return OmitNumberStr(accuracy, str) + "亿";
  584. }
  585. else if (longValue < Amount.万万亿)
  586. {
  587. string str = (longValue / Amount.万亿).ToString();
  588. return OmitNumberStr(accuracy, str) + "万亿";
  589. }
  590. else
  591. {
  592. string str = (longValue / Amount.万亿).ToString();
  593. return OmitNumberStr(accuracy, str) + "万亿";
  594. }
  595. }
  596. else if (ManaLan.CurrentLan == Lan.ChineseTraditional)
  597. {
  598. if (longValue < Amount.万)
  599. {
  600. return longValue.ToString();
  601. }
  602. else if (longValue < Amount.亿)
  603. {
  604. string str = (longValue / Amount.万).ToString();
  605. return OmitNumberStr(accuracy, str) + "萬";
  606. }
  607. else if (longValue < Amount.万亿)
  608. {
  609. string str = (longValue / Amount.亿).ToString();
  610. return OmitNumberStr(accuracy, str) + "億";
  611. }
  612. else if (longValue < Amount.万万亿)
  613. {
  614. string str = (longValue / Amount.万亿).ToString();
  615. return OmitNumberStr(accuracy, str) + "萬億";
  616. }
  617. else
  618. {
  619. string str = (longValue / Amount.万亿).ToString();
  620. return OmitNumberStr(accuracy, str) + "萬億";
  621. }
  622. }
  623. else
  624. {
  625. throw new Exception();
  626. }
  627. }
  628. public static int IntParse(string str, int defaultValue)
  629. {
  630. if (string.IsNullOrEmpty(str))
  631. {
  632. return defaultValue;
  633. }
  634. else
  635. {
  636. return int.Parse(str);
  637. }
  638. }
  639. public static long LongParse(string str, long defaultValue)
  640. {
  641. if (string.IsNullOrEmpty(str))
  642. {
  643. return defaultValue;
  644. }
  645. else
  646. {
  647. return long.Parse(str);
  648. }
  649. }
  650. public static bool BoolParse(string str, bool defaultValue)
  651. {
  652. if (string.IsNullOrEmpty(str))
  653. {
  654. return defaultValue;
  655. }
  656. else
  657. {
  658. return Convert.ToBoolean(int.Parse(str));
  659. }
  660. }
  661. public static float FloatParse(string str, float defaultValue)
  662. {
  663. if (string.IsNullOrEmpty(str))
  664. {
  665. return defaultValue;
  666. }
  667. else
  668. {
  669. return float.Parse(str);
  670. }
  671. }
  672. public static double DoubleParse(string str, double defaultValue)
  673. {
  674. if (string.IsNullOrEmpty(str))
  675. {
  676. return defaultValue;
  677. }
  678. else
  679. {
  680. return float.Parse(str);
  681. }
  682. }
  683. public static List<int> IntListParse(char cah, string str, List<int> defaultValue)
  684. {
  685. if (string.IsNullOrEmpty(str))
  686. {
  687. return defaultValue;
  688. }
  689. else
  690. {
  691. string[] strings = str.Split(cah);
  692. List<int> list = new List<int>();
  693. for (int i = 0; i < strings.Length; i++)
  694. {
  695. list.Add(int.Parse(strings[i]));
  696. }
  697. return list;
  698. }
  699. }
  700. public static List<string> StringListParse(char cah, string str, List<string> defaultValue)
  701. {
  702. if (string.IsNullOrEmpty(str))
  703. {
  704. return defaultValue;
  705. }
  706. else
  707. {
  708. string[] strings = str.Split(cah);
  709. List<string> list = new List<string>();
  710. for (int i = 0; i < strings.Length; i++)
  711. {
  712. list.Add(strings[i]);
  713. }
  714. return list;
  715. }
  716. }
  717. public static List<double> DoubleListParse(char cah, string str, List<double> defaultValue)
  718. {
  719. if (string.IsNullOrEmpty(str))
  720. {
  721. return defaultValue;
  722. }
  723. else
  724. {
  725. string[] strings = str.Split(cah);
  726. List<double> list = new List<double>();
  727. for (int i = 0; i < strings.Length; i++)
  728. {
  729. list.Add(double.Parse(strings[i]));
  730. }
  731. return list;
  732. }
  733. }
  734. }