forked from cgvr/DeltaVR
40 lines
900 B
C#
40 lines
900 B
C#
|
|
using System.IO;
|
|
using UnityEngine;
|
|
|
|
public class ConfigManager : MonoBehaviour
|
|
{
|
|
public GameConfig Config { get; private set; }
|
|
public static ConfigManager Instance { get; private set; }
|
|
public static string configPath = "config.json";
|
|
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
LoadConfig();
|
|
}
|
|
|
|
public void LoadConfig()
|
|
{
|
|
if (File.Exists(configPath))
|
|
{
|
|
string json = File.ReadAllText(configPath);
|
|
Config = JsonUtility.FromJson<GameConfig>(json);
|
|
}
|
|
else
|
|
{
|
|
// Create config with default values
|
|
Config = new GameConfig();
|
|
SaveConfig();
|
|
}
|
|
|
|
Debug.Log("Loaded config from: " + configPath);
|
|
}
|
|
|
|
public void SaveConfig()
|
|
{
|
|
string json = JsonUtility.ToJson(Config, true);
|
|
File.WriteAllText(configPath, json);
|
|
}
|
|
}
|