Auxiliary.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260
  1. using LitJson;
  2. using MiniJSON;
  3. using ScottGarland;
  4. using DragonBones;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. using UnityEngine.Events;
  8. using UnityEngine.Advertisements;
  9. using System;
  10. using System.IO;
  11. using System.Xml;
  12. using System.Linq;
  13. using System.Net.Mail;
  14. using System.Net;
  15. using System.Text;
  16. using System.Collections;
  17. using System.Diagnostics;
  18. using System.Collections.Generic;
  19. using System.ComponentModel.Design;
  20. using System.Security.Cryptography;
  21. using System.Runtime.Serialization.Formatters.Binary;
  22. using System.Security;
  23. using System.Text.RegularExpressions;
  24. using System.Security.Cryptography.Xml;
  25. using Sfs2X.Entities.Data;
  26. using Sfs2X.Requests;
  27. using Debug = UnityEngine.Debug;
  28. using Random = UnityEngine.Random;
  29. using Transform = UnityEngine.Transform;
  30. public enum Unit
  31. {
  32. Second
  33. }
  34. public class Amount
  35. {
  36. public static double 百 = 100;
  37. public static double 千 = 1000;
  38. public static double 万 = 10000;
  39. public static double 十万 = 100000;
  40. public static double 百万 = 1000000;
  41. public static double 千万 = 10000000;
  42. public static double 亿 = 100000000;
  43. public static double 十亿 = 1000000000;
  44. public static double 千亿 = 100000000000;
  45. public static double 兆 = 1000000000000;
  46. public static double 千兆 = 1000000000000000;
  47. public static double 京 = 10000000000000000;
  48. public static double 千京 = 10000000000000000000;
  49. public static BigInteger 垓 = new BigInteger("100000000000000000000");
  50. public static BigInteger 千垓 = new BigInteger("100000000000000000000000");
  51. }
  52. public class Auxiliary : Regist
  53. {
  54. #region 变量
  55. public string String1;
  56. public string String2;
  57. public Sprite Sprite;
  58. public TextAsset TextAsset;
  59. public Texture2D Texture;
  60. public Texture2D Texture1;
  61. public Texture2D Texture2;
  62. public Font Font;
  63. public GameObject Go;
  64. public List<Sprite> Sprites;
  65. public List<GameObject> GoList;
  66. public List<SpriteRenderer> SrList;
  67. public static bool AnyKeyUp;
  68. public static bool AnyKeyDown;
  69. public static Auxiliary Instance;
  70. public static MD5 MD5
  71. {
  72. get
  73. {
  74. if (_MD5 == null)
  75. {
  76. _MD5 = new MD5CryptoServiceProvider();
  77. }
  78. return _MD5;
  79. }
  80. set { _MD5 = value; }
  81. }
  82. public static DESCryptoServiceProvider Des
  83. {
  84. get
  85. {
  86. if (_Des == null)
  87. {
  88. _Des = new DESCryptoServiceProvider();
  89. _Des.IV = Encoding.UTF8.GetBytes("19283740");
  90. _Des.Key = Encoding.UTF8.GetBytes("93287123");
  91. }
  92. return _Des;
  93. }
  94. set { _Des = value; }
  95. }
  96. private static MD5 _MD5;
  97. private static DESCryptoServiceProvider _Des;
  98. #endregion
  99. public override bool InitAtOnce()
  100. {
  101. if (base.InitAtOnce())
  102. {
  103. return true;
  104. }
  105. enabled = true;
  106. return false;
  107. }
  108. private void Awake()
  109. {
  110. Instance = this;
  111. }
  112. private void Update()
  113. {
  114. #region 调试
  115. if (Input.GetKeyDown(KeyCode.Escape))
  116. {
  117. SFSManager.GardenSmartFox.SmartFox.Disconnect();
  118. RobotManager.DeactivateAllRobots(false);
  119. }
  120. if (Input.GetKeyDown(KeyCode.Space))
  121. {
  122. HttpManager.GetThanksGiftInfo(ThanksGift.Init, () => Bubble.Show(null, Language.GetStr("UI", "GetThanksGiftInfoFailed")));
  123. }
  124. //if (Input.GetKeyDown(KeyCode.A))
  125. //{
  126. // URLRequestData urlData = new URLRequestData();
  127. // urlData.Add("i", "");
  128. // URLRequest.CreateURLRequest(false, ManaServer.NewBaseURL + "/user/rand", urlData, data => { Debug.Log(data.ToJson()); }, URLRequest.Method.POST);
  129. // ManaSocial.UpdatePage(true);
  130. // PlazaRoomMge.DownloadRoomData(0);
  131. // DatabaseManager.GetRoomList(-1);
  132. // ManaServer.NotificationIndex = ManaData.GetPlayerInt("NotificationIndex") + 1;
  133. // ManaCenter.OfflineLock = true;
  134. // ManaSign.ShowOfflinePanel();
  135. // ManaTutorial.EnterC1();
  136. //}
  137. //if (Input.GetKeyDown(KeyCode.S))
  138. //{
  139. // ManaTutorial.EnterD1();
  140. //}
  141. //if (Input.GetKeyDown(KeyCode.D))
  142. //{
  143. // SFSManager.GardenSmartFox.PlazaRoomManager.BeginEnterPlazaRoom();
  144. //}
  145. if (Input.GetKeyDown(KeyCode.Z))
  146. {
  147. Manager.MiniTimer = 0;
  148. }
  149. //if (Input.GetKeyDown(KeyCode.X))
  150. //{
  151. // GardenSmartFoxManager.GardenSmartFox.ExtensionManager.PlazaRoomExtension.SendPublicMessage("123");
  152. // ManaPlayer.Player.PlayAnim("newAnimation");
  153. // StartCoroutine(ManaServer.DownloadAllAsset(new List<string>() { "http://or5zgoeui.bkt.clouddn.com/game_icon.png", "https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=3853411417,2245648913&fm=26&gp=0.jpg" }, ManaServer.DownloadAllTexture));
  154. // ManaMiniGame.GameTimer = 45;
  155. // Lottery.TempTypeList = new List<int>();
  156. // Lottery.TempValueList = new List<int>();
  157. // Lottery.TempLotteryList = new List<Lottery>();
  158. // Lottery.EnterAnimation();
  159. // ManaReso.Get(PrefabLabel.Bc_LotteryItem1).TweenForEuler();
  160. // ManaReso.Get(PrefabLabel.Bc_LotteryItem2).TweenForEuler();
  161. // ManaReso.Get(PrefabLabel.Bc_LotteryItem3).TweenForEuler();
  162. //}
  163. //if (Input.GetKeyDown(KeyCode.C))
  164. //{
  165. // GardenSmartFoxManager.GardenSmartFox.PlazaRoomManager.SendExpression(ExpressionID.郁闷);
  166. // SFSObject sfsObject = new SFSObject();
  167. // sfsObject.PutInt(DataID.SenderID.GetHashString(), 0);
  168. // sfsObject.PutText(DataID.Message.GetHashString(), "123");
  169. // SFSObject parameter = GardenSmartFox.ConstructCommandParameter(CommandID.ReceivePublicMessage.GetHashCode(), sfsObject, -1);
  170. // GardenSmartFoxManager.GardenSmartFox.AddRequest(parameter, RequestType.Immediate);
  171. // GardenSmartFoxManager.GardenSmartFox.SmartFox.Send(new ExtensionRequest("0", sfsObject));
  172. // ManaPlayer.Player.PlayAnim("newAnimation1");
  173. // ManaReso.Get(PrefabLabel.C_Notify).TweenForCG();
  174. // ManaMiniGame.Score += 400;
  175. // ManaSign.SignTime = new DateTime(2007, 1, 1);
  176. //}
  177. //if (Input.GetKeyDown(KeyCode.V))
  178. //{
  179. // ManaData.PlayerDoc.SelectSingleNode(PlayerConfigLabel.RootNode).SelectSingleNode(PlayerConfigLabel.Version).Attributes[0].Value = 6.ToString();
  180. // ManaData.PlayerNode.RemoveChild(ManaData.PlayerNode.SelectSingleNode("FlowerAmtList"));
  181. // Debug.Log(ManaData.GetPlayerString("FlowerList"));
  182. // Debug.Log(ManaData.GetPlayerString("FlowerAmtList"));
  183. // ManaPlayer.Player.PlayAnim("newAnimation2");
  184. // ManaPlayer.Player.Flip(PlayerDirection.Right);
  185. // ManaServer.MailReward mailReward = new ManaServer.MailReward("1", "pack", "4");
  186. // ManaServer.MailReward mailReward1 = new ManaServer.MailReward("1", "close", "2");
  187. // ManaServer.GetMainReward(mailReward);
  188. // ManaServer.GetMainReward(mailReward1);
  189. // ManaGarden.ElfTimer = 0;
  190. // ManaServer.Time = new DateTime(2007, 1, 1);
  191. //}
  192. //if (Input.GetKeyDown(KeyCode.B))
  193. //{
  194. // ManaPlayer.Player.PlayAnim("newAnimation3");
  195. // ManaPlayer.Player.Flip(PlayerDirection.Left);
  196. // foreach (var VARIABLE in ManaPlayer.CloseUnitDic)
  197. // {
  198. // VARIABLE.Value.Unlock();
  199. // }
  200. //}
  201. //if (Input.GetKeyDown(KeyCode.M))
  202. //{
  203. // ManaReso.Get(PrefabLabel.G_Flower).SetActive(false);
  204. // Debug.Log(ManaGarden.Slot);
  205. //}
  206. //if (Input.GetKeyDown(KeyCode.N))
  207. //{
  208. // ManaCenter.Coin = 0;
  209. // ManaCenter.Diamond = 0;
  210. // foreach (var VARIABLE in ManaGarden.FlowerInfoDic)
  211. // {
  212. // VARIABLE.Value.Unlock = true;
  213. // }
  214. // foreach (var VARIABLE in ManaGarden.FlowerInfoDic)
  215. // {
  216. // VARIABLE.Value.Unlock = false;
  217. // }
  218. // ManaGarden.FlowerInfoDic.First().Value.Unlock = true;
  219. //}
  220. //if (Input.GetKeyDown(KeyCode.P))
  221. //{
  222. // ManaData.Level += 20;
  223. //}
  224. //if (Input.GetKeyDown(KeyCode.O))
  225. //{
  226. // for (int i = 0; i < ManaCenter.CoolList.Count; i++)
  227. // {
  228. // ManaCenter.CoolList[i].CoolTimer = 0;
  229. // }
  230. //}
  231. //if (Input.GetKeyDown(KeyCode.I))
  232. //{
  233. // ManaCenter.Coin += 1000;
  234. // ManaCenter.Diamond += 1000;
  235. //}
  236. //if (Input.GetKeyDown(KeyCode.U))
  237. //{
  238. // Data.SavePlayerConfig();
  239. // Data.SaveXml();
  240. //}
  241. //if (Input.GetKeyDown(KeyCode.Y))
  242. //{
  243. // Data.ResetPlayerConfig();
  244. // Data.SaveXml();
  245. //}
  246. //if (Input.GetKeyDown(KeyCode.T))
  247. //{
  248. // ManaData.Pause = !ManaData.Pause;
  249. //}
  250. #endregion
  251. #region 输入检测
  252. if (Input.GetKeyDown(KeyCode.Escape))
  253. {
  254. MiniGameManager.Pause = true;
  255. Bubble.Show(Language.GetStr("Common", "QuitGame"), null, null, null, Application.Quit, () => { MiniGameManager.Pause = false; });
  256. }
  257. if (AnyKeyUp)
  258. {
  259. if (Input.anyKey == false)
  260. {
  261. AnyKeyUp = false;
  262. }
  263. }
  264. if (Input.anyKeyDown)
  265. {
  266. AnyKeyDown = true;
  267. }
  268. if (AnyKeyDown)
  269. {
  270. if (Input.anyKey == false)
  271. {
  272. AnyKeyUp = true;
  273. AnyKeyDown = false;
  274. }
  275. }
  276. #endregion
  277. }
  278. private static void ResetAllCd()
  279. {
  280. for (int i = 0; i < Manager.CoolList.Count; i++)
  281. {
  282. Manager.CoolList[i].CoolTimer = 0;
  283. }
  284. }
  285. public static byte[] GetMD5(object obj)
  286. {
  287. MemoryStream memoryStream = new MemoryStream();
  288. BinaryFormatter binaryFormatter = new BinaryFormatter();
  289. binaryFormatter.Serialize(memoryStream, obj);
  290. byte[] bytes = memoryStream.GetBuffer();
  291. memoryStream.Dispose();
  292. return MD5.ComputeHash(bytes);
  293. }
  294. public static void EncryptXml(XmlDocument doc)
  295. {
  296. EncryptedXml encryptedXml = new EncryptedXml();
  297. XmlElement xmlElement = doc.DocumentElement;
  298. byte[] bytes = encryptedXml.EncryptData(xmlElement, Des, false);
  299. EncryptedData encryptedData = new EncryptedData();
  300. encryptedData.Type = EncryptedXml.XmlEncElementUrl;
  301. encryptedData.EncryptionMethod = new EncryptionMethod(EncryptedXml.XmlEncDESUrl);
  302. encryptedData.CipherData.CipherValue = bytes;
  303. EncryptedXml.ReplaceElement(xmlElement, encryptedData, false);
  304. }
  305. public static void DecryptXml(XmlDocument doc)
  306. {
  307. EncryptedXml encryptedXml = new EncryptedXml();
  308. XmlElement encryptXmlElement = (XmlElement)doc.GetElementsByTagName("EncryptedData")[0];
  309. EncryptedData encryptedData = new EncryptedData();
  310. encryptedData.LoadXml(encryptXmlElement);
  311. byte[] bytes = encryptedXml.DecryptData(encryptedData, Des);
  312. encryptedXml.ReplaceData(encryptXmlElement, bytes);
  313. }
  314. public static byte[] Encrypt(string str)
  315. {
  316. byte[] bytes = Encoding.UTF8.GetBytes(str);
  317. byte[] encryptBytes = Des.CreateEncryptor().TransformFinalBlock(bytes, 0, bytes.Length);
  318. return encryptBytes;
  319. }
  320. public static byte[] ToBytes(string str)
  321. {
  322. string[] strings = str.Split(' ');
  323. byte[] bytes = new byte[strings.Length];
  324. for (int i = 0; i < bytes.Length; i++)
  325. {
  326. bytes[i] = byte.Parse(strings[i]);
  327. }
  328. return bytes;
  329. }
  330. public static string Decrypt(string str)
  331. {
  332. byte[] encryptBytes = ToBytes(str);
  333. byte[] decryptBytes = Des.CreateDecryptor().TransformFinalBlock(encryptBytes, 0, encryptBytes.Length);
  334. return Encoding.UTF8.GetString(decryptBytes);
  335. }
  336. public static string ToString(byte[] bytes)
  337. {
  338. StringBuilder strB = new StringBuilder();
  339. for (int i = 0; i < bytes.Length; i++)
  340. {
  341. if (i == bytes.Length - 1)
  342. {
  343. strB.Append(bytes[i]);
  344. }
  345. else
  346. {
  347. strB.Append(bytes[i] + " ");
  348. }
  349. }
  350. return strB.ToString();
  351. }
  352. public static void CompileDic(Transform tra, Dictionary<string, Transform> dic, bool enableIgnore = true)
  353. {
  354. Transform[] transforms = tra.GetComponentsInChildren<Transform>(true);
  355. for (int i = 0; i < transforms.Length; i++)
  356. {
  357. if (enableIgnore)
  358. {
  359. if (transforms[i].GetComponent<IgnoreIndexing>())
  360. {
  361. continue;
  362. }
  363. }
  364. if (dic.ContainsKey(transforms[i].name))
  365. {
  366. throw new Exception(transforms[i].name);
  367. }
  368. else
  369. {
  370. dic.Add(transforms[i].name, transforms[i]);
  371. }
  372. }
  373. }
  374. public static string GetUnit(int value, Unit unit)
  375. {
  376. if (unit == Unit.Second)
  377. {
  378. if (LanguageManager.CurrentLanguage == CurrentLanguage.English)
  379. {
  380. if (value == 0 || value == 1)
  381. {
  382. return " Second";
  383. }
  384. else
  385. {
  386. return " Seconds";
  387. }
  388. }
  389. else if (LanguageManager.CurrentLanguage == CurrentLanguage.ChineseSimplified)
  390. {
  391. return "秒";
  392. }
  393. else if (LanguageManager.CurrentLanguage == CurrentLanguage.ChineseTraditional)
  394. {
  395. return "秒";
  396. }
  397. else
  398. {
  399. throw new Exception();
  400. }
  401. }
  402. else
  403. {
  404. throw new Exception();
  405. }
  406. }
  407. public static string GetStreamPath()
  408. {
  409. if (Application.isEditor)
  410. {
  411. return "file://" + Application.streamingAssetsPath;
  412. }
  413. else if (Application.platform == RuntimePlatform.IPhonePlayer)
  414. {
  415. return "file://" + Application.streamingAssetsPath;
  416. }
  417. else if (Application.isMobilePlatform)
  418. {
  419. return Application.streamingAssetsPath;
  420. }
  421. else
  422. {
  423. throw new Exception();
  424. }
  425. }
  426. public Coroutine DelayCall(UnityAction function, int frame)
  427. {
  428. return StartCoroutine(IDelayCall(function, frame));
  429. }
  430. public Coroutine DelayCall(UnityAction function, float time)
  431. {
  432. return StartCoroutine(IDelayCall(function, time));
  433. }
  434. public static IEnumerator IDelayCall(UnityAction function, int frame)
  435. {
  436. int count = 0;
  437. while (count < frame)
  438. {
  439. count++;
  440. yield return null;
  441. }
  442. function.Invoke();
  443. }
  444. public static IEnumerator IDelayCall(UnityAction function, float time)
  445. {
  446. yield return new WaitForSeconds(time);
  447. function.Invoke();
  448. }
  449. public static string FmlParse1(string str)
  450. {
  451. int index = 0;
  452. int openIndex = 0;
  453. bool flag = false;
  454. bool group = false;
  455. for (int i = 0; i < str.Length; i++)
  456. {
  457. if (group)
  458. {
  459. if (str[i] == '+' || str[i] == '-' || str[i] == '*' || str[i] == '/')
  460. {
  461. str = str.Replace(openIndex, i - 1, FmlParse2(str[index], str.Between(openIndex, index - 1), str.Between(index + 1, i - 1)));
  462. i = 0;
  463. group = false;
  464. }
  465. else if (i == str.Length - 1)
  466. {
  467. str = str.Replace(openIndex, i, FmlParse2(str[index], str.Between(openIndex, index - 1), str.Between(index + 1, i)));
  468. break;
  469. }
  470. }
  471. else
  472. {
  473. if (str[i] == '+' || str[i] == '-')
  474. {
  475. flag = true;
  476. openIndex = i + 1;
  477. }
  478. else if (str[i] == '*' || str[i] == '/')
  479. {
  480. index = i;
  481. group = true;
  482. if (!flag)
  483. {
  484. openIndex = 0;
  485. }
  486. }
  487. }
  488. }
  489. group = false;
  490. for (int i = 0; i < str.Length; i++)
  491. {
  492. if (group)
  493. {
  494. if (str[i] == '+' || str[i] == '-')
  495. {
  496. str = str.Replace(0, i - 1, FmlParse2(str[index], str.Between(0, index - 1), str.Between(index + 1, i - 1)));
  497. i = -1;
  498. group = false;
  499. }
  500. else if (i == str.Length - 1)
  501. {
  502. return FmlParse2(str[index], str.Between(0, index - 1), str.Between(index + 1, i));
  503. }
  504. }
  505. else
  506. {
  507. if (str[i] == '+' || str[i] == '-')
  508. {
  509. index = i;
  510. group = true;
  511. }
  512. }
  513. }
  514. return str;
  515. }
  516. public static string FmlParse2(char op, string str1, string str2)
  517. {
  518. double var1 = double.Parse(str1);
  519. double var2 = double.Parse(str2);
  520. if (op == '+')
  521. {
  522. return (var1 + var2).ToString();
  523. }
  524. else if (op == '-')
  525. {
  526. return (var1 - var2).ToString();
  527. }
  528. else if (op == '*')
  529. {
  530. return (var1 * var2).ToString();
  531. }
  532. else if (op == '/')
  533. {
  534. return (var1 / var2).ToString();
  535. }
  536. else
  537. {
  538. throw new Exception(op.ToString());
  539. }
  540. }
  541. public static double FmlParse(string str, params string[] strings)
  542. {
  543. for (int i = 0; i < strings.Length; i += 2)
  544. {
  545. if (str.Contains(strings[i]))
  546. {
  547. str = str.Replace(strings[i], strings[i + 1]);
  548. }
  549. else
  550. {
  551. //Debug.Log("No such var " + strings[i + 1]);
  552. }
  553. }
  554. int openIndex = 0;
  555. for (int i = 0; i < str.Length; i++)
  556. {
  557. if (str[i] == '(')
  558. {
  559. openIndex = i;
  560. }
  561. else if (str[i] == ')')
  562. {
  563. str = str.Replace(openIndex, i, FmlParse1(str.Between(openIndex + 1, i - 1)));
  564. i = -1;
  565. }
  566. }
  567. return double.Parse(FmlParse1(str));
  568. }
  569. public static string OmitNumberStr(int accuray, string str)
  570. {
  571. int index = str.IndexOf('.');
  572. if (index == -1)
  573. {
  574. return str;
  575. }
  576. if (accuray == 0)
  577. {
  578. return str.Substring(0, index);
  579. }
  580. else
  581. {
  582. for (int i = index + 1; i < index + accuray + 1; i++)
  583. {
  584. if (str[i] != '0')
  585. {
  586. return str.Substring(0, index + accuray + 1);
  587. }
  588. }
  589. return str.Substring(0, index);
  590. }
  591. }
  592. public static double ShrinkNumber(double value, int accuracy = 1)
  593. {
  594. if (LanguageManager.CurrentLanguage == CurrentLanguage.English)
  595. {
  596. if (value < Amount.千)
  597. {
  598. return value;
  599. }
  600. else if (value < Amount.百万)
  601. {
  602. string str = (value / Amount.千).ToString("F" + (accuracy + 1));
  603. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.千;
  604. }
  605. else if (value < Amount.十亿)
  606. {
  607. string str = (value / Amount.百万).ToString("F" + (accuracy + 1));
  608. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.百万;
  609. }
  610. else if (value < Amount.兆)
  611. {
  612. string str = (value / Amount.十亿).ToString("F" + (accuracy + 1));
  613. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.十亿;
  614. }
  615. else if (value < Amount.千兆)
  616. {
  617. string str = (value / Amount.兆).ToString("F" + (accuracy + 1));
  618. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.兆;
  619. }
  620. else
  621. {
  622. string str = (value / Amount.千兆).ToString("F" + (accuracy + 1));
  623. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.千兆;
  624. }
  625. }
  626. else if (LanguageManager.CurrentLanguage == CurrentLanguage.ChineseSimplified || LanguageManager.CurrentLanguage == CurrentLanguage.ChineseTraditional)
  627. {
  628. if (value < Amount.万)
  629. {
  630. return value;
  631. }
  632. else if (value < Amount.千万)
  633. {
  634. string str = (value / Amount.万).ToString("F" + (accuracy + 1));
  635. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.万;
  636. }
  637. else if (value < Amount.亿)
  638. {
  639. string str = (value / Amount.千万).ToString("F" + (accuracy + 1));
  640. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.千万;
  641. }
  642. else if (value < Amount.千亿)
  643. {
  644. string str = (value / Amount.亿).ToString("F" + (accuracy + 1));
  645. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.亿;
  646. }
  647. else if (value < Amount.兆)
  648. {
  649. string str = (value / Amount.千亿).ToString("F" + (accuracy + 1));
  650. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.千亿;
  651. }
  652. else if (value < Amount.千兆)
  653. {
  654. string str = (value / Amount.兆).ToString("F" + (accuracy + 1));
  655. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.兆;
  656. }
  657. else if (value < Amount.京)
  658. {
  659. string str = (value / Amount.千兆).ToString("F" + (accuracy + 1));
  660. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.千兆;
  661. }
  662. else if (value < Amount.千京)
  663. {
  664. string str = (value / Amount.京).ToString("F" + (accuracy + 1));
  665. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.京;
  666. }
  667. else if (new BigInteger(value.ToString("0")) < Amount.垓)
  668. {
  669. string str = (value / Amount.千京).ToString("F" + (accuracy + 1));
  670. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.千京;
  671. }
  672. else if (new BigInteger(value.ToString("0")) < Amount.千垓)
  673. {
  674. string str = (new BigInteger(value.ToString("0")) / Amount.垓).ToString();
  675. return double.Parse(OmitNumberStr(0, str)) * Amount.千京 * 10;
  676. }
  677. else
  678. {
  679. string str = (new BigInteger(value.ToString("0")) / Amount.千垓).ToString();
  680. return double.Parse(OmitNumberStr(0, str)) * Amount.千京 * 10000;
  681. }
  682. }
  683. else
  684. {
  685. throw new Exception();
  686. }
  687. }
  688. public static string ShrinkNumberStr(double value, int accuracy = 1)
  689. {
  690. if (LanguageManager.CurrentLanguage == CurrentLanguage.English)
  691. {
  692. if (value < Amount.千)
  693. {
  694. return value.ToString("0");
  695. }
  696. else if (value < Amount.百万)
  697. {
  698. string str = (value / Amount.千).ToString("F" + (accuracy + 1));
  699. return OmitNumberStr(accuracy, str) + "K";
  700. }
  701. else if (value < Amount.十亿)
  702. {
  703. string str = (value / Amount.百万).ToString("F" + (accuracy + 1));
  704. return OmitNumberStr(accuracy, str) + "M";
  705. }
  706. else if (value < Amount.兆)
  707. {
  708. string str = (value / Amount.十亿).ToString("F" + (accuracy + 1));
  709. return OmitNumberStr(accuracy, str) + "B";
  710. }
  711. else if (value < Amount.千兆)
  712. {
  713. string str = (value / Amount.兆).ToString("F" + (accuracy + 1));
  714. return OmitNumberStr(accuracy, str) + "T";
  715. }
  716. else
  717. {
  718. string str = (value / Amount.兆).ToString("F" + (accuracy + 1));
  719. return OmitNumberStr(accuracy, str) + "T";
  720. }
  721. }
  722. else if (LanguageManager.CurrentLanguage == CurrentLanguage.ChineseSimplified)
  723. {
  724. if (value < Amount.万)
  725. {
  726. return value.ToString("0");
  727. }
  728. else if (value < Amount.千万)
  729. {
  730. string str = (value / Amount.万).ToString("F" + (accuracy + 1));
  731. return OmitNumberStr(accuracy, str) + "万";
  732. }
  733. else if (value < Amount.亿)
  734. {
  735. string str = (value/Amount.千万).ToString("F" + (accuracy + 1));
  736. return OmitNumberStr(accuracy, str) + "千万";
  737. }
  738. else if (value < Amount.千亿)
  739. {
  740. string str = (value / Amount.亿).ToString("F" + (accuracy + 1));
  741. return OmitNumberStr(accuracy, str) + "亿";
  742. }
  743. else if (value < Amount.兆)
  744. {
  745. string str = (value / Amount.千亿).ToString("F" + (accuracy + 1));
  746. return OmitNumberStr(accuracy, str) + "千亿";
  747. }
  748. else if (value < Amount.千兆)
  749. {
  750. string str = (value / Amount.兆).ToString("F" + (accuracy + 1));
  751. return OmitNumberStr(accuracy, str) + "兆";
  752. }
  753. else if (value < Amount.京)
  754. {
  755. string str = (value / Amount.千兆).ToString("F" + (accuracy + 1));
  756. return OmitNumberStr(accuracy, str) + "千兆";
  757. }
  758. else if (value < Amount.千京)
  759. {
  760. string str = (value / Amount.京).ToString("F" + (accuracy + 1));
  761. return OmitNumberStr(accuracy, str) + "京";
  762. }
  763. else if (new BigInteger(value.ToString("0")) < Amount.垓)
  764. {
  765. string str = (value / Amount.千京).ToString("F" + (accuracy + 1));
  766. return OmitNumberStr(accuracy, str) + "千京";
  767. }
  768. else if (new BigInteger(value.ToString("0")) < Amount.千垓)
  769. {
  770. string str = (new BigInteger(value.ToString("0")) / Amount.垓).ToString();
  771. return OmitNumberStr(0, str) + "垓";
  772. }
  773. else
  774. {
  775. string str = (new BigInteger(value.ToString("0")) / Amount.千垓).ToString();
  776. return OmitNumberStr(0, str) + "千垓";
  777. }
  778. }
  779. else if (LanguageManager.CurrentLanguage == CurrentLanguage.ChineseTraditional)
  780. {
  781. if (value < Amount.万)
  782. {
  783. return value.ToString("0");
  784. }
  785. else if (value < Amount.千万)
  786. {
  787. string str = (value / Amount.万).ToString("F" + (accuracy + 1));
  788. return OmitNumberStr(accuracy, str) + "萬";
  789. }
  790. else if (value < Amount.亿)
  791. {
  792. string str = (value / Amount.千万).ToString("F" + (accuracy + 1));
  793. return OmitNumberStr(accuracy, str) + "千萬";
  794. }
  795. else if (value < Amount.千亿)
  796. {
  797. string str = (value / Amount.亿).ToString("F" + (accuracy + 1));
  798. return OmitNumberStr(accuracy, str) + "億";
  799. }
  800. else if (value < Amount.兆)
  801. {
  802. string str = (value / Amount.千亿).ToString("F" + (accuracy + 1));
  803. return OmitNumberStr(accuracy, str) + "千億";
  804. }
  805. else if (value < Amount.千兆)
  806. {
  807. string str = (value / Amount.兆).ToString("F" + (accuracy + 1));
  808. return OmitNumberStr(accuracy, str) + "兆";
  809. }
  810. else if (value < Amount.京)
  811. {
  812. string str = (value / Amount.千兆).ToString("F" + (accuracy + 1));
  813. return OmitNumberStr(accuracy, str) + "千兆";
  814. }
  815. else if (value < Amount.千京)
  816. {
  817. string str = (value / Amount.京).ToString("F" + (accuracy + 1));
  818. return OmitNumberStr(accuracy, str) + "京";
  819. }
  820. else if (new BigInteger(value.ToString("0")) < Amount.垓)
  821. {
  822. string str = (value / Amount.千京).ToString("F" + (accuracy + 1));
  823. return OmitNumberStr(accuracy, str) + "千京";
  824. }
  825. else if (new BigInteger(value.ToString("0")) < Amount.千垓)
  826. {
  827. string str = (new BigInteger(value.ToString("0")) / Amount.垓).ToString();
  828. return OmitNumberStr(0, str) + "垓";
  829. }
  830. else
  831. {
  832. string str = (new BigInteger(value.ToString("0")) / Amount.千垓).ToString();
  833. return OmitNumberStr(0, str) + "千垓";
  834. }
  835. }
  836. else
  837. {
  838. throw new Exception();
  839. }
  840. }
  841. public static string ImageParse(Current current)
  842. {
  843. if (current == Current.Coin)
  844. {
  845. return TransferLabel.CoinSprite;
  846. }
  847. else if (current == Current.Diamond)
  848. {
  849. return TransferLabel.DiamondSprite;
  850. }
  851. else if (current == Current.Cash)
  852. {
  853. return Language.GetStr("Common", "Cash");
  854. }
  855. else
  856. {
  857. throw new Exception(current.ToString());
  858. }
  859. }
  860. public static Current CurrentParse(string str)
  861. {
  862. if (string.IsNullOrEmpty(str))
  863. {
  864. return Current.Free;
  865. }
  866. else
  867. {
  868. int number = int.Parse(str);
  869. if (number == 1)
  870. {
  871. return Current.Coin;
  872. }
  873. else if (number == 2)
  874. {
  875. return Current.Diamond;
  876. }
  877. else if (number == 3)
  878. {
  879. return Current.Cash;
  880. }
  881. else if (number == 4)
  882. {
  883. return Current.Other;
  884. }
  885. else if (number == 5)
  886. {
  887. return Current.AD;
  888. }
  889. else
  890. {
  891. throw new Exception(number.ToString());
  892. }
  893. }
  894. }
  895. public static int StringToInt(string str, int defaultValue)
  896. {
  897. if (string.IsNullOrEmpty(str))
  898. {
  899. return defaultValue;
  900. }
  901. else
  902. {
  903. return int.Parse(str);
  904. }
  905. }
  906. public static long StringToLong(string str, long defaultValue)
  907. {
  908. if (string.IsNullOrEmpty(str))
  909. {
  910. return defaultValue;
  911. }
  912. else
  913. {
  914. return long.Parse(str);
  915. }
  916. }
  917. public static bool StringToBool(string str, bool defaultValue)
  918. {
  919. if (string.IsNullOrEmpty(str))
  920. {
  921. return defaultValue;
  922. }
  923. else
  924. {
  925. return Convert.ToBoolean(int.Parse(str));
  926. }
  927. }
  928. public static float StringToFloat(string str, float defaultValue)
  929. {
  930. if (string.IsNullOrEmpty(str))
  931. {
  932. return defaultValue;
  933. }
  934. else
  935. {
  936. return float.Parse(str);
  937. }
  938. }
  939. public static double StringToDouble(string str, double defaultValue)
  940. {
  941. if (string.IsNullOrEmpty(str))
  942. {
  943. return defaultValue;
  944. }
  945. else
  946. {
  947. return float.Parse(str);
  948. }
  949. }
  950. public static Vector3 StringToVector(char seperateChar, string str, Vector3 defaultValue)
  951. {
  952. if (string.IsNullOrEmpty(str))
  953. {
  954. return defaultValue;
  955. }
  956. else
  957. {
  958. string[] strings = str.Split(seperateChar);
  959. if (strings.Length == 2)
  960. {
  961. Vector2 result = new Vector2();
  962. result.x = float.Parse(strings[0]);
  963. result.y = float.Parse(strings[1]);
  964. return result;
  965. }
  966. else if (strings.Length == 3)
  967. {
  968. Vector3 result = new Vector3();
  969. result.x = float.Parse(strings[0]);
  970. result.y = float.Parse(strings[1]);
  971. result.z = float.Parse(strings[2]);
  972. return result;
  973. }
  974. else
  975. {
  976. Debug.Log(str);
  977. throw new Exception();
  978. }
  979. }
  980. }
  981. public static List<int> StringToInts(char seperateChar, string str, List<int> defaultValue)
  982. {
  983. if (string.IsNullOrEmpty(str))
  984. {
  985. return defaultValue;
  986. }
  987. else
  988. {
  989. string[] strings = str.Split(seperateChar);
  990. List<int> list = new List<int>();
  991. for (int i = 0; i < strings.Length; i++)
  992. {
  993. list.Add(int.Parse(strings[i]));
  994. }
  995. return list;
  996. }
  997. }
  998. public static List<string> StringToStrings(char seperateChar, string str, List<string> defaultValue)
  999. {
  1000. if (string.IsNullOrEmpty(str))
  1001. {
  1002. return defaultValue;
  1003. }
  1004. else
  1005. {
  1006. string[] strings = str.Split(seperateChar);
  1007. List<string> list = new List<string>();
  1008. for (int i = 0; i < strings.Length; i++)
  1009. {
  1010. list.Add(strings[i]);
  1011. }
  1012. return list;
  1013. }
  1014. }
  1015. public static List<double> StringToDoubles(char seperateChar, string str, List<double> defaultValue)
  1016. {
  1017. if (string.IsNullOrEmpty(str))
  1018. {
  1019. return defaultValue;
  1020. }
  1021. else
  1022. {
  1023. string[] strings = str.Split(seperateChar);
  1024. List<double> list = new List<double>();
  1025. for (int i = 0; i < strings.Length; i++)
  1026. {
  1027. list.Add(double.Parse(strings[i]));
  1028. }
  1029. return list;
  1030. }
  1031. }
  1032. }