Showing posts with label INI Reader. Show all posts
Showing posts with label INI Reader. Show all posts

Wednesday, 18 April 2012

INISystem: Updated Tutorial


So with the 2.0 release of INISystem there comes a bunch of breaking changes code side. So this is an updated tutorial showing some basic usage.

Loading an .ini file called config, that doesn't require Unity specific DataTypes.
INIContent config;
try
{
 config = INIFile.Read("config.ini"); // Reads the file from disk.
}
catch (System.IO.FileNotFoundException ex)// INIFile.Read throws a FileNotFound exception when the file doesn't exist.
{
 // You can now place any handling of that, such as creating an INI file.
 config = new INIContent();
 INIFile.Write(ex.FileName, config);
}
Loading an .ini file called config, that requires Unity specific DataTypes (e.g. Color, Vector2)
INIUnity unityConfig;
try
{
 config = INIFile.Read("config.ini").ToINIUnity(); // Reads the file from disk.
}
catch (System.IO.FileNotFoundException ex)// INIFile.Read throws a FileNotFound exception when the file doesn't exist.
{
 // You can now place any handling of that, such as creating an INI file.
 config = new INIUnity();
 INIFile.Write(ex.FileName, config);
}
To get an entry from the INI file it is as simple as it was before, even simpler when using Unity DataTypes. (The following assumes you have loaded an INI file by the previous method for Unity Specific.
// To load a string
string text = config.GetString("text", "General", "Default text, if no text is found");
// To load an integer
int number = config.GetInt("number", "General", );
// To load a Unity specific DataType (Color)
Color hudColor = config.GetColor("HUDColor", "General", Color.White);
// To load a Unity specific DataType (Vector2)
Vector2 menuLocation = config.GetVector2("menuLocation", "General", new Vector2(10,10));
The following is used to change an INI entry. (Assumes that the second loading method was used to set up a config object of type INIUnity)
// Changing a string value
config.Change("text", "New text that will now be loaded", "General");
// Changing a integer value
config.Change("number", 5, "General");
// Changing a Unity specific DataType (Color)
config.Change("hudColor", Color.Green, "General");
// Changing a Unity specific DataType (Vector2)
config.Change("menuLocation", new Vector2(50,180), "General");
Finally to save the changes back to file, it is fairly simple. (The following assumes that you have followed the previous example and made changes to the config)
// Saves the changes to file.
if (INIFile.Write("config.ini", (INIContent)config))
 Debug.Log("File saved successfully!");
else
 Debug.Log("Error encountered while trying to save config file");
I hope this tutorial has enlightened you to the changes in version 2.0. You can purchase INISystem from Unity's Asset Store at: http://u3d.as/content/corrupted-smile-studio/inisystem

Regards, Garth

Update

I apologise for the lack of updates over the last couple of weeks. I have been busy with university which sucks up a lot of my time and energy. However, there is some good news hidden somewhere.

I have released updates to both INISystem and JukeBox Pro, so check them out on Unity's Asset Store. I will be doing an update to the previous INISystem tutorial as a lot has changed since version 1.1.

I also took some time to look at Canyon Project again my on and off game project for the last year or so. I have been playing around with trying to get that optimised so that it can run on a PC that isn't a quad core. So I got to focus some time on that.

I shall be seeing you guys around soon,
Garth

Monday, 28 November 2011

INISystem Update 1.11 - Bug Fix


I decided to push the bug fix release of INISystem before the new release has even been approved. This version has a couple breaking features in it.

Such as the classes are no longer under the CSS namespace instead they are under CorruptedSmileStudio.INI namespace. This change was made to ensure that there should never be any clashes with other classes with similar names. The main class is also compiled as a DLL, this is just to ensure if there are any bugs that get reported I will know that it is not as a result of my code being changed. The INIHelper class however is not in the DLL but free, this allows a programmer to add their own parsers to the class as they see fit.

I hope this won't cause too much disruption and updating your code to reflect these changes shouldn't take longer than 5 minutes or less.

Regards,
Garth (Lead)