Lecture des valeurs 2DA
This commit is contained in:
parent
cd19c701d9
commit
70c8d57c11
1 changed files with 20 additions and 1 deletions
|
@ -17,7 +17,6 @@ public class TwoDA : Object {
|
|||
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){
|
||||
|
@ -38,6 +37,18 @@ public class TwoDA : Object {
|
|||
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(){
|
||||
string sMsg = "";
|
||||
foreach(string s in m_header){
|
||||
|
@ -54,6 +65,14 @@ public class TwoDA : Object {
|
|||
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_data;
|
||||
|
|
Loading…
Add table
Reference in a new issue