using System.Collections; using System.Collections.Generic; using System.IO; using Fort23.UTool; using UnityEngine; using Utility; public class AccountFileInfo : Singleton { private string persistentDataPath = Application.persistentDataPath + "/playerData.txt"; public PlayerData playerData = new PlayerData(); [System.Serializable] public class PlayerData { /// /// 主力英雄数据(主力等级(=afk2的共鸣等级)) /// public List HeroListInLeadDatas = new List(); /// /// 后备英雄(共享等级) /// public List HeroListInBackDatas = new List(); } 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)) { LogTool.Log("没有文件: " + persistentDataPath); ClearInitPlayerData(); // File.Create(persistentDataPath).Close(); } LogTool.Log("读取=文件: " + persistentDataPath); StreamReader sr = File.OpenText(persistentDataPath); string data = sr.ReadToEnd(); sr.Close(); playerData = new PlayerData(); JsonUtility.FromJsonOverwrite(data, playerData); } public void SavePlayerData() { if (!string.IsNullOrEmpty(persistentDataPath)) { string playerSettingJson = JsonManager.ToJson(playerData); File.WriteAllText(persistentDataPath, playerSettingJson); } } /// /// 不要服务器的话,这里初始化玩家的起始数据 /// public void ClearInitPlayerData() { HeroData heroData1 = new HeroData { heroModelId = 105, heroPowerId = 1, heroPromoteId = 3 }; HeroData heroData2 = new HeroData { heroModelId = 107, heroPowerId = 1, heroPromoteId = 3 }; HeroData heroData3 = new HeroData { heroModelId = 116, heroPowerId = 1, heroPromoteId = 3 }; playerData.HeroListInLeadDatas.Add(heroData1); playerData.HeroListInLeadDatas.Add(heroData2); playerData.HeroListInLeadDatas.Add(heroData3); SavePlayerData(); } [System.Serializable] public class HeroData { /// /// 英雄基础信息 /// public int heroModelId; /// /// 英雄等级 /// public int heroPowerId; /// /// 星级 /// public int heroPromoteId; } }