123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using Fort23.UTool;
- using UnityEngine;
- using Utility;
- public class AccountFileInfo : Singleton<AccountFileInfo>
- {
-
- public string persistentDataPath = Application.persistentDataPath + "/playerData.txt";
- public PlayerData playerData = new PlayerData();
-
- [System.Serializable]
- public class PlayerData
- {
- /// <summary>
- /// 主力英雄数据(主力等级(=afk2的共鸣等级))
- /// </summary>
- public List<HeroData> HeroListInLeadDatas = new List<HeroData>();
-
- /// <summary>
- /// 后备英雄(共享等级)
- /// </summary>
- public List<HeroData> HeroListInBackDatas = new List<HeroData>();
- }
-
- 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 DeleteFile(string filePath)
- {
- if (File.Exists(filePath))
- {
- File.Delete(filePath); // 删除文件
- LogTool.Log($"文件已删除:{filePath}");
- }
- else
- {
- LogTool.Log($"文件不存在:{filePath}");
- }
- }
- /// <summary>
- /// 不要服务器的话,这里初始化玩家的起始数据
- /// </summary>
- 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
- };
- HeroData heroData4 = new HeroData
- {
- heroModelId = 113,
- heroPowerId = 1,
- heroPromoteId = 3
- };
- playerData.HeroListInLeadDatas.Add(heroData1);
- playerData.HeroListInLeadDatas.Add(heroData2);
- playerData.HeroListInLeadDatas.Add(heroData3);
- playerData.HeroListInLeadDatas.Add(heroData4);
- SavePlayerData();
- }
-
- [System.Serializable]
- public class HeroData
- {
- /// <summary>
- /// 英雄基础信息
- /// </summary>
- public int heroModelId;
- /// <summary>
- /// 英雄等级
- /// </summary>
- public int heroPowerId;
- /// <summary>
- /// 星级
- /// </summary>
- public int heroPromoteId;
- }
- }
|