Chargement tables 2DA
This commit is contained in:
parent
27555de329
commit
cd19c701d9
|
@ -0,0 +1,5 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2888cbe7ebb784642a964f4c7dd302ec
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
|
@ -0,0 +1,3 @@
|
||||||
|
id name value
|
||||||
|
0 test0 testvalue0
|
||||||
|
1 test1 testvalue1
|
|
@ -0,0 +1,4 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 19ee65d3703a2c4418dad22daa24bdf6
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
|
@ -0,0 +1,5 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 93d127da9094f784f9c43e734e301345
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
|
@ -0,0 +1,60 @@
|
||||||
|
using UnityEngine;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
public class TwoDA : 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();
|
||||||
|
int nCols = m_header.Length;
|
||||||
|
|
||||||
|
m_data = new string[100, nCols-1];//TODO: make this array dynamic instead of 100
|
||||||
|
|
||||||
|
int nFileLine = 1;
|
||||||
|
while((line = file.ReadLine()) != null)
|
||||||
|
{
|
||||||
|
Debug.Log(line);
|
||||||
|
if(line[0] != '#'){//Ignore commented lines
|
||||||
|
string[] linedata = line.Split();
|
||||||
|
if(linedata.Length == nCols){
|
||||||
|
int nLine = int.Parse(linedata[0]);
|
||||||
|
|
||||||
|
for(int i=0 ; i<nCols-1 ; i++){
|
||||||
|
m_data[nLine, i] = linedata[i+1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
Debug.LogWarning(filepath+":"+nFileLine.ToString()+" ignored. Found "+linedata.Length.ToString()+" columns instead of "+nCols.ToString());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
nFileLine++;
|
||||||
|
}
|
||||||
|
|
||||||
|
file.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString(){
|
||||||
|
string sMsg = "";
|
||||||
|
foreach(string s in m_header){
|
||||||
|
sMsg += s+"\t";
|
||||||
|
}
|
||||||
|
sMsg += "\n";
|
||||||
|
for(int line=0 ; line<m_data.GetLength(0) ; line++){
|
||||||
|
sMsg += line.ToString() + "\t";
|
||||||
|
for(int col=0 ; col<m_data.GetLength(1) ; col++){
|
||||||
|
sMsg += m_data[line, col]+"\t";
|
||||||
|
}
|
||||||
|
sMsg += "\n";
|
||||||
|
}
|
||||||
|
return sMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private string[] m_header;
|
||||||
|
private string[,] m_data;
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3a5b231b19851264abe393511e1d5ccb
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
Loading…
Reference in New Issue