Lecture des valeurs 2DA
This commit is contained in:
parent
cd19c701d9
commit
70c8d57c11
|
@ -17,7 +17,6 @@ public class TwoDA : Object {
|
||||||
int nFileLine = 1;
|
int nFileLine = 1;
|
||||||
while((line = file.ReadLine()) != null)
|
while((line = file.ReadLine()) != null)
|
||||||
{
|
{
|
||||||
Debug.Log(line);
|
|
||||||
if(line[0] != '#'){//Ignore commented lines
|
if(line[0] != '#'){//Ignore commented lines
|
||||||
string[] linedata = line.Split();
|
string[] linedata = line.Split();
|
||||||
if(linedata.Length == nCols){
|
if(linedata.Length == nCols){
|
||||||
|
@ -38,6 +37,18 @@ public class TwoDA : Object {
|
||||||
file.Close();
|
file.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string GetValue(int nRow, string sColumn){
|
||||||
|
|
||||||
|
int nCol = FindHeaderCol(sColumn);
|
||||||
|
if(nCol>=0){
|
||||||
|
return m_data[nRow, nCol];
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
throw new UnityException("Column '"+sColumn+"' not found in 2DA");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public override string ToString(){
|
public override string ToString(){
|
||||||
string sMsg = "";
|
string sMsg = "";
|
||||||
foreach(string s in m_header){
|
foreach(string s in m_header){
|
||||||
|
@ -54,6 +65,14 @@ public class TwoDA : Object {
|
||||||
return sMsg;
|
return sMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int FindHeaderCol(string sColName){
|
||||||
|
for(int i=0 ; i<m_header.Length ; i++){
|
||||||
|
if(m_header[i] == sColName)
|
||||||
|
return i-1;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private string[] m_header;
|
private string[] m_header;
|
||||||
private string[,] m_data;
|
private string[,] m_data;
|
||||||
|
|
Loading…
Reference in New Issue