AccountFileInfo.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using Fort23.UTool;
  5. using UnityEngine;
  6. using Utility;
  7. public class AccountFileInfo : Singleton<AccountFileInfo>
  8. {
  9. private string persistentDataPath = Application.persistentDataPath + "/playerData.txt";
  10. public PlayerData playerData = new PlayerData();
  11. [System.Serializable]
  12. public class PlayerData
  13. {
  14. /// <summary>
  15. /// 主力英雄数据(主力等级(=afk2的共鸣等级))
  16. /// </summary>
  17. public List<HeroData> HeroListInLeadDatas = new List<HeroData>();
  18. /// <summary>
  19. /// 后备英雄(共享等级)
  20. /// </summary>
  21. public List<HeroData> HeroListInBackDatas = new List<HeroData>();
  22. }
  23. public void LoadPlayerData()
  24. {
  25. // #if UNITY_EDITOR || UNITY_STANDALONE_WIN
  26. // persistentDataPath = Application.streamingAssetsPath + $"/{playerId}playerSetting.txt";
  27. // #elif UNITY_ANDROID
  28. // playerSettingPath = Application.persistentDataPath+$"/{playerId}playerSetting.txt";
  29. // #elif UNITY_IPHONE
  30. // playerSettingPath = Application.persistentDataPath+$"/{playerId}playerSetting.txt";
  31. // #endif
  32. if (!File.Exists(persistentDataPath))
  33. {
  34. LogTool.Log("没有文件: " + persistentDataPath);
  35. ClearInitPlayerData();
  36. // File.Create(persistentDataPath).Close();
  37. }
  38. LogTool.Log("读取=文件: " + persistentDataPath);
  39. StreamReader sr = File.OpenText(persistentDataPath);
  40. string data = sr.ReadToEnd();
  41. sr.Close();
  42. playerData = new PlayerData();
  43. JsonUtility.FromJsonOverwrite(data, playerData);
  44. }
  45. public void SavePlayerData()
  46. {
  47. if (!string.IsNullOrEmpty(persistentDataPath))
  48. {
  49. string playerSettingJson = JsonManager.ToJson(playerData);
  50. File.WriteAllText(persistentDataPath, playerSettingJson);
  51. }
  52. }
  53. /// <summary>
  54. /// 不要服务器的话,这里初始化玩家的起始数据
  55. /// </summary>
  56. public void ClearInitPlayerData()
  57. {
  58. HeroData heroData1 = new HeroData
  59. {
  60. heroModelId = 105,
  61. heroPowerId = 1,
  62. heroPromoteId = 3
  63. };
  64. HeroData heroData2 = new HeroData
  65. {
  66. heroModelId = 107,
  67. heroPowerId = 1,
  68. heroPromoteId = 3
  69. };
  70. HeroData heroData3 = new HeroData
  71. {
  72. heroModelId = 116,
  73. heroPowerId = 1,
  74. heroPromoteId = 3
  75. };
  76. playerData.HeroListInLeadDatas.Add(heroData1);
  77. playerData.HeroListInLeadDatas.Add(heroData2);
  78. playerData.HeroListInLeadDatas.Add(heroData3);
  79. SavePlayerData();
  80. }
  81. [System.Serializable]
  82. public class HeroData
  83. {
  84. /// <summary>
  85. /// 英雄基础信息
  86. /// </summary>
  87. public int heroModelId;
  88. /// <summary>
  89. /// 英雄等级
  90. /// </summary>
  91. public int heroPowerId;
  92. /// <summary>
  93. /// 星级
  94. /// </summary>
  95. public int heroPromoteId;
  96. }
  97. }