Auxiliary.cs 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283
  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 Config
  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(LanguageLabel.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.MinigameCDTimer = 0;
  148. TutorialManager.MemoryMinigameTutorial = true;
  149. }
  150. //if (Input.GetKeyDown(KeyCode.X))
  151. //{
  152. // GardenSmartFoxManager.GardenSmartFox.ExtensionManager.PlazaRoomExtension.SendPublicMessage("123");
  153. // ManaPlayer.Player.PlayAnim("newAnimation");
  154. // 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));
  155. // ManaMiniGame.GameTimer = 45;
  156. // Lottery.TempTypeList = new List<int>();
  157. // Lottery.TempValueList = new List<int>();
  158. // Lottery.TempLotteryList = new List<Lottery>();
  159. // Lottery.EnterAnimation();
  160. // ManaReso.Get(PrefabLabel.Bc_LotteryItem1).TweenForEuler();
  161. // ManaReso.Get(PrefabLabel.Bc_LotteryItem2).TweenForEuler();
  162. // ManaReso.Get(PrefabLabel.Bc_LotteryItem3).TweenForEuler();
  163. //}
  164. //if (Input.GetKeyDown(KeyCode.C))
  165. //{
  166. // GardenSmartFoxManager.GardenSmartFox.PlazaRoomManager.SendExpression(ExpressionID.郁闷);
  167. // SFSObject sfsObject = new SFSObject();
  168. // sfsObject.PutInt(DataID.SenderID.GetHashString(), 0);
  169. // sfsObject.PutText(DataID.Message.GetHashString(), "123");
  170. // SFSObject parameter = GardenSmartFox.ConstructCommandParameter(CommandID.ReceivePublicMessage.GetHashCode(), sfsObject, -1);
  171. // GardenSmartFoxManager.GardenSmartFox.AddRequest(parameter, RequestType.Immediate);
  172. // GardenSmartFoxManager.GardenSmartFox.SmartFox.Send(new ExtensionRequest("0", sfsObject));
  173. // ManaPlayer.Player.PlayAnim("newAnimation1");
  174. // ManaReso.Get(PrefabLabel.C_Notify).TweenForCG();
  175. // ManaMiniGame.Score += 400;
  176. // ManaSign.SignTime = new DateTime(2007, 1, 1);
  177. //}
  178. //if (Input.GetKeyDown(KeyCode.V))
  179. //{
  180. // ManaData.PlayerDoc.SelectSingleNode(PlayerConfigLabel.RootNode).SelectSingleNode(PlayerConfigLabel.Version).Attributes[0].Value = 6.ToString();
  181. // ManaData.PlayerNode.RemoveChild(ManaData.PlayerNode.SelectSingleNode("FlowerAmtList"));
  182. // Debug.Log(ManaData.GetPlayerString("FlowerList"));
  183. // Debug.Log(ManaData.GetPlayerString("FlowerAmtList"));
  184. // ManaPlayer.Player.PlayAnim("newAnimation2");
  185. // ManaPlayer.Player.Flip(PlayerDirection.Right);
  186. // ManaServer.MailReward mailReward = new ManaServer.MailReward("1", "pack", "4");
  187. // ManaServer.MailReward mailReward1 = new ManaServer.MailReward("1", "close", "2");
  188. // ManaServer.GetMainReward(mailReward);
  189. // ManaServer.GetMainReward(mailReward1);
  190. // ManaGarden.ElfTimer = 0;
  191. // ManaServer.Time = new DateTime(2007, 1, 1);
  192. //}
  193. //if (Input.GetKeyDown(KeyCode.B))
  194. //{
  195. // ManaPlayer.Player.PlayAnim("newAnimation3");
  196. // ManaPlayer.Player.Flip(PlayerDirection.Left);
  197. // foreach (var VARIABLE in ManaPlayer.CloseUnitDic)
  198. // {
  199. // VARIABLE.Value.Unlock();
  200. // }
  201. //}
  202. //if (Input.GetKeyDown(KeyCode.M))
  203. //{
  204. // ManaReso.Get(PrefabLabel.G_Flower).SetActive(false);
  205. // Debug.Log(ManaGarden.Slot);
  206. //}
  207. //if (Input.GetKeyDown(KeyCode.N))
  208. //{
  209. // ManaCenter.Coin = 0;
  210. // ManaCenter.Diamond = 0;
  211. // foreach (var VARIABLE in ManaGarden.FlowerInfoDic)
  212. // {
  213. // VARIABLE.Value.Unlock = true;
  214. // }
  215. // foreach (var VARIABLE in ManaGarden.FlowerInfoDic)
  216. // {
  217. // VARIABLE.Value.Unlock = false;
  218. // }
  219. // ManaGarden.FlowerInfoDic.First().Value.Unlock = true;
  220. //}
  221. //if (Input.GetKeyDown(KeyCode.P))
  222. //{
  223. // ManaData.Level += 20;
  224. //}
  225. //if (Input.GetKeyDown(KeyCode.O))
  226. //{
  227. // for (int i = 0; i < ManaCenter.CoolList.Count; i++)
  228. // {
  229. // ManaCenter.CoolList[i].CoolTimer = 0;
  230. // }
  231. //}
  232. //if (Input.GetKeyDown(KeyCode.I))
  233. //{
  234. // ManaCenter.Coin += 1000;
  235. // ManaCenter.Diamond += 1000;
  236. //}
  237. //if (Input.GetKeyDown(KeyCode.U))
  238. //{
  239. // Data.SavePlayerConfig();
  240. // Data.SaveXml();
  241. //}
  242. //if (Input.GetKeyDown(KeyCode.Y))
  243. //{
  244. // Data.ResetPlayerConfig();
  245. // Data.SaveXml();
  246. //}
  247. //if (Input.GetKeyDown(KeyCode.T))
  248. //{
  249. // ManaData.Pause = !ManaData.Pause;
  250. //}
  251. #endregion
  252. #region 输入检测
  253. if (Input.GetKeyDown(KeyCode.Escape))
  254. {
  255. MiniGameManager.Pause = true;
  256. Bubble.Show(Language.GetStr(LanguageLabel.Common__QuitGame), null, null, null, Application.Quit, () => { MiniGameManager.Pause = false; });
  257. }
  258. if (AnyKeyUp)
  259. {
  260. if (Input.anyKey == false)
  261. {
  262. AnyKeyUp = false;
  263. }
  264. }
  265. if (Input.anyKeyDown)
  266. {
  267. AnyKeyDown = true;
  268. }
  269. if (AnyKeyDown)
  270. {
  271. if (Input.anyKey == false)
  272. {
  273. AnyKeyUp = true;
  274. AnyKeyDown = false;
  275. }
  276. }
  277. #endregion
  278. }
  279. private static void ResetAllCd()
  280. {
  281. for (int i = 0; i < Manager.CoolSkillList.Count; i++)
  282. {
  283. Manager.CoolSkillList[i].CoolTimer = 0;
  284. }
  285. }
  286. public static byte[] GetMD5(object obj)
  287. {
  288. MemoryStream memoryStream = new MemoryStream();
  289. BinaryFormatter binaryFormatter = new BinaryFormatter();
  290. binaryFormatter.Serialize(memoryStream, obj);
  291. byte[] bytes = memoryStream.GetBuffer();
  292. memoryStream.Dispose();
  293. return MD5.ComputeHash(bytes);
  294. }
  295. public static void EncryptXml(XmlDocument doc)
  296. {
  297. EncryptedXml encryptedXml = new EncryptedXml();
  298. XmlElement xmlElement = doc.DocumentElement;
  299. byte[] bytes = encryptedXml.EncryptData(xmlElement, Des, false);
  300. EncryptedData encryptedData = new EncryptedData();
  301. encryptedData.Type = EncryptedXml.XmlEncElementUrl;
  302. encryptedData.EncryptionMethod = new EncryptionMethod(EncryptedXml.XmlEncDESUrl);
  303. encryptedData.CipherData.CipherValue = bytes;
  304. EncryptedXml.ReplaceElement(xmlElement, encryptedData, false);
  305. }
  306. public static void DecryptXml(XmlDocument doc)
  307. {
  308. EncryptedXml encryptedXml = new EncryptedXml();
  309. XmlElement encryptXmlElement = (XmlElement)doc.GetElementsByTagName("EncryptedData")[0];
  310. EncryptedData encryptedData = new EncryptedData();
  311. encryptedData.LoadXml(encryptXmlElement);
  312. byte[] bytes = encryptedXml.DecryptData(encryptedData, Des);
  313. encryptedXml.ReplaceData(encryptXmlElement, bytes);
  314. }
  315. public static byte[] Encrypt(string str)
  316. {
  317. byte[] bytes = Encoding.UTF8.GetBytes(str);
  318. byte[] encryptBytes = Des.CreateEncryptor().TransformFinalBlock(bytes, 0, bytes.Length);
  319. return encryptBytes;
  320. }
  321. public static byte[] ToBytes(string str)
  322. {
  323. string[] strings = str.Split(' ');
  324. byte[] bytes = new byte[strings.Length];
  325. for (int i = 0; i < bytes.Length; i++)
  326. {
  327. bytes[i] = byte.Parse(strings[i]);
  328. }
  329. return bytes;
  330. }
  331. public static string Decrypt(string str)
  332. {
  333. byte[] encryptBytes = ToBytes(str);
  334. byte[] decryptBytes = Des.CreateDecryptor().TransformFinalBlock(encryptBytes, 0, encryptBytes.Length);
  335. return Encoding.UTF8.GetString(decryptBytes);
  336. }
  337. public static string ToString(byte[] bytes)
  338. {
  339. StringBuilder strB = new StringBuilder();
  340. for (int i = 0; i < bytes.Length; i++)
  341. {
  342. if (i == bytes.Length - 1)
  343. {
  344. strB.Append(bytes[i]);
  345. }
  346. else
  347. {
  348. strB.Append(bytes[i] + " ");
  349. }
  350. }
  351. return strB.ToString();
  352. }
  353. public static void CompileDic(Transform tra, Dictionary<string, Transform> dic, bool enableIgnore = true)
  354. {
  355. Transform[] transforms = tra.GetComponentsInChildren<Transform>(true);
  356. for (int i = 0; i < transforms.Length; i++)
  357. {
  358. if (enableIgnore)
  359. {
  360. if (transforms[i].GetComponent<IgnoreIndexing>())
  361. {
  362. continue;
  363. }
  364. }
  365. if (dic.ContainsKey(transforms[i].name))
  366. {
  367. throw new Exception(transforms[i].name);
  368. }
  369. else
  370. {
  371. dic.Add(transforms[i].name, transforms[i]);
  372. }
  373. }
  374. }
  375. public static string GetUnit(int value, Unit unit)
  376. {
  377. if (unit == Unit.Second)
  378. {
  379. if (LanguageManager.CurrentLanguage == CurrentLanguage.English)
  380. {
  381. if (value == 0 || value == 1)
  382. {
  383. return " Second";
  384. }
  385. else
  386. {
  387. return " Seconds";
  388. }
  389. }
  390. else if (LanguageManager.CurrentLanguage == CurrentLanguage.ChineseSimplified)
  391. {
  392. return "秒";
  393. }
  394. else if (LanguageManager.CurrentLanguage == CurrentLanguage.ChineseTraditional)
  395. {
  396. return "秒";
  397. }
  398. else
  399. {
  400. throw new Exception();
  401. }
  402. }
  403. else
  404. {
  405. throw new Exception();
  406. }
  407. }
  408. public static string GetStreamPath()
  409. {
  410. if (Application.isEditor)
  411. {
  412. return "file://" + Application.streamingAssetsPath;
  413. }
  414. else if (Application.platform == RuntimePlatform.IPhonePlayer)
  415. {
  416. return "file://" + Application.streamingAssetsPath;
  417. }
  418. else if (Application.isMobilePlatform)
  419. {
  420. return Application.streamingAssetsPath;
  421. }
  422. else
  423. {
  424. throw new Exception();
  425. }
  426. }
  427. public Coroutine DelayCall(UnityAction function, int frame)
  428. {
  429. return StartCoroutine(IDelayCall(function, frame));
  430. }
  431. public Coroutine DelayCall(UnityAction function, float time)
  432. {
  433. return StartCoroutine(IDelayCall(function, time));
  434. }
  435. public static IEnumerator IDelayCall(UnityAction function, int frame)
  436. {
  437. int count = 0;
  438. while (count < frame)
  439. {
  440. count++;
  441. yield return null;
  442. }
  443. function.Invoke();
  444. }
  445. public static IEnumerator IDelayCall(UnityAction function, float time)
  446. {
  447. yield return new WaitForSeconds(time);
  448. function.Invoke();
  449. }
  450. public static string FmlParse1(string str)
  451. {
  452. int index = 0;
  453. int openIndex = 0;
  454. bool flag = false;
  455. bool group = false;
  456. for (int i = 0; i < str.Length; i++)
  457. {
  458. if (group)
  459. {
  460. if (str[i] == '+' || str[i] == '-' || str[i] == '*' || str[i] == '/')
  461. {
  462. str = str.Replace(openIndex, i - 1, FmlParse2(str[index], str.Between(openIndex, index - 1), str.Between(index + 1, i - 1)));
  463. i = 0;
  464. group = false;
  465. }
  466. else if (i == str.Length - 1)
  467. {
  468. str = str.Replace(openIndex, i, FmlParse2(str[index], str.Between(openIndex, index - 1), str.Between(index + 1, i)));
  469. break;
  470. }
  471. }
  472. else
  473. {
  474. if (str[i] == '+' || str[i] == '-')
  475. {
  476. flag = true;
  477. openIndex = i + 1;
  478. }
  479. else if (str[i] == '*' || str[i] == '/')
  480. {
  481. index = i;
  482. group = true;
  483. if (!flag)
  484. {
  485. openIndex = 0;
  486. }
  487. }
  488. }
  489. }
  490. group = false;
  491. for (int i = 0; i < str.Length; i++)
  492. {
  493. if (group)
  494. {
  495. if (str[i] == '+' || str[i] == '-')
  496. {
  497. str = str.Replace(0, i - 1, FmlParse2(str[index], str.Between(0, index - 1), str.Between(index + 1, i - 1)));
  498. i = -1;
  499. group = false;
  500. }
  501. else if (i == str.Length - 1)
  502. {
  503. return FmlParse2(str[index], str.Between(0, index - 1), str.Between(index + 1, i));
  504. }
  505. }
  506. else
  507. {
  508. if (str[i] == '+' || str[i] == '-')
  509. {
  510. index = i;
  511. group = true;
  512. }
  513. }
  514. }
  515. return str;
  516. }
  517. public static string FmlParse2(char op, string str1, string str2)
  518. {
  519. double var1 = double.Parse(str1);
  520. double var2 = double.Parse(str2);
  521. if (op == '+')
  522. {
  523. return (var1 + var2).ToString();
  524. }
  525. else if (op == '-')
  526. {
  527. return (var1 - var2).ToString();
  528. }
  529. else if (op == '*')
  530. {
  531. return (var1 * var2).ToString();
  532. }
  533. else if (op == '/')
  534. {
  535. return (var1 / var2).ToString();
  536. }
  537. else
  538. {
  539. throw new Exception(op.ToString());
  540. }
  541. }
  542. public static double FmlParse(string str, params string[] strings)
  543. {
  544. for (int i = 0; i < strings.Length; i += 2)
  545. {
  546. if (str.Contains(strings[i]))
  547. {
  548. str = str.Replace(strings[i], strings[i + 1]);
  549. }
  550. else
  551. {
  552. //Debug.Log("No such var " + strings[i + 1]);
  553. }
  554. }
  555. int openIndex = 0;
  556. for (int i = 0; i < str.Length; i++)
  557. {
  558. if (str[i] == '(')
  559. {
  560. openIndex = i;
  561. }
  562. else if (str[i] == ')')
  563. {
  564. str = str.Replace(openIndex, i, FmlParse1(str.Between(openIndex + 1, i - 1)));
  565. i = -1;
  566. }
  567. }
  568. return double.Parse(FmlParse1(str));
  569. }
  570. public static string OmitNumberStr(int accuray, string str)
  571. {
  572. int index = str.IndexOf('.');
  573. if (index == -1)
  574. {
  575. return str;
  576. }
  577. if (accuray == 0)
  578. {
  579. return str.Substring(0, index);
  580. }
  581. else
  582. {
  583. for (int i = index + 1; i < index + accuray + 1; i++)
  584. {
  585. if (str[i] != '0')
  586. {
  587. return str.Substring(0, index + accuray + 1);
  588. }
  589. }
  590. return str.Substring(0, index);
  591. }
  592. }
  593. public static double ShrinkNumber(double value, int accuracy = 1)
  594. {
  595. if (LanguageManager.CurrentLanguage == CurrentLanguage.English)
  596. {
  597. if (value < Amount.千)
  598. {
  599. return value;
  600. }
  601. else if (value < Amount.百万)
  602. {
  603. string str = (value / Amount.千).ToString("F" + (accuracy + 1));
  604. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.千;
  605. }
  606. else if (value < Amount.十亿)
  607. {
  608. string str = (value / Amount.百万).ToString("F" + (accuracy + 1));
  609. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.百万;
  610. }
  611. else if (value < Amount.兆)
  612. {
  613. string str = (value / Amount.十亿).ToString("F" + (accuracy + 1));
  614. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.十亿;
  615. }
  616. else if (value < Amount.千兆)
  617. {
  618. string str = (value / Amount.兆).ToString("F" + (accuracy + 1));
  619. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.兆;
  620. }
  621. else
  622. {
  623. string str = (value / Amount.千兆).ToString("F" + (accuracy + 1));
  624. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.千兆;
  625. }
  626. }
  627. else if (LanguageManager.CurrentLanguage == CurrentLanguage.ChineseSimplified || LanguageManager.CurrentLanguage == CurrentLanguage.ChineseTraditional)
  628. {
  629. if (value < Amount.万)
  630. {
  631. return value;
  632. }
  633. else if (value < Amount.千万)
  634. {
  635. string str = (value / Amount.万).ToString("F" + (accuracy + 1));
  636. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.万;
  637. }
  638. else if (value < Amount.亿)
  639. {
  640. string str = (value / Amount.千万).ToString("F" + (accuracy + 1));
  641. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.千万;
  642. }
  643. else if (value < Amount.千亿)
  644. {
  645. string str = (value / Amount.亿).ToString("F" + (accuracy + 1));
  646. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.亿;
  647. }
  648. else if (value < Amount.兆)
  649. {
  650. string str = (value / Amount.千亿).ToString("F" + (accuracy + 1));
  651. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.千亿;
  652. }
  653. else if (value < Amount.千兆)
  654. {
  655. string str = (value / Amount.兆).ToString("F" + (accuracy + 1));
  656. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.兆;
  657. }
  658. else if (value < Amount.京)
  659. {
  660. string str = (value / Amount.千兆).ToString("F" + (accuracy + 1));
  661. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.千兆;
  662. }
  663. else if (value < Amount.千京)
  664. {
  665. string str = (value / Amount.京).ToString("F" + (accuracy + 1));
  666. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.京;
  667. }
  668. else if (new BigInteger(value.ToString("0")) < Amount.垓)
  669. {
  670. string str = (value / Amount.千京).ToString("F" + (accuracy + 1));
  671. return double.Parse(OmitNumberStr(accuracy, str)) * Amount.千京;
  672. }
  673. else if (new BigInteger(value.ToString("0")) < Amount.千垓)
  674. {
  675. string str = (new BigInteger(value.ToString("0")) / Amount.垓).ToString();
  676. return double.Parse(OmitNumberStr(0, str)) * Amount.千京 * 10;
  677. }
  678. else
  679. {
  680. string str = (new BigInteger(value.ToString("0")) / Amount.千垓).ToString();
  681. return double.Parse(OmitNumberStr(0, str)) * Amount.千京 * 10000;
  682. }
  683. }
  684. else
  685. {
  686. throw new Exception();
  687. }
  688. }
  689. public static string ShrinkNumberStr(double value, int accuracy = 1)
  690. {
  691. if (LanguageManager.CurrentLanguage == CurrentLanguage.English)
  692. {
  693. if (value < Amount.千)
  694. {
  695. return value.ToString("0");
  696. }
  697. else if (value < Amount.百万)
  698. {
  699. string str = (value / Amount.千).ToString("F" + (accuracy + 1));
  700. return OmitNumberStr(accuracy, str) + "K";
  701. }
  702. else if (value < Amount.十亿)
  703. {
  704. string str = (value / Amount.百万).ToString("F" + (accuracy + 1));
  705. return OmitNumberStr(accuracy, str) + "M";
  706. }
  707. else if (value < Amount.兆)
  708. {
  709. string str = (value / Amount.十亿).ToString("F" + (accuracy + 1));
  710. return OmitNumberStr(accuracy, str) + "B";
  711. }
  712. else if (value < Amount.千兆)
  713. {
  714. string str = (value / Amount.兆).ToString("F" + (accuracy + 1));
  715. return OmitNumberStr(accuracy, str) + "T";
  716. }
  717. else
  718. {
  719. string str = (value / Amount.兆).ToString("F" + (accuracy + 1));
  720. return OmitNumberStr(accuracy, str) + "T";
  721. }
  722. }
  723. else if (LanguageManager.CurrentLanguage == CurrentLanguage.ChineseSimplified)
  724. {
  725. if (value < Amount.万)
  726. {
  727. return value.ToString("0");
  728. }
  729. else if (value < Amount.千万)
  730. {
  731. string str = (value / Amount.万).ToString("F" + (accuracy + 1));
  732. return OmitNumberStr(accuracy, str) + "万";
  733. }
  734. else if (value < Amount.亿)
  735. {
  736. string str = (value/Amount.千万).ToString("F" + (accuracy + 1));
  737. return OmitNumberStr(accuracy, str) + "千万";
  738. }
  739. else if (value < Amount.千亿)
  740. {
  741. string str = (value / Amount.亿).ToString("F" + (accuracy + 1));
  742. return OmitNumberStr(accuracy, str) + "亿";
  743. }
  744. else if (value < Amount.兆)
  745. {
  746. string str = (value / Amount.千亿).ToString("F" + (accuracy + 1));
  747. return OmitNumberStr(accuracy, str) + "千亿";
  748. }
  749. else if (value < Amount.千兆)
  750. {
  751. string str = (value / Amount.兆).ToString("F" + (accuracy + 1));
  752. return OmitNumberStr(accuracy, str) + "兆";
  753. }
  754. else if (value < Amount.京)
  755. {
  756. string str = (value / Amount.千兆).ToString("F" + (accuracy + 1));
  757. return OmitNumberStr(accuracy, str) + "千兆";
  758. }
  759. else if (value < Amount.千京)
  760. {
  761. string str = (value / Amount.京).ToString("F" + (accuracy + 1));
  762. return OmitNumberStr(accuracy, str) + "京";
  763. }
  764. else if (new BigInteger(value.ToString("0")) < Amount.垓)
  765. {
  766. string str = (value / Amount.千京).ToString("F" + (accuracy + 1));
  767. return OmitNumberStr(accuracy, str) + "千京";
  768. }
  769. else if (new BigInteger(value.ToString("0")) < Amount.千垓)
  770. {
  771. string str = (new BigInteger(value.ToString("0")) / Amount.垓).ToString();
  772. return OmitNumberStr(0, str) + "垓";
  773. }
  774. else
  775. {
  776. string str = (new BigInteger(value.ToString("0")) / Amount.千垓).ToString();
  777. return OmitNumberStr(0, str) + "千垓";
  778. }
  779. }
  780. else if (LanguageManager.CurrentLanguage == CurrentLanguage.ChineseTraditional)
  781. {
  782. if (value < Amount.万)
  783. {
  784. return value.ToString("0");
  785. }
  786. else if (value < Amount.千万)
  787. {
  788. string str = (value / Amount.万).ToString("F" + (accuracy + 1));
  789. return OmitNumberStr(accuracy, str) + "萬";
  790. }
  791. else if (value < Amount.亿)
  792. {
  793. string str = (value / Amount.千万).ToString("F" + (accuracy + 1));
  794. return OmitNumberStr(accuracy, str) + "千萬";
  795. }
  796. else if (value < Amount.千亿)
  797. {
  798. string str = (value / Amount.亿).ToString("F" + (accuracy + 1));
  799. return OmitNumberStr(accuracy, str) + "億";
  800. }
  801. else if (value < Amount.兆)
  802. {
  803. string str = (value / Amount.千亿).ToString("F" + (accuracy + 1));
  804. return OmitNumberStr(accuracy, str) + "千億";
  805. }
  806. else if (value < Amount.千兆)
  807. {
  808. string str = (value / Amount.兆).ToString("F" + (accuracy + 1));
  809. return OmitNumberStr(accuracy, str) + "兆";
  810. }
  811. else if (value < Amount.京)
  812. {
  813. string str = (value / Amount.千兆).ToString("F" + (accuracy + 1));
  814. return OmitNumberStr(accuracy, str) + "千兆";
  815. }
  816. else if (value < Amount.千京)
  817. {
  818. string str = (value / Amount.京).ToString("F" + (accuracy + 1));
  819. return OmitNumberStr(accuracy, str) + "京";
  820. }
  821. else if (new BigInteger(value.ToString("0")) < Amount.垓)
  822. {
  823. string str = (value / Amount.千京).ToString("F" + (accuracy + 1));
  824. return OmitNumberStr(accuracy, str) + "千京";
  825. }
  826. else if (new BigInteger(value.ToString("0")) < Amount.千垓)
  827. {
  828. string str = (new BigInteger(value.ToString("0")) / Amount.垓).ToString();
  829. return OmitNumberStr(0, str) + "垓";
  830. }
  831. else
  832. {
  833. string str = (new BigInteger(value.ToString("0")) / Amount.千垓).ToString();
  834. return OmitNumberStr(0, str) + "千垓";
  835. }
  836. }
  837. else
  838. {
  839. throw new Exception();
  840. }
  841. }
  842. public static string ImageParse(Current current)
  843. {
  844. if (current == Current.Coin)
  845. {
  846. return TransferLabel.CoinSprite;
  847. }
  848. else if (current == Current.Diamond)
  849. {
  850. return TransferLabel.DiamondSprite;
  851. }
  852. else if (current == Current.Cash)
  853. {
  854. return Language.GetStr(LanguageLabel.Common__Cash);
  855. }
  856. else
  857. {
  858. throw new Exception(current.ToString());
  859. }
  860. }
  861. public static Current CurrentParse(string str)
  862. {
  863. if (string.IsNullOrEmpty(str))
  864. {
  865. return Current.Free;
  866. }
  867. else
  868. {
  869. int number = int.Parse(str);
  870. if (number == 1)
  871. {
  872. return Current.Coin;
  873. }
  874. else if (number == 2)
  875. {
  876. return Current.Diamond;
  877. }
  878. else if (number == 3)
  879. {
  880. return Current.Cash;
  881. }
  882. else if (number == 4)
  883. {
  884. return Current.Other;
  885. }
  886. else if (number == 5)
  887. {
  888. return Current.AD;
  889. }
  890. else
  891. {
  892. throw new Exception(number.ToString());
  893. }
  894. }
  895. }
  896. public static int StringToInt(string str, int defaultValue)
  897. {
  898. if (string.IsNullOrEmpty(str))
  899. {
  900. return defaultValue;
  901. }
  902. else
  903. {
  904. return int.Parse(str);
  905. }
  906. }
  907. public static long StringToLong(string str, long defaultValue)
  908. {
  909. if (string.IsNullOrEmpty(str))
  910. {
  911. return defaultValue;
  912. }
  913. else
  914. {
  915. return long.Parse(str);
  916. }
  917. }
  918. public static bool StringToBool(string str, bool defaultValue)
  919. {
  920. if (string.IsNullOrEmpty(str))
  921. {
  922. return defaultValue;
  923. }
  924. else
  925. {
  926. return Convert.ToBoolean(int.Parse(str));
  927. }
  928. }
  929. public static float StringToFloat(string str, float defaultValue)
  930. {
  931. if (string.IsNullOrEmpty(str))
  932. {
  933. return defaultValue;
  934. }
  935. else
  936. {
  937. return float.Parse(str);
  938. }
  939. }
  940. public static double StringToDouble(string str, double defaultValue)
  941. {
  942. if (string.IsNullOrEmpty(str))
  943. {
  944. return defaultValue;
  945. }
  946. else
  947. {
  948. return float.Parse(str);
  949. }
  950. }
  951. public static Vector3 StringToVector(char seperateChar, string str, Vector3 defaultValue)
  952. {
  953. if (string.IsNullOrEmpty(str))
  954. {
  955. return defaultValue;
  956. }
  957. else
  958. {
  959. string[] strings = str.Split(seperateChar);
  960. if (strings.Length == 2)
  961. {
  962. Vector2 result = new Vector2();
  963. result.x = float.Parse(strings[0]);
  964. result.y = float.Parse(strings[1]);
  965. return result;
  966. }
  967. else if (strings.Length == 3)
  968. {
  969. Vector3 result = new Vector3();
  970. result.x = float.Parse(strings[0]);
  971. result.y = float.Parse(strings[1]);
  972. result.z = float.Parse(strings[2]);
  973. return result;
  974. }
  975. else
  976. {
  977. Debug.Log(str);
  978. throw new Exception();
  979. }
  980. }
  981. }
  982. public static List<int> StringToInts(char seperateChar, string str, List<int> defaultValue)
  983. {
  984. if (string.IsNullOrEmpty(str))
  985. {
  986. return defaultValue;
  987. }
  988. else
  989. {
  990. string[] strings = str.Split(seperateChar);
  991. List<int> list = new List<int>();
  992. for (int i = 0; i < strings.Length; i++)
  993. {
  994. list.Add(int.Parse(strings[i]));
  995. }
  996. return list;
  997. }
  998. }
  999. public static List<string> StringToStrings(char seperateChar, string str, List<string> defaultValue)
  1000. {
  1001. if (string.IsNullOrEmpty(str))
  1002. {
  1003. return defaultValue;
  1004. }
  1005. else
  1006. {
  1007. string[] strings = str.Split(seperateChar);
  1008. List<string> list = new List<string>();
  1009. for (int i = 0; i < strings.Length; i++)
  1010. {
  1011. list.Add(strings[i]);
  1012. }
  1013. return list;
  1014. }
  1015. }
  1016. public static List<double> StringToDoubles(char seperateChar, string str, List<double> defaultValue)
  1017. {
  1018. if (string.IsNullOrEmpty(str))
  1019. {
  1020. return defaultValue;
  1021. }
  1022. else
  1023. {
  1024. string[] strings = str.Split(seperateChar);
  1025. List<double> list = new List<double>();
  1026. for (int i = 0; i < strings.Length; i++)
  1027. {
  1028. list.Add(double.Parse(strings[i]));
  1029. }
  1030. return list;
  1031. }
  1032. }
  1033. public static List<int> StartEndIndexToInts(int startIndex, int endIndex)
  1034. {
  1035. List<int> ints = new List<int>();
  1036. for (int i = startIndex; i <= endIndex; i++)
  1037. {
  1038. ints.Add(i);
  1039. }
  1040. return ints;
  1041. }
  1042. public static string IntsToString(List<int> ints)
  1043. {
  1044. StringBuilder stringBuilder = new StringBuilder();
  1045. for (int i = 0; i < ints.Count; i++)
  1046. {
  1047. stringBuilder.Append(ints[i] + " ");
  1048. }
  1049. return stringBuilder.ToString();
  1050. }
  1051. }