using System; using System.IO; using UnityEngine; using UnityEngine.UI; namespace OHM.UnityToolkit { public static class PersitantDataUtils { public static string GetFullPersitantPath(string subPath) { return Application.persistentDataPath + "/" + subPath; } public static bool LoadData(string subPath, out T obj) { string path = GetFullPersitantPath(subPath); Debug.Log("Loading " + path); try { if (File.Exists(path)) { obj = JsonUtility.FromJson(File.ReadAllText(path)); return true; } } catch (Exception e) { Debug.LogException(e); } obj = default(T); return false; } public static void SaveData(string subPath, T obj) { try { File.WriteAllText(GetFullPersitantPath(subPath), JsonUtility.ToJson(obj)); } catch (Exception e) { Debug.LogException(e); } } public static void RemoveData(string subPath) { if (File.Exists(GetFullPersitantPath(subPath))) { File.Delete(subPath); } } } }