From 70c8d57c118b6b2c46720928f36719545b00e3d3 Mon Sep 17 00:00:00 2001 From: "Crom (Thibaut CHARLES)" Date: Sun, 9 Nov 2014 00:40:35 +0100 Subject: [PATCH] Lecture des valeurs 2DA --- Assets/src/TwoDA.cs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Assets/src/TwoDA.cs b/Assets/src/TwoDA.cs index 47b9bba..c2c8eb5 100644 --- a/Assets/src/TwoDA.cs +++ b/Assets/src/TwoDA.cs @@ -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