ImpotDataGame.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace csvGetData
  5. {
  6. public class ImportDataGame
  7. {
  8. public static string GetPage(string _headerText, TextAsset _textAsset)
  9. {
  10. string page = null;
  11. int idx;
  12. idx = _textAsset.text.IndexOf(_headerText);
  13. if(idx == -1)
  14. {
  15. Debug.LogWarning(_headerText + " No exits in the TextAsset");
  16. return null;
  17. }
  18. page = _textAsset.text.Substring(idx);
  19. idx = page.IndexOf("end"+_headerText);
  20. if(idx == -1)
  21. {
  22. Debug.LogWarning("This is the last Page");
  23. return page;
  24. }
  25. page = page.Remove(idx);
  26. return page;
  27. }
  28. public static string GetLine(string _index, string _fileText)
  29. {
  30. string line = null;
  31. int index;
  32. index = _fileText.IndexOf(_index);
  33. if(index == -1)
  34. {
  35. Debug.LogWarning("No can find Line");
  36. return null;
  37. }
  38. line = _fileText.Substring(index);
  39. index = line.IndexOf('\n');
  40. line = line.Remove(index);
  41. return line;
  42. }
  43. public static List<string> GetLineValues(string _index, string _fileText, char _separator)
  44. {
  45. string line = GetLine(_index, _fileText);
  46. List<string> valu = GetValue(_index, line, _separator);
  47. return valu;
  48. }
  49. public static string GetLineValue(string _line, int idxValue, char _separator)
  50. {
  51. string[] values = _line.Split(_separator);
  52. /*if (idxValue >= 0 && idxValue <= values.Length)
  53. {
  54. Debug.LogError("idxValue out of Range");
  55. return null;
  56. }*/
  57. return values[idxValue];
  58. }
  59. public static string GetValue(string _line,int _index, char _separator)
  60. {
  61. string[] lines = _line.Split(_separator);
  62. return lines[_index];
  63. }
  64. public static string GetValue(string _index, string _page, int _idxValue, char _separator)
  65. {
  66. string line = GetLine(_index, _page);
  67. string[] values = line.Split(_separator);
  68. string value = values[_idxValue];
  69. return value;
  70. }
  71. public static List<string> GetValue(string _index, string _fileText,char _separator)
  72. {
  73. List<string> valu = new List<string>();
  74. string[] values = _fileText.Split(_separator);
  75. if (_fileText == null)
  76. {
  77. Debug.LogWarning("null _fileText in the method");
  78. return valu;
  79. }
  80. foreach (var value in values)
  81. {
  82. if (value != _index)
  83. {
  84. if(value != "")
  85. {
  86. valu.Add(value);
  87. }
  88. }
  89. }
  90. return valu;
  91. }
  92. public static int[] GetValueArray(string _line)
  93. {
  94. string[] values = _line.Split('-');
  95. int[] intValues = new int[values.Length];
  96. for (int i = 0; i < values.Length; i++)
  97. {
  98. intValues[i] = int.Parse(values[i]);
  99. }
  100. return intValues;
  101. }
  102. public static List<string> GetLines(string _index, string _page)
  103. {
  104. int idx = 0;
  105. bool startCount = true;
  106. List<string> lines = new List<string>();
  107. while (startCount)
  108. {
  109. idx++;
  110. string line = GetLine(_index + idx.ToString(), _page);
  111. if (line == null)
  112. {
  113. startCount = false;
  114. return lines;
  115. }
  116. else
  117. {
  118. lines.Add(line);
  119. }
  120. }
  121. return lines;
  122. }
  123. public static string RemoveSymbol(string _text,char _setSymbol = ',',char _removeSymbol = '+')
  124. {
  125. string text = _text.Replace(_removeSymbol, _setSymbol);
  126. return text;
  127. }
  128. public static List<string> GetLines(string _textAsset, char _separator)
  129. {
  130. string[] lines = _textAsset.Split('\n');
  131. List<string> listLines = new List<string>();
  132. foreach (var line in lines)
  133. {
  134. listLines.Add(line);
  135. }
  136. return listLines;
  137. }
  138. }
  139. }