Game Development Reference
In-Depth Information
However, neither Unity nor Mono offers native support for this, which means we
have to code the functionality ourselves, as shown in the following code sample 6-29:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
//Function to read basic ini file to dictionary
public static Dictionary<string, string> ReadINIFile(string
Filename)
{
//If file does not exist on system, then return null
if(!File.Exists(Filename)) return null;
//Create new dictionary
Dictionary<string, string> INIFile = new Dictionary<string,
string>();
//Create new stream reader
using (StreamReader SR = new StreamReader(Filename))
{
//String for current line
string Line;
//Keep reading valid lines
while(!string.IsNullOrEmpty(Line = SR.ReadLine()))
{
//Trim line of leading and trailing white space
Line.Trim();
//Split the line at key=value
string[] Parts = Line.Split(new char[] {'='});
//Now add to dictionary
INIFile.Add(Parts[0].Trim(), Parts[1].Trim());
}
}
//Return dictionary
return INIFile;
}
 
Search WWH ::




Custom Search