Auxiliary.cs 25 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
  1. using LitJson;
  2. using DragonBones;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEngine.Events;
  6. using UnityEngine.Advertisements;
  7. using System;
  8. using System.IO;
  9. using System.Xml;
  10. using System.Linq;
  11. using System.Net.Mail;
  12. using System.Net;
  13. using System.Text;
  14. using System.Collections;
  15. using System.Collections.Generic;
  16. using System.Security.Cryptography;
  17. using System.Runtime.Serialization.Formatters.Binary;
  18. using System.Security;
  19. using System.Security.Cryptography.Xml;
  20. using Random = UnityEngine.Random;
  21. using Transform = UnityEngine.Transform;
  22. public enum Unit
  23. {
  24. Second
  25. }
  26. public class Amount
  27. {
  28. public static double 百 = 100;
  29. public static double 千 = 1000;
  30. public static double 万 = 10000;
  31. public static double 十万 = 100000;
  32. public static double 百万 = 1000000;
  33. public static double 千万 = 10000000;
  34. public static double 亿 = 100000000;
  35. public static double 十亿 = 1000000000;
  36. public static double 千亿 = 100000000000;
  37. public static double 万亿 = 1000000000000;
  38. public static double 千万亿 = 1000000000000000;
  39. public static double 万万亿 = 10000000000000000;
  40. }
  41. public class Auxiliary : Regist
  42. {
  43. #region 变量
  44. public string String1;
  45. public string String2;
  46. public TextAsset TextAsset;
  47. public Texture2D Texture;
  48. public Font Font;
  49. public GameObject Go;
  50. public List<GameObject> GoList;
  51. public List<SpriteRenderer> SrList;
  52. public static bool AnyKeyUp;
  53. public static bool AnyKeyDown;
  54. public static Auxiliary Instance;
  55. public static MD5 MD5
  56. {
  57. get
  58. {
  59. if (_MD5 == null)
  60. {
  61. _MD5 = new MD5CryptoServiceProvider();
  62. }
  63. return _MD5;
  64. }
  65. set { _MD5 = value; }
  66. }
  67. public static DESCryptoServiceProvider Des
  68. {
  69. get
  70. {
  71. if (_Des == null)
  72. {
  73. _Des = new DESCryptoServiceProvider();
  74. _Des.IV = Encoding.UTF8.GetBytes("19283740");
  75. _Des.Key = Encoding.UTF8.GetBytes("93287123");
  76. }
  77. return _Des;
  78. }
  79. set { _Des = value; }
  80. }
  81. private static MD5 _MD5;
  82. private static DESCryptoServiceProvider _Des;
  83. #endregion
  84. public override bool RegistImmed()
  85. {
  86. if (base.RegistImmed())
  87. {
  88. return true;
  89. }
  90. enabled = true;
  91. return false;
  92. }
  93. private void Awake()
  94. {
  95. Instance = this;
  96. //gameObject.AddComponent<ManaAnim>().RegistImmed();
  97. }
  98. private void Update()
  99. {
  100. #region 调试
  101. if (Input.GetKeyDown(KeyCode.Escape))
  102. {
  103. }
  104. if (Input.GetKeyDown(KeyCode.N))
  105. {
  106. ManaData.PlayerDoc.SelectSingleNode("PlayerConfig").SelectSingleNode("Version").Attributes[0].Value = 670.ToString();
  107. //foreach (var VARIABLE in ManaGarden.FlowerInfoDic)
  108. //{
  109. // if (!VARIABLE.Value.Unlock)
  110. // {
  111. // VARIABLE.Value.Unlock = true;
  112. // }
  113. //}
  114. }
  115. if (Input.GetKeyDown(KeyCode.B))
  116. {
  117. for (int i = 0; i < ManaCenter.UseList.Count; i++)
  118. {
  119. ManaCenter.UseList[i].UseTimer = 0;
  120. }
  121. for (int i = 0; i < ManaCenter.CoolList.Count; i++)
  122. {
  123. ManaCenter.CoolList[i].CoolTimer = 0;
  124. }
  125. }
  126. if (Input.GetKeyDown(KeyCode.Z))
  127. {
  128. ManaCenter.MiniTimer = 0;
  129. }
  130. if (Input.GetKeyDown(KeyCode.X))
  131. {
  132. ManaMiniGame.Score = 1000;
  133. }
  134. if (Input.GetKeyDown(KeyCode.C))
  135. {
  136. ManaMiniGame.GameTimer = 45;
  137. }
  138. if (Input.GetKeyDown(KeyCode.V))
  139. {
  140. ManaGarden.ElfTimer = 0;
  141. }
  142. //if (Input.GetKeyDown(KeyCode.P))
  143. //{
  144. // ManaData.Level += 20;
  145. //}
  146. //if (Input.GetKeyDown(KeyCode.O))
  147. //{
  148. // for (int i = 0; i < ManaData.SkillList.Count; i++)
  149. // {
  150. // ManaData.SkillList[i].ReceiveCool(1, true, true);
  151. // }
  152. //}
  153. //if (Input.GetKeyDown(KeyCode.I))
  154. //{
  155. // ManaCenter.Coin += 1000;
  156. // ManaCenter.Diamond += 1000;
  157. //}
  158. //if (Input.GetKeyDown(KeyCode.U))
  159. //{
  160. // Data.SavePlayerConfig();
  161. // Data.SaveXml();
  162. //}
  163. //if (Input.GetKeyDown(KeyCode.Y))
  164. //{
  165. // Data.ResetPlayerConfig();
  166. // Data.SaveXml();
  167. //}
  168. //if (Input.GetKeyDown(KeyCode.T))
  169. //{
  170. // ManaData.Pause = !ManaData.Pause;
  171. //}
  172. #endregion
  173. #region 输入检测
  174. if (Input.GetKeyDown(KeyCode.Escape))
  175. {
  176. ManaMiniGame.Pause = true;
  177. Bubble.Show(Language.GetStr("Common", "QuitGame"), null, null, Application.Quit, () => { ManaMiniGame.Pause = false; });
  178. }
  179. if (AnyKeyUp)
  180. {
  181. if (Input.anyKey == false)
  182. {
  183. AnyKeyUp = false;
  184. }
  185. }
  186. if (Input.anyKeyDown)
  187. {
  188. AnyKeyDown = true;
  189. }
  190. if (AnyKeyDown)
  191. {
  192. if (Input.anyKey == false)
  193. {
  194. AnyKeyUp = true;
  195. AnyKeyDown = false;
  196. }
  197. }
  198. #endregion
  199. }
  200. public static byte[] GetMD5(object obj)
  201. {
  202. MemoryStream memoryStream = new MemoryStream();
  203. BinaryFormatter binaryFormatter = new BinaryFormatter();
  204. binaryFormatter.Serialize(memoryStream, obj);
  205. byte[] bytes = memoryStream.GetBuffer();
  206. memoryStream.Dispose();
  207. return MD5.ComputeHash(bytes);
  208. }
  209. public static void EncryptXml(XmlDocument doc)
  210. {
  211. EncryptedXml encryptedXml = new EncryptedXml();
  212. XmlElement xmlElement = doc.DocumentElement;
  213. byte[] bytes = encryptedXml.EncryptData(xmlElement, Des, false);
  214. EncryptedData encryptedData = new EncryptedData();
  215. encryptedData.Type = EncryptedXml.XmlEncElementUrl;
  216. encryptedData.EncryptionMethod = new EncryptionMethod(EncryptedXml.XmlEncDESUrl);
  217. encryptedData.CipherData.CipherValue = bytes;
  218. EncryptedXml.ReplaceElement(xmlElement, encryptedData, false);
  219. }
  220. public static void DecryptXml(XmlDocument doc)
  221. {
  222. EncryptedXml encryptedXml = new EncryptedXml();
  223. XmlElement encryptXmlElement = (XmlElement)doc.GetElementsByTagName("EncryptedData")[0];
  224. EncryptedData encryptedData = new EncryptedData();
  225. encryptedData.LoadXml(encryptXmlElement);
  226. byte[] bytes = encryptedXml.DecryptData(encryptedData, Des);
  227. encryptedXml.ReplaceData(encryptXmlElement, bytes);
  228. }
  229. public static byte[] Encrypt(string str)
  230. {
  231. byte[] bytes = Encoding.UTF8.GetBytes(str);
  232. byte[] encryptBytes = Des.CreateEncryptor().TransformFinalBlock(bytes, 0, bytes.Length);
  233. return encryptBytes;
  234. }
  235. public static byte[] ToBytes(string str)
  236. {
  237. string[] strings = str.Split(' ');
  238. byte[] bytes = new byte[strings.Length];
  239. for (int i = 0; i < bytes.Length; i++)
  240. {
  241. bytes[i] = byte.Parse(strings[i]);
  242. }
  243. return bytes;
  244. }
  245. public static string Decrypt(string str)
  246. {
  247. byte[] encryptBytes = ToBytes(str);
  248. byte[] decryptBytes = Des.CreateDecryptor().TransformFinalBlock(encryptBytes, 0, encryptBytes.Length);
  249. return Encoding.UTF8.GetString(decryptBytes);
  250. }
  251. public static string ToString(byte[] bytes)
  252. {
  253. StringBuilder strB = new StringBuilder();
  254. for (int i = 0; i < bytes.Length; i++)
  255. {
  256. if (i == bytes.Length - 1)
  257. {
  258. strB.Append(bytes[i]);
  259. }
  260. else
  261. {
  262. strB.Append(bytes[i] + " ");
  263. }
  264. }
  265. return strB.ToString();
  266. }
  267. public static void CompileDic(Transform tra, Dictionary<string, Transform> dic, bool enableIgnore = true)
  268. {
  269. Transform[] transforms = tra.GetComponentsInChildren<Transform>(true);
  270. for (int i = 0; i < transforms.Length; i++)
  271. {
  272. if (enableIgnore)
  273. {
  274. if (transforms[i].GetComponent<IgnoreIndexing>())
  275. {
  276. continue;
  277. }
  278. }
  279. if (dic.ContainsKey(transforms[i].name))
  280. {
  281. throw new Exception(transforms[i].name);
  282. }
  283. else
  284. {
  285. dic.Add(transforms[i].name, transforms[i]);
  286. }
  287. }
  288. }
  289. public static string GetUnit(int value, Unit unit)
  290. {
  291. if (unit == Unit.Second)
  292. {
  293. if (ManaLan.CurrentLan == Lan.English)
  294. {
  295. if (value == 0 || value == 1)
  296. {
  297. return " Second";
  298. }
  299. else
  300. {
  301. return " Seconds";
  302. }
  303. }
  304. else if (ManaLan.CurrentLan == Lan.ChineseSimplified)
  305. {
  306. return "秒";
  307. }
  308. else if (ManaLan.CurrentLan == Lan.ChineseTraditional)
  309. {
  310. return "秒";
  311. }
  312. else
  313. {
  314. throw new Exception();
  315. }
  316. }
  317. else
  318. {
  319. throw new Exception();
  320. }
  321. }
  322. public static string GetStreamPath()
  323. {
  324. if (Application.isEditor)
  325. {
  326. return "file://" + Application.streamingAssetsPath;
  327. }
  328. else if (Application.platform == RuntimePlatform.IPhonePlayer)
  329. {
  330. return "file://" + Application.streamingAssetsPath;
  331. }
  332. else if (Application.isMobilePlatform)
  333. {
  334. return Application.streamingAssetsPath;
  335. }
  336. else
  337. {
  338. throw new Exception();
  339. }
  340. }
  341. public void DelayCall(UnityAction function, int frame)
  342. {
  343. StartCoroutine(IDelayCall(function, frame));
  344. }
  345. public void DelayCall(UnityAction function, float time)
  346. {
  347. StartCoroutine(IDelayCall(function, time));
  348. }
  349. public static IEnumerator IDelayCall(UnityAction function, int frame)
  350. {
  351. int count = 0;
  352. while (count < frame)
  353. {
  354. count++;
  355. yield return null;
  356. }
  357. function.Invoke();
  358. }
  359. public static IEnumerator IDelayCall(UnityAction function, float time)
  360. {
  361. yield return new WaitForSeconds(time);
  362. function.Invoke();
  363. }
  364. public static string FmlParse1(string str)
  365. {
  366. int index = 0;
  367. int openIndex = 0;
  368. bool flag = false;
  369. bool group = false;
  370. for (int i = 0; i < str.Length; i++)
  371. {
  372. if (group)
  373. {
  374. if (str[i] == '+' || str[i] == '-' || str[i] == '*' || str[i] == '/')
  375. {
  376. str = str.Replace(openIndex, i - 1, FmlParse2(str[index], str.Between(openIndex, index - 1), str.Between(index + 1, i - 1)));
  377. i = 0;
  378. group = false;
  379. }
  380. else if (i == str.Length - 1)
  381. {
  382. str = str.Replace(openIndex, i, FmlParse2(str[index], str.Between(openIndex, index - 1), str.Between(index + 1, i)));
  383. break;
  384. }
  385. }
  386. else
  387. {
  388. if (str[i] == '+' || str[i] == '-')
  389. {
  390. flag = true;
  391. openIndex = i + 1;
  392. }
  393. else if (str[i] == '*' || str[i] == '/')
  394. {
  395. index = i;
  396. group = true;
  397. if (!flag)
  398. {
  399. openIndex = 0;
  400. }
  401. }
  402. }
  403. }
  404. group = false;
  405. for (int i = 0; i < str.Length; i++)
  406. {
  407. if (group)
  408. {
  409. if (str[i] == '+' || str[i] == '-')
  410. {
  411. str = str.Replace(0, i - 1, FmlParse2(str[index], str.Between(0, index - 1), str.Between(index + 1, i - 1)));
  412. i = -1;
  413. group = false;
  414. }
  415. else if (i == str.Length - 1)
  416. {
  417. return FmlParse2(str[index], str.Between(0, index - 1), str.Between(index + 1, i));
  418. }
  419. }
  420. else
  421. {
  422. if (str[i] == '+' || str[i] == '-')
  423. {
  424. index = i;
  425. group = true;
  426. }
  427. }
  428. }
  429. return str;
  430. }
  431. public static string FmlParse2(char op, string str1, string str2)
  432. {
  433. double var1 = double.Parse(str1);
  434. double var2 = double.Parse(str2);
  435. if (op == '+')
  436. {
  437. return (var1 + var2).ToString();
  438. }
  439. else if (op == '-')
  440. {
  441. return (var1 - var2).ToString();
  442. }
  443. else if (op == '*')
  444. {
  445. return (var1 * var2).ToString();
  446. }
  447. else if (op == '/')
  448. {
  449. return (var1 / var2).ToString();
  450. }
  451. else
  452. {
  453. throw new Exception(op.ToString());
  454. }
  455. }
  456. public static double FmlParse(string str, params string[] strings)
  457. {
  458. for (int i = 0; i < strings.Length; i += 2)
  459. {
  460. if (str.Contains(strings[i]))
  461. {
  462. str = str.Replace(strings[i], strings[i + 1]);
  463. }
  464. else
  465. {
  466. //Debug.Log("No such var " + strings[i + 1]);
  467. }
  468. }
  469. int openIndex = 0;
  470. for (int i = 0; i < str.Length; i++)
  471. {
  472. if (str[i] == '(')
  473. {
  474. openIndex = i;
  475. }
  476. else if (str[i] == ')')
  477. {
  478. str = str.Replace(openIndex, i, FmlParse1(str.Between(openIndex + 1, i - 1)));
  479. i = -1;
  480. }
  481. }
  482. return double.Parse(FmlParse1(str));
  483. }
  484. public static string OmitNumberStr(int accuray, string str)
  485. {
  486. int index = str.IndexOf('.');
  487. if (index == -1)
  488. {
  489. return str;
  490. }
  491. if (accuray == 0)
  492. {
  493. return str.Substring(0, index);
  494. }
  495. else
  496. {
  497. return str.Substring(0, index + accuray + 1);
  498. }
  499. }
  500. public static long ShrinkNumber(double value, int accuracy = 1)
  501. {
  502. long longValue = (long) value;
  503. if (ManaLan.CurrentLan == Lan.English)
  504. {
  505. if (longValue < Amount.千)
  506. {
  507. return longValue;
  508. }
  509. else if (longValue < Amount.百万)
  510. {
  511. long temp = (long) Amount.百;
  512. return (longValue/ temp) * temp;
  513. }
  514. else if (longValue < Amount.十亿)
  515. {
  516. long temp = (long)Amount.十万;
  517. return (longValue / temp) * temp;
  518. }
  519. else if (longValue < Amount.万亿)
  520. {
  521. long temp = (long)Amount.亿;
  522. return (longValue / temp) * temp;
  523. }
  524. else if (longValue < Amount.千万亿)
  525. {
  526. long temp = (long)Amount.千亿;
  527. return (longValue / temp) * temp;
  528. }
  529. else
  530. {
  531. long temp = (long)Amount.千亿;
  532. return (longValue / temp) * temp;
  533. }
  534. }
  535. else if (ManaLan.CurrentLan == Lan.ChineseSimplified || ManaLan.CurrentLan == Lan.ChineseTraditional)
  536. {
  537. if (longValue < Amount.万)
  538. {
  539. return longValue;
  540. }
  541. else if (longValue < Amount.亿)
  542. {
  543. long temp = (long)Amount.千;
  544. return (longValue / temp) * temp;
  545. }
  546. else if (longValue < Amount.万亿)
  547. {
  548. long temp = (long)Amount.千万;
  549. return (longValue / temp) * temp;
  550. }
  551. else if (longValue < Amount.万万亿)
  552. {
  553. long temp = (long)Amount.千亿;
  554. return (longValue / temp) * temp;
  555. }
  556. else
  557. {
  558. long temp = (long)Amount.千亿;
  559. return (longValue / temp) * temp;
  560. }
  561. }
  562. else
  563. {
  564. throw new Exception();
  565. }
  566. }
  567. public static string ShrinkNumberStr(double value, int accuracy = 1)
  568. {
  569. long longValue = (long) value;
  570. if (ManaLan.CurrentLan == Lan.English)
  571. {
  572. if (longValue < Amount.千)
  573. {
  574. return longValue.ToString();
  575. }
  576. else if (longValue < Amount.百万)
  577. {
  578. string str = (longValue / Amount.千).ToString();
  579. return OmitNumberStr(accuracy, str) + "K";
  580. }
  581. else if (longValue < Amount.十亿)
  582. {
  583. string str = (longValue / Amount.百万).ToString();
  584. return OmitNumberStr(accuracy, str) + "M";
  585. }
  586. else if (longValue < Amount.万亿)
  587. {
  588. string str = (longValue / Amount.十亿).ToString();
  589. return OmitNumberStr(accuracy, str) + "B";
  590. }
  591. else if (longValue < Amount.千万亿)
  592. {
  593. string str = (longValue / Amount.万亿).ToString();
  594. return OmitNumberStr(accuracy, str) + "T";
  595. }
  596. else
  597. {
  598. string str = (longValue / Amount.万亿).ToString();
  599. return OmitNumberStr(accuracy, str) + "T";
  600. }
  601. }
  602. else if (ManaLan.CurrentLan == Lan.ChineseSimplified)
  603. {
  604. if (longValue < Amount.万)
  605. {
  606. return longValue.ToString();
  607. }
  608. else if (longValue < Amount.亿)
  609. {
  610. string str = (longValue/Amount.万).ToString();
  611. return OmitNumberStr(accuracy, str) + "万";
  612. }
  613. else if (longValue < Amount.万亿)
  614. {
  615. string str = (longValue / Amount.亿).ToString();
  616. return OmitNumberStr(accuracy, str) + "亿";
  617. }
  618. else if (longValue < Amount.万万亿)
  619. {
  620. string str = (longValue / Amount.万亿).ToString();
  621. return OmitNumberStr(accuracy, str) + "万亿";
  622. }
  623. else
  624. {
  625. string str = (longValue / Amount.万亿).ToString();
  626. return OmitNumberStr(accuracy, str) + "万亿";
  627. }
  628. }
  629. else if (ManaLan.CurrentLan == Lan.ChineseTraditional)
  630. {
  631. if (longValue < Amount.万)
  632. {
  633. return longValue.ToString();
  634. }
  635. else if (longValue < Amount.亿)
  636. {
  637. string str = (longValue / Amount.万).ToString();
  638. return OmitNumberStr(accuracy, str) + "萬";
  639. }
  640. else if (longValue < Amount.万亿)
  641. {
  642. string str = (longValue / Amount.亿).ToString();
  643. return OmitNumberStr(accuracy, str) + "億";
  644. }
  645. else if (longValue < Amount.万万亿)
  646. {
  647. string str = (longValue / Amount.万亿).ToString();
  648. return OmitNumberStr(accuracy, str) + "萬億";
  649. }
  650. else
  651. {
  652. string str = (longValue / Amount.万亿).ToString();
  653. return OmitNumberStr(accuracy, str) + "萬億";
  654. }
  655. }
  656. else
  657. {
  658. throw new Exception();
  659. }
  660. }
  661. public static string ImageParse(Current current)
  662. {
  663. if (current == Current.Coin)
  664. {
  665. return "<(金币)>";
  666. }
  667. else if (current == Current.Diamond)
  668. {
  669. return "<(钻石)>";
  670. }
  671. else if (current == Current.Cash)
  672. {
  673. return Language.GetStr("Common", "Cash");
  674. }
  675. else
  676. {
  677. throw new Exception(current.ToString());
  678. }
  679. }
  680. public static Current CurrentParse(string str)
  681. {
  682. if (string.IsNullOrEmpty(str))
  683. {
  684. return Current.Free;
  685. }
  686. else
  687. {
  688. int number = int.Parse(str);
  689. if (number == 1)
  690. {
  691. return Current.Coin;
  692. }
  693. else if (number == 2)
  694. {
  695. return Current.Diamond;
  696. }
  697. else if (number == 3)
  698. {
  699. return Current.Cash;
  700. }
  701. else if (number == 4)
  702. {
  703. return Current.Other;
  704. }
  705. else if (number == 5)
  706. {
  707. return Current.AD;
  708. }
  709. else
  710. {
  711. throw new Exception(number.ToString());
  712. }
  713. }
  714. }
  715. public static int IntParse(string str, int defaultValue)
  716. {
  717. if (string.IsNullOrEmpty(str))
  718. {
  719. return defaultValue;
  720. }
  721. else
  722. {
  723. return int.Parse(str);
  724. }
  725. }
  726. public static long LongParse(string str, long defaultValue)
  727. {
  728. if (string.IsNullOrEmpty(str))
  729. {
  730. return defaultValue;
  731. }
  732. else
  733. {
  734. return long.Parse(str);
  735. }
  736. }
  737. public static bool BoolParse(string str, bool defaultValue)
  738. {
  739. if (string.IsNullOrEmpty(str))
  740. {
  741. return defaultValue;
  742. }
  743. else
  744. {
  745. return Convert.ToBoolean(int.Parse(str));
  746. }
  747. }
  748. public static float FloatParse(string str, float defaultValue)
  749. {
  750. if (string.IsNullOrEmpty(str))
  751. {
  752. return defaultValue;
  753. }
  754. else
  755. {
  756. return float.Parse(str);
  757. }
  758. }
  759. public static double DoubleParse(string str, double defaultValue)
  760. {
  761. if (string.IsNullOrEmpty(str))
  762. {
  763. return defaultValue;
  764. }
  765. else
  766. {
  767. return float.Parse(str);
  768. }
  769. }
  770. public static Vector3 VectorParse(char cah, string str, Vector3 defaultValue)
  771. {
  772. if (string.IsNullOrEmpty(str))
  773. {
  774. return defaultValue;
  775. }
  776. else
  777. {
  778. string[] strings = str.Split(',');
  779. if (strings.Length == 2)
  780. {
  781. Vector2 result = new Vector2();
  782. result.x = float.Parse(strings[0]);
  783. result.y = float.Parse(strings[1]);
  784. return result;
  785. }
  786. else if (strings.Length == 3)
  787. {
  788. Vector3 result = new Vector3();
  789. result.x = float.Parse(strings[0]);
  790. result.y = float.Parse(strings[1]);
  791. result.z = float.Parse(strings[2]);
  792. return result;
  793. }
  794. else
  795. {
  796. throw new Exception();
  797. }
  798. }
  799. }
  800. public static List<int> IntListParse(char cah, string str, List<int> defaultValue)
  801. {
  802. if (string.IsNullOrEmpty(str))
  803. {
  804. return defaultValue;
  805. }
  806. else
  807. {
  808. string[] strings = str.Split(cah);
  809. List<int> list = new List<int>();
  810. for (int i = 0; i < strings.Length; i++)
  811. {
  812. list.Add(int.Parse(strings[i]));
  813. }
  814. return list;
  815. }
  816. }
  817. public static List<string> StringListParse(char cah, string str, List<string> defaultValue)
  818. {
  819. if (string.IsNullOrEmpty(str))
  820. {
  821. return defaultValue;
  822. }
  823. else
  824. {
  825. string[] strings = str.Split(cah);
  826. List<string> list = new List<string>();
  827. for (int i = 0; i < strings.Length; i++)
  828. {
  829. list.Add(strings[i]);
  830. }
  831. return list;
  832. }
  833. }
  834. public static List<double> DoubleListParse(char cah, string str, List<double> defaultValue)
  835. {
  836. if (string.IsNullOrEmpty(str))
  837. {
  838. return defaultValue;
  839. }
  840. else
  841. {
  842. string[] strings = str.Split(cah);
  843. List<double> list = new List<double>();
  844. for (int i = 0; i < strings.Length; i++)
  845. {
  846. list.Add(double.Parse(strings[i]));
  847. }
  848. return list;
  849. }
  850. }
  851. }