1

Im working on this project and I am quite new to c#. I want to load configuration from a file. I dont know how to quite explain it, or maybe I'm just retarded because I get nothing of what I'm looking for when I try to search it, but let me try and explain, heres my code:

    public class Example : MonoBehaviour
{
    int min = 0;
    int sec = 10;
    void Start()
    {
        InvokeRepeating("ResetItems", 1, min * 60 + sec);
        if (min * 60 + sec > 60)
        {
            InvokeRepeating("Warning", 1, min * 60 + sec - 60);
        }
    }
    void Warning()
    {
        NetworkChat.sendAlert("Items Respawning in one minute");
    }
    void ResetItems()
    {
        NetworkChat.sendAlert("Items respawning..");
        SpawnItems.reset();
    }
}

Now what I want to do is make it so I have a config file that reads something like this:

min=1
sec=20

so in my project, those integers will change. or be set to what's in the external config file rather than having to go and manually edit it.

  • you want a config file to read the content and then do the c# thing on it? – Afzaal Ahmad Zeeshan Aug 02 '14 at 21:57
  • 2
    You haven't been able to find ANYTHING related to `ConfigurationManager` and an XML file? – Tdorno Aug 02 '14 at 22:04
  • possible duplicate of [Reading/writing an INI file](http://stackoverflow.com/questions/217902/reading-writing-an-ini-file) – ahruss Aug 02 '14 at 22:09
  • If you really just want key-value pairs, it's really simple to write a parse yourself... just open the file, iterate over lines, split on =, and parse the RHS. – ahruss Aug 02 '14 at 22:12

1 Answers1

1

Right click on your project and go to Properties.

There is a Settings tab.

From there you can add properties like so: enter image description here

These properties are now available in your App.Config file:

<applicationSettings>
    <CSharpWinForms.Properties.Settings>
        <setting name="min" serializeAs="String">
            <value>1</value>
        </setting>
        <setting name="sec" serializeAs="String">
            <value>20</value>
        </setting>
    </CSharpWinForms.Properties.Settings>
</applicationSettings>

To access them you use the Properties.Settings.Default class like so:

var min = Properties.Settings.Default.min;
var sec = Properties.Settings.Default.sec;
John Koerner
  • 37,428
  • 8
  • 84
  • 134
  • This worked, in the build file and called it Plugin1.dll.config I will edit this file to the linking of my choices correct? – Daniel Nunez Aug 02 '14 at 22:27