using UnityEngine; using System.Collections.Generic; using System.Text.RegularExpressions; public class TwoDA : UnityEngine.Object { public TwoDA(string filepath) { // Read the file and display it line by line. System.IO.StreamReader file = new System.IO.StreamReader(filepath); string line = file.ReadLine(); m_header = line.Split((string[])null, System.StringSplitOptions.RemoveEmptyEntries); int nCols = m_header.Length; m_data = new List(); int nFileLine = 1; while((line = file.ReadLine()) != null) { if(line[0] != '#') { //Ignore commented lines MatchCollection matches = m_rgxField.Matches(line); if(matches.Count == nCols) { int nLine = int.Parse(matches[0].Value); string[] buff = new string[nCols-1]; for(int i=0 ; i=0) { return m_data[nRow][nCol]; } else { throw new UnityException("Column '"+sColumn+"' not found in 2DA"); } } public override string ToString() { string sMsg = ""; foreach(string s in m_header) { sMsg += s+"\t"; } sMsg += "\n"; for(int line=0 ; line m_data; }