123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- 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<string> GetLineValues(string _index, string _fileText, char _separator)
- {
- string line = GetLine(_index, _fileText);
- List<string> 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<string> GetValue(string _index, string _fileText,char _separator)
- {
- List<string> valu = new List<string>();
- 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<string> GetLines(string _index, string _page)
- {
- int idx = 0;
- bool startCount = true;
- List<string> lines = new List<string>();
- 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<string> GetLines(string _textAsset, char _separator)
- {
- string[] lines = _textAsset.Split('\n');
- List<string> listLines = new List<string>();
- foreach (var line in lines)
- {
- listLines.Add(line);
- }
- return listLines;
- }
-
- }
- }
|