using System.Collections; using System.Collections.Generic; using UnityEngine; namespace csvGetData { public class ImportDataGame { public static string GetPage(string _headerText, TextAsset _textAsset) { string page = null; int idx; idx = _textAsset.text.IndexOf(_headerText); if(idx == -1) { Debug.LogWarning(_headerText + " No exits in the TextAsset"); return null; } page = _textAsset.text.Substring(idx); idx = page.IndexOf("end"+_headerText); if(idx == -1) { Debug.LogWarning("This is the last Page"); return page; } page = page.Remove(idx); return page; } public static string GetLine(string _index, string _fileText) { string line = null; int index; index = _fileText.IndexOf(_index); if(index == -1) { Debug.LogWarning("No can find Line"); return null; } line = _fileText.Substring(index); index = line.IndexOf('\n'); line = line.Remove(index); return line; } public static List GetLineValues(string _index, string _fileText, char _separator) { string line = GetLine(_index, _fileText); List valu = GetValue(_index, line, _separator); return valu; } public static string GetLineValue(string _line, int idxValue, char _separator) { string[] values = _line.Split(_separator); /*if (idxValue >= 0 && idxValue <= values.Length) { Debug.LogError("idxValue out of Range"); return null; }*/ return values[idxValue]; } public static string GetValue(string _line,int _index, char _separator) { string[] lines = _line.Split(_separator); return lines[_index]; } public static string GetValue(string _index, string _page, int _idxValue, char _separator) { string line = GetLine(_index, _page); string[] values = line.Split(_separator); string value = values[_idxValue]; return value; } public static List GetValue(string _index, string _fileText,char _separator) { List valu = new List(); string[] values = _fileText.Split(_separator); if (_fileText == null) { Debug.LogWarning("null _fileText in the method"); return valu; } foreach (var value in values) { if (value != _index) { if(value != "") { valu.Add(value); } } } return valu; } public static int[] GetValueArray(string _line) { string[] values = _line.Split('-'); int[] intValues = new int[values.Length]; for (int i = 0; i < values.Length; i++) { intValues[i] = int.Parse(values[i]); } return intValues; } public static List GetLines(string _index, string _page) { int idx = 0; bool startCount = true; List lines = new List(); while (startCount) { idx++; string line = GetLine(_index + idx.ToString(), _page); if (line == null) { startCount = false; return lines; } else { lines.Add(line); } } return lines; } public static string RemoveSymbol(string _text,char _setSymbol = ',',char _removeSymbol = '+') { string text = _text.Replace(_removeSymbol, _setSymbol); return text; } public static List GetLines(string _textAsset, char _separator) { string[] lines = _textAsset.Split('\n'); List listLines = new List(); foreach (var line in lines) { listLines.Add(line); } return listLines; } } }