-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.cs
More file actions
executable file
·54 lines (49 loc) · 1.74 KB
/
Copy pathConfig.cs
File metadata and controls
executable file
·54 lines (49 loc) · 1.74 KB
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
using Newtonsoft.Json;
using System;
using System.IO;
using System.Reflection;
using UnityEngine;
namespace oni_vietnamese.Config {
public class FontConfig {
public string Filename { get; set; }
public string Code { get; set; }
public bool LeftToRight { get; set; }
public float Scale { get; set; }
public FontConfig(string filename, string code, bool leftToRight, float scale) {
this.Filename = filename;
this.Code = code;
this.LeftToRight = leftToRight;
this.Scale = scale;
}
}
public class ConfigManager {
private readonly string ns = MethodBase.GetCurrentMethod().DeclaringType.Namespace;
private static readonly object _lock = new object();
private static ConfigManager instance;
public string configPath { get; set; }
public static ConfigManager Instance {
get {
lock (_lock) {
if (instance == null) {
instance = new ConfigManager();
}
return instance;
}
}
}
public FontConfig LoadConfigFile() {
FontConfig fc;
try {
using (var r = new StreamReader(Path.Combine(configPath, "config.json"))) {
var json = r.ReadToEnd();
fc = JsonConvert.DeserializeObject<FontConfig>(json);
}
} catch (Exception e) {
Debug.Log($"[{ns}] Load config failure...Excption: {e.Message}");
Debug.Log($"[{ns}] Use default config.");
fc = new FontConfig("font", "zh", true, 1);
}
return fc;
}
}
}