GameData.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using SaveDataModel;
  5. using UnityEngine;
  6. public class GameData
  7. {
  8. public YieldInstruction Save(bool justSaveData = false)
  9. {
  10. if (!justSaveData)
  11. {
  12. if (LevelManager.SceneName == "ui_start")
  13. {
  14. Log.Error("在开始界面存档");
  15. return null;
  16. }
  17. this.PlayerPosition = ((!(R.Player.GameObject != null)) ? Vector3.zero : R.Player.Transform.position);
  18. this.SceneName = LevelManager.SceneName;
  19. this.SavePlayerAttribute(R.Player.Attribute);
  20. }
  21. return SaveManager.AutoSave(this);
  22. }
  23. public YieldInstruction Load()
  24. {
  25. if (SaveManager.IsAutoSaveDataExists)
  26. {
  27. return R.Coroutine.Start(this.LoadCoroutine());
  28. }
  29. return null;
  30. }
  31. private IEnumerator LoadCoroutine()
  32. {
  33. yield return SaveManager.AutoLoad();
  34. R.GameData = SaveManager.GameData;
  35. this.LoadPlayerAttribute(R.Player.Attribute, R.GameData.PlayerAttributeGameData);
  36. yield break;
  37. }
  38. public void Reset()
  39. {
  40. R.GameData = new GameData();
  41. this.LoadPlayerAttribute(R.Player.Attribute, R.GameData.PlayerAttributeGameData);
  42. }
  43. private void SavePlayerAttribute(PlayerAttribute attr)
  44. {
  45. this.PlayerAttributeGameData.faceDir = attr.faceDir;
  46. this.PlayerAttributeGameData.moveSpeed = attr.moveSpeed;
  47. this.PlayerAttributeGameData.maxHP = attr.maxHP;
  48. this.PlayerAttributeGameData.currentHP = attr.currentHP;
  49. this.PlayerAttributeGameData.CurrentEnergy = attr.currentEnergy;
  50. this.PlayerAttributeGameData.flashLevel = attr.flashLevel;
  51. }
  52. private void LoadPlayerAttribute(PlayerAttribute attr, PlayerAttributeGameData playerAttributeGameData)
  53. {
  54. attr.faceDir = playerAttributeGameData.faceDir;
  55. attr.moveSpeed = playerAttributeGameData.moveSpeed;
  56. attr.maxHP = playerAttributeGameData.maxHP;
  57. attr.currentHP = playerAttributeGameData.currentHP;
  58. attr.currentEnergy = playerAttributeGameData.CurrentEnergy;
  59. attr.flashLevel = playerAttributeGameData.flashLevel;
  60. attr.currentFlashTimes = attr.flashTimes;
  61. }
  62. public Vector3 PlayerPosition;
  63. public string RoleName = "ICEY";
  64. public string UserName = string.Empty;
  65. public string SceneName;
  66. public bool WindyVisiable = true;
  67. public int Difficulty;
  68. public readonly Dictionary<string, int> ThisSaveValidStorage = new Dictionary<string, int>();
  69. public readonly Dictionary<string, int> ThisRoundValidStorage = new Dictionary<string, int>();
  70. public readonly Dictionary<string, bool> BattleZoneDict = new Dictionary<string, bool>();
  71. public readonly PlayerAttributeGameData PlayerAttributeGameData = new PlayerAttributeGameData();
  72. public readonly Enhancement Enhancement = new Enhancement();
  73. public readonly Equipment Equipment = new Equipment();
  74. public readonly List<BloodPalaceTotalScore> BloodPalaceRecords = new List<BloodPalaceTotalScore>();
  75. }