Game Development Reference
In-Depth Information
//File exists, now load text from file
return File.ReadAllText(Filename);
}
The code sample 6-26 loads a complete text file into one string object. You might,
however, prefer to process a text file line by line instead, especially if the file is
a configuration file where values are specified in separate lines. For this, see the
following code sample 6-27:
//Function to load text data, line by line, into a string array
public static string[] LoadTextAsLines(string Filename)
{
//If file does not exist on system, then return empty array
if(!File.Exists(Filename)) return null;
//Get lines
return File.ReadAllLines(Filename);
}
Text Assets - loading from the INI files
Among the many text file types, you can load a common format is the INI file.
It's, perhaps, not as common with Unity games, because many developers use the
PlayerPreferences class instead to store application settings. Even so, the INI files
offer the advantage of storing application configuration data in only one place and
in the same format across many different platforms. For this reason, there are strong
reasons to use INI files. Refer to the code sample 6-28 for an example INI that uses a
key-value pairing format:
ApplicationName=MyTestApp
Date=1st Nov 2014
Author=Alan Thorn
Engine=Unity
Build=Production
An ideal data structure to load INI files is the dictionary that mirrors a key-value pair
structure. For this reason, it'd be great to load an INI file into a dictionary.
 
Search WWH ::




Custom Search