Coder Social home page Coder Social logo

unity-inistorage's Introduction

IniStorage for Unity - Working with ini files in Unity!

  • Code can be changed! :)

  • Tested on Unity:

    • 2021.2.7f1

In Unity forum: https://forum.unity.com/threads/read-write-ini-file.857215/


How to put?

Move the script to the project.

Example:

Code:

var ini = new IniStorage(Application.dataPath + "/config.ini");

if(!ini.Contains("Test"))
    ini.Set("Test", "Test string")
        .ClearComments()
        .AddComment("Test comment")
        .AddComment("Test comment 2");

if (!ini.Contains("Test2"))
    ini.Set("Test2", "Test string");

if (!ini.Contains("Test3"))
    ini.Set("Test3", "Test string");

if (!ini.Contains("Test4"))
    ini.Set("Test4", "Test string")
        .AddComment("Test comment");

if (!ini.Contains("Test5"))
    ini.Set("Test5", "Test string");

if (!ini.Contains("TestGroup", "Test"))
    ini.Set("TestGroup", "Test", 5.545434f)
        .ClearComments()
        .AddComment("Test group pair comment");

if (!ini.Contains("TestGroup", "Test2"))
    ini.Set("TestGroup", "Test2", "Test value");

ini.GetGroup("TestGroup")
    .ClearComments()
    .AddComment("Test group comment!");

if (!ini.Contains("TestGroup", "Test3"))
    ini.Set("TestGroup", "Test3", "Test value 2");

if (!ini.ContainsEndComment("End comment"))
    ini.ClearEndComments()
        .AddEndComment("End comment")
        .AddEndComment("End comment 2");

ini.Save();

Debug.Log(ini.GetStringOrDefault("Test", "None"));
Debug.Log(ini.GetFloat("TestGroup", "Test"));
Debug.Log(ini.GetFloatOrDefault("TestGroup", "Test2", 0f));

config.ini:

#Test comment
#Test comment 2
Test=Test string
Test2=Test string
Test3=Test string
Test4=Test string
Test5=Test string

#Test group comment!
[TestGroup]

#Test group pair comment
Test=5,545434
Test2=Test value
Test3=Test value 2

#End comment
#End comment 2

Logs:

Test string
5.545434
0

unity-inistorage's People

Contributors

illa4257 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.