|
@@ -7,12 +7,15 @@ using GameLogic.Bag;
|
|
|
using GameLogic.Hero;
|
|
|
using UnityEngine;
|
|
|
using Utility;
|
|
|
+using WeChatWASM;
|
|
|
|
|
|
public class AccountFileInfo : Singleton<AccountFileInfo>
|
|
|
{
|
|
|
public string persistentDataPath = Application.persistentDataPath + "/playerData.txt";
|
|
|
public PlayerData playerData = new PlayerData();
|
|
|
|
|
|
+ public string fileName = "/playerData.txt";
|
|
|
+
|
|
|
[System.Serializable]
|
|
|
public class PlayerData
|
|
|
{
|
|
@@ -35,14 +38,23 @@ public class AccountFileInfo : Singleton<AccountFileInfo>
|
|
|
|
|
|
public void LoadPlayerData()
|
|
|
{
|
|
|
-// #if UNITY_EDITOR || UNITY_STANDALONE_WIN
|
|
|
-// persistentDataPath = Application.streamingAssetsPath + $"/{playerId}playerSetting.txt";
|
|
|
-// #elif UNITY_ANDROID
|
|
|
-// playerSettingPath = Application.persistentDataPath+$"/{playerId}playerSetting.txt";
|
|
|
-// #elif UNITY_IPHONE
|
|
|
-// playerSettingPath = Application.persistentDataPath+$"/{playerId}playerSetting.txt";
|
|
|
-// #endif
|
|
|
- if (!File.Exists(persistentDataPath))
|
|
|
+#if UNITY_WEIXINMINIGAME
|
|
|
+ persistentDataPath = WX.env.USER_DATA_PATH + fileName;
|
|
|
+
|
|
|
+ WXFileSystemManager wxFileSystemManager = WX.GetFileSystemManager();
|
|
|
+ if (wxFileSystemManager.AccessSync(persistentDataPath).Equals("access:ok"))
|
|
|
+ {
|
|
|
+ string data = wxFileSystemManager.ReadFileSync(persistentDataPath, "utf8");
|
|
|
+ playerData = new PlayerData();
|
|
|
+ JsonUtility.FromJsonOverwrite(data, playerData);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ ClearInitPlayerData();
|
|
|
+ SavePlayerData();
|
|
|
+ }
|
|
|
+#else
|
|
|
+ if (!File.Exists(persistentDataPath))
|
|
|
{
|
|
|
LogTool.Log("没有文件: " + persistentDataPath);
|
|
|
ClearInitPlayerData();
|
|
@@ -55,6 +67,7 @@ public class AccountFileInfo : Singleton<AccountFileInfo>
|
|
|
sr.Close();
|
|
|
playerData = new PlayerData();
|
|
|
JsonUtility.FromJsonOverwrite(data, playerData);
|
|
|
+#endif
|
|
|
}
|
|
|
|
|
|
|
|
@@ -123,13 +136,23 @@ public class AccountFileInfo : Singleton<AccountFileInfo>
|
|
|
if (!string.IsNullOrEmpty(persistentDataPath))
|
|
|
{
|
|
|
string playerSettingJson = JsonManager.ToJson(playerData);
|
|
|
- File.WriteAllText(persistentDataPath, playerSettingJson);
|
|
|
+#if UNITY_WEIXINMINIGAME
|
|
|
+ WXFileSystemManager wxFileSystemManager = WX.GetFileSystemManager();
|
|
|
+ wxFileSystemManager.WriteFileSync(persistentDataPath, playerSettingJson, "utf8");
|
|
|
+#else
|
|
|
+ File.WriteAllText(persistentDataPath, playerSettingJson);
|
|
|
+#endif
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public void DeleteFile(string filePath)
|
|
|
{
|
|
|
- if (File.Exists(filePath))
|
|
|
+#if UNITY_WEIXINMINIGAME
|
|
|
+ playerData = new PlayerData();
|
|
|
+ SavePlayerData();
|
|
|
+ ClearInitPlayerData();
|
|
|
+#else
|
|
|
+ if (File.Exists(filePath))
|
|
|
{
|
|
|
File.Delete(filePath); // 删除文件
|
|
|
LogTool.Log($"文件已删除:{filePath}");
|
|
@@ -138,6 +161,7 @@ public class AccountFileInfo : Singleton<AccountFileInfo>
|
|
|
{
|
|
|
LogTool.Log($"文件不存在:{filePath}");
|
|
|
}
|
|
|
+#endif
|
|
|
}
|
|
|
|
|
|
/// <summary>
|