using System.IO; using System.Collections; using System.Collections.Generic; using UnityEngine; using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace BITKit { public static partial class Utility { public static partial class Config { public static bool TryGetConfig(string configName, out T value) { var path = Utility.Path.CombinePath(Utility.Path.persistentDataPath, $"{configName}.json"); if (File.Exists(path)) { var json = File.ReadAllText(path); value = JsonConvert.DeserializeObject(json); return true; } value = default; return false; } public static T GetConfig(string configName) where T : new() { if (TryGetConfig(configName, out var config)) { } else { SaveConfig(configName, new()); TryGetConfig(configName, out config); } return config; } public static void SaveConfig(string configName, T value) { var json = JsonConvert.SerializeObject(value, Formatting.Indented); var path = Utility.Path.CombinePath(Utility.Path.persistentDataPath, $"{configName}.json"); File.WriteAllText(path, json); } } } public class ConfigSO : ScriptableObject { public string json; } }