Game Development Reference
In-Depth Information
A dictionary returned from this function will match the structure of the INI file.
Therefore, values can be accessed in the form string Value = MyDictionary["Key"]; .
You can also enumerate through all key and value members of a dictionary inside a
foreach , as shown in the following code sample 6-30:
//Build a dictionary from an INI file
Dictionary<string,string> DB = ReadINIFile(@"c:\myfile.ini");
//List all entries in dictionary
foreach(KeyValuePair<string, string> Entry in DB)
{
//Loop through each key and value pair
Debug.Log("Key: " + Entry.Key + " Value: " + Entry.Value);
}
Text Assets - loading from the CSV files
Earlier in this chapter, we saw how to process a CSV file that features character
names, both male and female. Let's now see some source code to load CSV from a file
on disk into an array of strings, with each string separated by a comma, as shown in
the following code sample 6-31:
//Function to load a string array from a CSV file
public static string[] LoadFromCSV(string Filename)
{
//If file does not exist on system, then return null
if(!File.Exists(Filename)) return null;
//Get all text
string AllText = File.ReadAllText(Filename);
//Return string array
return AllText.Split(new char[] {','});
}
 
Search WWH ::




Custom Search