Previous post: http://blog.kennyist.com/?p=864

Github: https://github.com/kennyist/Unity_tools

In this version i have added the ability to have sections and have also updated the ini formatting. With sections you can also use multiple keys with the same name as long as they are in different sections. The usage is pretty much the same as the previous with a few minor changes:

Usage update:

the main difference is to setting and getting. To set you now have to use:

parser.Set(KEY NAME, KEY SECTION, KEY VALUE);

Key section can be empty and will show up in the ini at the top with all other nu-sectioned keys. You still add a comment like so:

parser.Set(KEY NAME, SECTION, VALUE, COMMENT);

Getting the key is exactly the same, But if you have multiple of the same name, it will only return the first. So there is now a new Get overload:

parser.Get(KEY NAME, KEY SECTION);

The saved ini file:

So if i was creating an ini with differant sections like so (doesnt matter what order you use):

parser.Set("resolution","graphics","1920x1080");
parser.Set("antiAlias","graphics","8","Can only be: 0, 1, 2, 4, 8");
parser.Set("UncatagorizedKey1","","1","Keys can be created without sections and will be displayed that the top");
parser.Set("UncatagorizedKey2","","2","Sections are sorted by name, Keys are not");
parser.Set("mode","audio","sterio");
parser.Set("masterLevel","audio","100","Can only be 0 - 100");
parser.Set("musicLevel","audio","75");
parser.save(IniFiles.SETTINGS);

It will be shown like this in the .ini file:

UncatagorizedKey1=1										; Keys can be created without sections and will be displayed that the top
UncatagorizedKey2=2										; Sections are sorted by name, Keys are not



mode=sterio
masterLevel=100											; Can only be 0 - 100
musicLevel=75

[graphics]

resolution=1920x1080
antiAlias=8											; Can only be: 0, 1, 2, 4, 8

One main difference is that comments are displayed 60 characters away from line start, meaning you can only use 60 characters for name and value, This can be easily changed in the Save method.

Code:

The code is now available on gitHub: https://github.com/kennyist/Unity_tools

Categories: CodeUnity

Leave a Reply

Your email address will not be published.