Auxiliary.cs 24 KB

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