-
Notifications
You must be signed in to change notification settings - Fork 1
/
Config.cs
77 lines (71 loc) · 2.25 KB
/
Config.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using UnityEngine;
using System;
using System.IO;
using System.Text;
using System.Collections;
public class Config : Singleton<Config> {
public string filename = "config.ini";
private InputController _inputController;
void Awake()
{
//Initialize Singletons
_inputController = InputController.Instance;
loadFile(filename);
// Other stuff
}
void loadFile(string filename)
{
if (!File.Exists(filename))
{
File.CreateText(filename);
return;
}
try
{
string line;
StreamReader sReader = new StreamReader(filename, Encoding.Default);
do
{
line = sReader.ReadLine();
if (line != null)
{
// Lines with # are for comments
if (!line.Contains("#"))
{
// Value property identified by string before the colon.
string[] data = line.Split(':');
if (data.Length == 2)
{
string val = data[1].Trim();
string key = data[0].Trim().ToLower();
switch (key)
{
case "player count":
int count = int.Parse(val);
//Do stuff
break;
case "ip address":
string address = val;
//Do stuff
break;
case "port":
int port = int.Parse(val);
//Do stuff
break;
default:
break;
}
}
}
}
}
while (line != null);
sReader.Close();
return;
}
catch (Exception e)
{
Debug.Log(e);
}
}
}