加入用户最近100场战绩记录并实现展示
This commit is contained in:
@@ -1,48 +1,55 @@
|
||||
using UnityEngine;
|
||||
using System.IO;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json;
|
||||
using UnityEngine;
|
||||
|
||||
public static class JsonDataHandler
|
||||
{
|
||||
public static string File_Path_Folder => Application.persistentDataPath + "/FILE/";
|
||||
static readonly string File_Suffix = ".json";
|
||||
private const string SaveCategory = "generic_json_data";
|
||||
private static readonly string FileSuffix = ".json";
|
||||
|
||||
public static string File_Path_Folder => Path.Combine(Application.persistentDataPath, "FILE");
|
||||
|
||||
public static string File_Path(string file_Name)
|
||||
{
|
||||
return File_Path_Folder + file_Name + File_Suffix;
|
||||
return Path.Combine(File_Path_Folder, file_Name + FileSuffix);
|
||||
}
|
||||
|
||||
public static void Save<T>(T data, string file_Name, string saver_Name)
|
||||
{
|
||||
string json = JsonConvert.SerializeObject(data, Formatting.Indented);
|
||||
string legacyPath = File_Path(file_Name);
|
||||
|
||||
if (!SecureSaveVault.SaveRawJson(SaveCategory, file_Name, json, legacyPath))
|
||||
{
|
||||
Debug.LogWarning($"[JsonDataHandler] Save failed: {file_Name}");
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
Debug.Log($"_Save_[{file_Name}{FileSuffix}]_FROM_[{saver_Name}]\nSECURE::{SaveCategory}/{file_Name}");
|
||||
}
|
||||
|
||||
public static bool Try_Load<T>(ref T data, string file_Name)
|
||||
{
|
||||
var path = File_Path(file_Name);
|
||||
if (!File.Exists(path))
|
||||
string json;
|
||||
if (!SecureSaveVault.TryLoadRawJson(SaveCategory, file_Name, out json, File_Path(file_Name)))
|
||||
{
|
||||
Debug.Log($"Load_[{file_Name}]_NULL");
|
||||
return false;
|
||||
}
|
||||
data = JsonConvert.DeserializeObject<T>(System.IO.File.ReadAllText(path));
|
||||
|
||||
data = JsonConvert.DeserializeObject<T>(json);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static T Load<T>(string file_Name)
|
||||
{
|
||||
var path = File_Path(file_Name);
|
||||
if (!System.IO.File.Exists(path))
|
||||
string json;
|
||||
if (!SecureSaveVault.TryLoadRawJson(SaveCategory, file_Name, out json, File_Path(file_Name)))
|
||||
{
|
||||
Debug.Log($"Load_[{file_Name}]_NULL");
|
||||
return default;
|
||||
//return T;
|
||||
}
|
||||
return JsonConvert.DeserializeObject<T>(System.IO.File.ReadAllText(path));
|
||||
|
||||
return JsonConvert.DeserializeObject<T>(json);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user