mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
Update ClientSaveData.cs
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using Newtonsoft.Json;
|
using System.Text;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace TEngine
|
namespace TEngine
|
||||||
@@ -43,6 +44,8 @@ namespace TEngine
|
|||||||
|
|
||||||
public class ClientSaveData
|
public class ClientSaveData
|
||||||
{
|
{
|
||||||
|
private StringBuilder _stringBuilder = new StringBuilder();
|
||||||
|
|
||||||
public static string GetSaveUniqPrefix()
|
public static string GetSaveUniqPrefix()
|
||||||
{
|
{
|
||||||
string hashPath = UnityUtil.GetHashCodeByString(Application.dataPath).ToString();
|
string hashPath = UnityUtil.GetHashCodeByString(Application.dataPath).ToString();
|
||||||
@@ -65,15 +68,16 @@ namespace TEngine
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static T Load<T>(T type) where T : class
|
public static T Load<T>(string keyName, int userId = 0) where T : class
|
||||||
{
|
{
|
||||||
T ret = default(T);
|
T ret = default(T);
|
||||||
|
|
||||||
string typeName = typeof(T).Name;
|
string typeName = typeof(T).Name + keyName;
|
||||||
|
|
||||||
string fullName = GetSaveUniqPrefix() + typeName;
|
string fullName = GetSaveUniqPrefix() + typeName + userId;
|
||||||
|
|
||||||
var jsonString = PlayerPrefs.GetString(fullName);
|
var jsonString = PlayerPrefs.GetString(fullName);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(jsonString))
|
if (!string.IsNullOrEmpty(jsonString))
|
||||||
{
|
{
|
||||||
ret = Deserialize<T>(jsonString);
|
ret = Deserialize<T>(jsonString);
|
||||||
@@ -81,30 +85,34 @@ namespace TEngine
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool Save<T>(T type) where T : class
|
public static bool Save<T>(string keyName, T type, int userId = 0) where T : class
|
||||||
{
|
{
|
||||||
var jsonTex = ClientSaveData.Serialize<T>(type);
|
var jsonTex = Serialize<T>(type);
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(jsonTex))
|
if (!string.IsNullOrEmpty(jsonTex))
|
||||||
{
|
{
|
||||||
TLogger.LogInfoSuccessd(jsonTex);
|
TLogger.LogInfoSuccessd(jsonTex);
|
||||||
return Save<string>(jsonTex);
|
|
||||||
|
return Save<T>(keyName, jsonTex, userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool Save<T>(string json) where T : class
|
public static bool Save<T>(string keyName, string json, int userId = 0) where T : class
|
||||||
{
|
{
|
||||||
var ret = false;
|
var ret = false;
|
||||||
|
|
||||||
string typeName = typeof(T).Name;
|
string typeName = typeof(T).Name + keyName;
|
||||||
|
|
||||||
string fullName = GetSaveUniqPrefix() + typeName;
|
string fullName = GetSaveUniqPrefix() + typeName + userId;
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(json))
|
if (!string.IsNullOrEmpty(json))
|
||||||
{
|
{
|
||||||
PlayerPrefs.SetString(fullName, json);
|
PlayerPrefs.SetString(fullName, json);
|
||||||
|
|
||||||
PlayerPrefs.Save();
|
PlayerPrefs.Save();
|
||||||
|
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user