Auxiliary.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  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.Text;
  10. using System.Collections;
  11. using System.Collections.Generic;
  12. using System.Security.Cryptography;
  13. using System.Runtime.Serialization.Formatters.Binary;
  14. using Random = UnityEngine.Random;
  15. using Transform = UnityEngine.Transform;
  16. public class Amount
  17. {
  18. public static double 百 = 100;
  19. public static double 千 = 1000;
  20. public static double 万 = 10000;
  21. public static double 十万 = 100000;
  22. public static double 百万 = 1000000;
  23. public static double 千万 = 10000000;
  24. public static double 亿 = 100000000;
  25. public static double 十亿 = 1000000000;
  26. public static double 千亿 = 100000000000;
  27. public static double 万亿 = 1000000000000;
  28. public static double 千万亿 = 1000000000000000;
  29. public static double 万万亿 = 10000000000000000;
  30. }
  31. public class Auxiliary : MonoBehaviour
  32. {
  33. #region 变量
  34. public string String;
  35. public Font Font;
  36. public GameObject Go;
  37. public List<GameObject> GoList;
  38. public List<SpriteRenderer> SrList;
  39. public static bool AnyKeyUp;
  40. public static bool AnyKeyDown;
  41. public static Auxiliary Instance;
  42. public static MD5 MD5
  43. {
  44. get
  45. {
  46. if (_MD5 == null)
  47. {
  48. _MD5 = new MD5CryptoServiceProvider();
  49. }
  50. return _MD5;
  51. }
  52. set { _MD5 = value; }
  53. }
  54. public static DESCryptoServiceProvider Des
  55. {
  56. get
  57. {
  58. if (_Des == null)
  59. {
  60. _Des = new DESCryptoServiceProvider();
  61. _Des.IV = Encoding.UTF8.GetBytes("12345678");
  62. _Des.Key = Encoding.UTF8.GetBytes("12345678");
  63. }
  64. return _Des;
  65. }
  66. set { _Des = value; }
  67. }
  68. private static MD5 _MD5;
  69. private static DESCryptoServiceProvider _Des;
  70. #endregion
  71. private void Awake()
  72. {
  73. Instance = this;
  74. }
  75. private void Update()
  76. {
  77. #region 调试
  78. //if (Input.GetKeyDown(KeyCode.Z))
  79. //{
  80. // ManaServer.Save();
  81. //}
  82. //if (Input.GetKeyDown(KeyCode.X))
  83. //{
  84. // ManaServer.Load();
  85. //}
  86. if (Input.GetKeyDown(KeyCode.Space))
  87. {
  88. ManaData.Coin = 0;
  89. }
  90. if (Input.GetKeyDown(KeyCode.P))
  91. {
  92. ManaData.Level += 20;
  93. }
  94. if (Input.GetKeyDown(KeyCode.O))
  95. {
  96. for (int i = 0; i < ManaData.SkillList.Count; i++)
  97. {
  98. ManaData.SkillList[i].ReceiveCool(1, true, true);
  99. }
  100. }
  101. if (Input.GetKeyDown(KeyCode.I))
  102. {
  103. ManaData.Coin += 1000;
  104. ManaData.Diamond += 1000;
  105. }
  106. if (Input.GetKeyDown(KeyCode.U))
  107. {
  108. Data.SavePlayerConfig();
  109. }
  110. if (Input.GetKeyDown(KeyCode.Y))
  111. {
  112. Data.ResetPlayerConfig();
  113. }
  114. if (Input.GetKeyDown(KeyCode.T))
  115. {
  116. ManaData.Pause = !ManaData.Pause;
  117. }
  118. if (Input.GetKeyDown(KeyCode.Escape))
  119. {
  120. ManaReso.Get("K_QuitGame").TweenForCG();
  121. }
  122. #endregion
  123. #region 输入检测
  124. if (AnyKeyUp)
  125. {
  126. if (Input.anyKey == false)
  127. {
  128. AnyKeyUp = false;
  129. }
  130. }
  131. if (Input.anyKeyDown)
  132. {
  133. AnyKeyDown = true;
  134. }
  135. if (AnyKeyDown)
  136. {
  137. if (Input.anyKey == false)
  138. {
  139. AnyKeyUp = true;
  140. AnyKeyDown = false;
  141. }
  142. }
  143. #endregion
  144. }
  145. public static byte[] GetMD5(object obj)
  146. {
  147. MemoryStream memoryStream = new MemoryStream();
  148. BinaryFormatter binaryFormatter = new BinaryFormatter();
  149. binaryFormatter.Serialize(memoryStream, obj);
  150. byte[] bytes = memoryStream.GetBuffer();
  151. memoryStream.Dispose();
  152. return MD5.ComputeHash(bytes);
  153. }
  154. public static byte[] Encrypt(string str)
  155. {
  156. byte[] bytes = Encoding.UTF8.GetBytes(str);
  157. byte[] encryptBytes = Des.CreateEncryptor().TransformFinalBlock(bytes, 0, bytes.Length);
  158. return encryptBytes;
  159. }
  160. public static byte[] ToBytes(string str)
  161. {
  162. string[] strings = str.Split(' ');
  163. byte[] bytes = new byte[strings.Length];
  164. for (int i = 0; i < bytes.Length; i++)
  165. {
  166. bytes[i] = byte.Parse(strings[i]);
  167. }
  168. return bytes;
  169. }
  170. public static string Decrypt(string str)
  171. {
  172. byte[] encryptBytes = ToBytes(str);
  173. byte[] decryptBytes = Des.CreateDecryptor().TransformFinalBlock(encryptBytes, 0, encryptBytes.Length);
  174. return Encoding.UTF8.GetString(decryptBytes);
  175. }
  176. public static string ToString(byte[] bytes)
  177. {
  178. StringBuilder strB = new StringBuilder();
  179. for (int i = 0; i < bytes.Length; i++)
  180. {
  181. if (i == bytes.Length - 1)
  182. {
  183. strB.Append(bytes[i]);
  184. }
  185. else
  186. {
  187. strB.Append(bytes[i] + " ");
  188. }
  189. }
  190. return strB.ToString();
  191. }
  192. public static void CompileDic(Transform tra, Dictionary<string, Transform> dic)
  193. {
  194. Transform[] transforms = tra.GetComponentsInChildren<Transform>(true);
  195. for (int i = 0; i < transforms.Length; i++)
  196. {
  197. if (dic.ContainsKey(transforms[i].name))
  198. {
  199. throw new Exception(transforms[i].name);
  200. }
  201. else
  202. {
  203. dic.Add(transforms[i].name, transforms[i]);
  204. }
  205. }
  206. }
  207. public void DelayCall(UnityAction function, int frame)
  208. {
  209. StartCoroutine(IDelayCall(function, frame));
  210. }
  211. public void DelayCall(UnityAction function, float time)
  212. {
  213. StartCoroutine(IDelayCall(function, time));
  214. }
  215. public static IEnumerator IDelayCall(UnityAction function, int frame)
  216. {
  217. int count = 0;
  218. if (count++ < frame)
  219. {
  220. yield return null;
  221. }
  222. function.Invoke();
  223. }
  224. public static IEnumerator IDelayCall(UnityAction function, float time)
  225. {
  226. yield return new WaitForSeconds(time);
  227. function.Invoke();
  228. }
  229. public static string FmlParse1(string str)
  230. {
  231. int index = 0;
  232. int openIndex = 0;
  233. bool flag = false;
  234. bool group = false;
  235. for (int i = 0; i < str.Length; i++)
  236. {
  237. if (group)
  238. {
  239. if (str[i] == '+' || str[i] == '-' || str[i] == '*' || str[i] == '/')
  240. {
  241. str = str.Replace(openIndex, i - 1, FmlParse2(str[index], str.Between(openIndex, index - 1), str.Between(index + 1, i - 1)));
  242. i = 0;
  243. group = false;
  244. }
  245. else if (i == str.Length - 1)
  246. {
  247. str = str.Replace(openIndex, i, FmlParse2(str[index], str.Between(openIndex, index - 1), str.Between(index + 1, i)));
  248. break;
  249. }
  250. }
  251. else
  252. {
  253. if (str[i] == '+' || str[i] == '-')
  254. {
  255. flag = true;
  256. openIndex = i + 1;
  257. }
  258. else if (str[i] == '*' || str[i] == '/')
  259. {
  260. index = i;
  261. group = true;
  262. if (!flag)
  263. {
  264. openIndex = 0;
  265. }
  266. }
  267. }
  268. }
  269. group = false;
  270. for (int i = 0; i < str.Length; i++)
  271. {
  272. if (group)
  273. {
  274. if (str[i] == '+' || str[i] == '-')
  275. {
  276. str = str.Replace(0, i - 1, FmlParse2(str[index], str.Between(0, index - 1), str.Between(index + 1, i - 1)));
  277. i = -1;
  278. group = false;
  279. }
  280. else if (i == str.Length - 1)
  281. {
  282. return FmlParse2(str[index], str.Between(0, index - 1), str.Between(index + 1, i));
  283. }
  284. }
  285. else
  286. {
  287. if (str[i] == '+' || str[i] == '-')
  288. {
  289. index = i;
  290. group = true;
  291. }
  292. }
  293. }
  294. return str;
  295. }
  296. public static string FmlParse2(char op, string str1, string str2)
  297. {
  298. double var1 = double.Parse(str1);
  299. double var2 = double.Parse(str2);
  300. if (op == '+')
  301. {
  302. return (var1 + var2).ToString();
  303. }
  304. else if (op == '-')
  305. {
  306. return (var1 - var2).ToString();
  307. }
  308. else if (op == '*')
  309. {
  310. return (var1 * var2).ToString();
  311. }
  312. else if (op == '/')
  313. {
  314. return (var1 / var2).ToString();
  315. }
  316. else
  317. {
  318. throw new Exception(op.ToString());
  319. }
  320. }
  321. public static double FmlParse(string str, params string[] strings)
  322. {
  323. for (int i = 0; i < strings.Length; i += 2)
  324. {
  325. str = str.Replace(strings[i], strings[i + 1]);
  326. }
  327. int openIndex = 0;
  328. for (int i = 0; i < str.Length; i++)
  329. {
  330. if (str[i] == '(')
  331. {
  332. openIndex = i;
  333. }
  334. else if (str[i] == ')')
  335. {
  336. str = str.Replace(openIndex, i, FmlParse1(str.Between(openIndex + 1, i - 1)));
  337. i = -1;
  338. }
  339. }
  340. return double.Parse(FmlParse1(str));
  341. }
  342. public static string OmitNumberStr(int accuray, string str)
  343. {
  344. int index = str.IndexOf('.');
  345. if (index == -1)
  346. {
  347. return str;
  348. }
  349. if (accuray == 0)
  350. {
  351. return str.Substring(0, index);
  352. }
  353. else
  354. {
  355. return str.Substring(0, index + accuray + 1);
  356. }
  357. }
  358. public static long ShrinkNumber(double value, int accuracy = 1)
  359. {
  360. long longValue = (long) value;
  361. if (ManaLan.CurrentLan == Lan.English)
  362. {
  363. if (longValue < Amount.千)
  364. {
  365. return longValue;
  366. }
  367. else if (longValue < Amount.百万)
  368. {
  369. long temp = (long) Amount.百;
  370. return (longValue/ temp) * temp;
  371. }
  372. else if (longValue < Amount.十亿)
  373. {
  374. long temp = (long)Amount.十万;
  375. return (longValue / temp) * temp;
  376. }
  377. else if (longValue < Amount.万亿)
  378. {
  379. long temp = (long)Amount.亿;
  380. return (longValue / temp) * temp;
  381. }
  382. else if (longValue < Amount.千万亿)
  383. {
  384. long temp = (long)Amount.千亿;
  385. return (longValue / temp) * temp;
  386. }
  387. }
  388. else if (ManaLan.CurrentLan == Lan.ChineseSimplified)
  389. {
  390. if (longValue < Amount.万)
  391. {
  392. return longValue;
  393. }
  394. else if (longValue < Amount.亿)
  395. {
  396. long temp = (long)Amount.千;
  397. return (longValue / temp) * temp;
  398. }
  399. else if (longValue < Amount.万亿)
  400. {
  401. long temp = (long)Amount.千万;
  402. return (longValue / temp) * temp;
  403. }
  404. else if (longValue < Amount.万万亿)
  405. {
  406. long temp = (long)Amount.千亿;
  407. return (longValue / temp) * temp;
  408. }
  409. }
  410. throw new Exception();
  411. }
  412. public static string ShrinkNumberStr(double value, int accuracy = 1)
  413. {
  414. long longValue = (long) value;
  415. if (ManaLan.CurrentLan == Lan.English)
  416. {
  417. if (longValue < Amount.千)
  418. {
  419. return longValue.ToString();
  420. }
  421. else if (longValue < Amount.百万)
  422. {
  423. string str = (longValue / Amount.千).ToString();
  424. return OmitNumberStr(accuracy, str) + "K";
  425. }
  426. else if (longValue < Amount.十亿)
  427. {
  428. string str = (longValue / Amount.百万).ToString();
  429. return OmitNumberStr(accuracy, str) + "M";
  430. }
  431. else if (longValue < Amount.万亿)
  432. {
  433. string str = (longValue / Amount.十亿).ToString();
  434. return OmitNumberStr(accuracy, str) + "B";
  435. }
  436. else if (longValue < Amount.千万亿)
  437. {
  438. string str = (longValue / Amount.万亿).ToString();
  439. return OmitNumberStr(accuracy, str) + "T";
  440. }
  441. }
  442. else if (ManaLan.CurrentLan == Lan.ChineseSimplified)
  443. {
  444. if (longValue < Amount.万)
  445. {
  446. return longValue.ToString();
  447. }
  448. else if (longValue < Amount.亿)
  449. {
  450. string str = (longValue/Amount.万).ToString();
  451. return OmitNumberStr(accuracy, str) + "万";
  452. }
  453. else if (longValue < Amount.万亿)
  454. {
  455. string str = (longValue / Amount.亿).ToString();
  456. return OmitNumberStr(accuracy, str) + "亿";
  457. }
  458. else if (longValue < Amount.万万亿)
  459. {
  460. string str = (longValue / Amount.万亿).ToString();
  461. return OmitNumberStr(accuracy, str) + "万亿";
  462. }
  463. }
  464. throw new Exception();
  465. }
  466. public static int IntParse(string str, int defaultValue)
  467. {
  468. if (string.IsNullOrEmpty(str))
  469. {
  470. return defaultValue;
  471. }
  472. else
  473. {
  474. return int.Parse(str);
  475. }
  476. }
  477. public static bool BoolParse(string str, bool defaultValue)
  478. {
  479. if (string.IsNullOrEmpty(str))
  480. {
  481. return defaultValue;
  482. }
  483. else
  484. {
  485. return Convert.ToBoolean(int.Parse(str));
  486. }
  487. }
  488. public static float FloatParse(string str, float defaultValue)
  489. {
  490. if (string.IsNullOrEmpty(str))
  491. {
  492. return defaultValue;
  493. }
  494. else
  495. {
  496. return float.Parse(str);
  497. }
  498. }
  499. public static double DoubleParse(string str, double defaultValue)
  500. {
  501. if (string.IsNullOrEmpty(str))
  502. {
  503. return defaultValue;
  504. }
  505. else
  506. {
  507. return float.Parse(str);
  508. }
  509. }
  510. public static List<int> IntListParse(char cah, string str, List<int> defaultValue)
  511. {
  512. if (string.IsNullOrEmpty(str))
  513. {
  514. return defaultValue;
  515. }
  516. else
  517. {
  518. string[] strings = str.Split(cah);
  519. List<int> list = new List<int>();
  520. for (int i = 0; i < strings.Length; i++)
  521. {
  522. list.Add(int.Parse(strings[i]));
  523. }
  524. return list;
  525. }
  526. }
  527. public static List<string> StringListParse(char cah, string str, List<string> defaultValue)
  528. {
  529. if (string.IsNullOrEmpty(str))
  530. {
  531. return defaultValue;
  532. }
  533. else
  534. {
  535. string[] strings = str.Split(cah);
  536. List<string> list = new List<string>();
  537. for (int i = 0; i < strings.Length; i++)
  538. {
  539. list.Add(strings[i]);
  540. }
  541. return list;
  542. }
  543. }
  544. public static List<double> DoubleListParse(char cah, string str, List<double> defaultValue)
  545. {
  546. if (string.IsNullOrEmpty(str))
  547. {
  548. return defaultValue;
  549. }
  550. else
  551. {
  552. string[] strings = str.Split(cah);
  553. List<double> list = new List<double>();
  554. for (int i = 0; i < strings.Length; i++)
  555. {
  556. list.Add(double.Parse(strings[i]));
  557. }
  558. return list;
  559. }
  560. }
  561. }