整合包
gameplay bundle has been imported together
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
using UnityEngine;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
public static class JsonDataHandler
|
||||
{
|
||||
public static string File_Path_Folder => Application.persistentDataPath + "/FILE/";
|
||||
static readonly string File_Suffix = ".json";
|
||||
public static string File_Path(string file_Name)
|
||||
{
|
||||
return File_Path_Folder + file_Name + File_Suffix;
|
||||
}
|
||||
public static void Save<T>(T data, string file_Name, string saver_Name)
|
||||
{
|
||||
|
||||
|
||||
var path = File_Path(file_Name);
|
||||
if (!File.Exists(path)) Directory.CreateDirectory(File_Path_Folder);
|
||||
|
||||
var file_Data = JsonConvert.SerializeObject(data, Formatting.Indented);
|
||||
// file_Data = $"//SAVER:[{saver_Name}]\n" + file_Data;
|
||||
File.WriteAllText(path, file_Data);
|
||||
|
||||
Debug.Log($"_Save_[{file_Name}{File_Suffix}]_FROM_[{saver_Name}]\n" + path);
|
||||
}
|
||||
public static bool Try_Load<T>(ref T data, string file_Name)
|
||||
{
|
||||
var path = File_Path(file_Name);
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
Debug.Log($"Load_[{file_Name}]_NULL");
|
||||
return false;
|
||||
}
|
||||
data = JsonConvert.DeserializeObject<T>(System.IO.File.ReadAllText(path));
|
||||
return true;
|
||||
}
|
||||
public static T Load<T>(string file_Name)
|
||||
{
|
||||
var path = File_Path(file_Name);
|
||||
if (!System.IO.File.Exists(path))
|
||||
{
|
||||
Debug.Log($"Load_[{file_Name}]_NULL");
|
||||
return default;
|
||||
//return T;
|
||||
}
|
||||
return JsonConvert.DeserializeObject<T>(System.IO.File.ReadAllText(path));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user