Auxiliary.cs 24 KB

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