Showing posts with label ini Files. Show all posts
Showing posts with label ini Files. 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)

INISystem Update: Version 1.1


I have posted an update to INISystem, to the Unity Asset Store, it is currently awaiting approval. This version brings some parsers for both reading and writing some of Unity's data-types and some basic data-types.

There is a new static class that helps with Unity data-types and the basic data-types are included in the base class.

Unity Data-Types:

  • Vector2
  • Vector3
  • Color
  • Quaternion
Basic Data-Types:
  • Float
  • Integer
  • Bool
  • String (which was already included)
Also Get has been depreciated in favour of GetString, this just brings the system together because there are now various parser methods available. So in order to get any of the previous mentioned types it would be as simple as GetFloat, GetInt, GetBool.

However with the new Unity specific data-types you have to access it through INIHelper.GetVector2/Vector3/Color/Quaternion. With these methods, you will have to pass a reference to an INISystem class that you have created in order to be able to read /edit values.

This version also completely removed the Add methods in favour of using Change which is more robust and developed than Add was.

Regards,
Garth (Lead)

Thursday, 24 November 2011

INISystem - Intro Tutorial


Here's a very simple introduction tutorial for INISystem (Available on Unity's Asset Store Now).

You will need to purchase and download INISystem from http://u3d.as/content/corrupted-smile-studio/inisystem. Once downloaded you will have a new folder called INISystem within your project. this contains all the required files (one in total), an example scene, an example HUD script and a Readme PDF.

The INISystem main class is contained with the CSS namespace. This means that you will need to add using CSS; to the top of the file creating the INISystem class.

You will then need to create an instance of the INISystem class.
INISystem ini = new INISystem();
To load a file it is as easy as calling ini.LoadFile(PathToFile); which returns a boolean based on whether the file was loaded or not. Then you can read strings from the file via ini.GetString("elementName", "SectionName", "Optional Default Value");


To change a value and then save the file you can make use of ini.Change("elementName", "NewValue", "SectionName"); which will either change a current value or add it if it doesn't exist. To save to file use ini.Save(pathToFile);


I hope this short intro tutorial will help you understand how easy this system is to use.

Regards,
Garth (Lead)

Tuesday, 22 November 2011

INISystem: V1 Released


Version 1 of INISystem has been approved on the Unity Asset Store. Head over there now to get file based settings enabled in your game.

Asset Store Link

Regards,
Garth (Lead)

Friday, 18 November 2011

INISystem - Awaiting Approval


While working on Canyon Project we developed a system which allows easy reading, editing and creating of ini files (simple config type files). It works with sections, which allows there to be multiple "variables" with the same name under different sections.

A basic ini layout will be similar to the following:
[general]
startLevel=1
language=En

[graphics]
width=1920
height=1080
anti-aliasing=8x
The system simplifies the processing of these files to allow you to access elements within each section regardless of whether there are elements with the same name under different sections.

INISystem will only work correctly with standalone builds as it makes use of System.IO for reading and saving.
It has only been tested on a Windows 7 (x64) pc but should work with Mac and other Windows versions.

It has currently been uploaded to Unity's Asset Store where it will be available soon, hopefully, for $10.

Name: INISystem
Source: C#
Price: $10
Asset Store Link

Regards,
Garth (Lead)