add project files
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
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<T>(string subPath, out T obj)
|
||||
{
|
||||
string path = GetFullPersitantPath(subPath);
|
||||
Debug.Log("Loading " + path);
|
||||
try
|
||||
{
|
||||
if (File.Exists(path))
|
||||
{
|
||||
obj = JsonUtility.FromJson<T>(File.ReadAllText(path));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogException(e);
|
||||
}
|
||||
obj = default(T);
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void SaveData<T>(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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user