Auxiliary.cs 20 KB

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