(client) feat:添加基地界面到游玩界面的过程,添加存档管理,技能树变得可用 (#58)

Co-authored-by: m0_75251201 <m0_75251201@noreply.gitcode.com>
Reviewed-on: http://47.107.252.169:3000/Roguelite-Game-Developing-Team/Gen_Hack-and-Slash-Roguelite/pulls/58
This commit is contained in:
2025-10-03 00:31:34 +08:00
parent aff747be17
commit dd9d90439d
134 changed files with 10322 additions and 4872 deletions

View File

@@ -20,7 +20,7 @@ namespace Managers
/// <summary>
/// 用于标记在单例类中需要被SaveManager存储的属性。
/// </summary>
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
public class SavableAttribute : Attribute
{
/// <summary>
@@ -40,13 +40,17 @@ namespace Managers
private const string SaveFileName = "game_save.json";
// 存档路径
private static string SaveFilePath => Path.Combine(Application.persistentDataPath, SaveFileName);
private static string SaveFilePath => Path.Combine("Save", SaveFileName);
public string StepDescription => "加载存档中";
// 存储所有需要保存状态的单例实例
private readonly Dictionary<Type, ISavableSingleton> _savableSingletons = new();
~SaveManager()
{
SaveGame(); // 在销毁时保存游戏
}
/// <summary>
/// 注册一个需要保存状态的单例实例。
/// </summary>
@@ -86,33 +90,10 @@ namespace Managers
}
/// <summary>
/// 实现ILaunchManager接口的Clear方法清空存档数据
/// 实现ILaunchManager接口的Clear方法Clear是重载不做任何事
/// </summary>
public void Clear()
{
try
{
if (File.Exists(SaveFilePath))
{
File.Delete(SaveFilePath);
Debug.Log($"SaveManager: 存档文件 '{SaveFileName}' 已删除。");
}
}
catch (Exception ex)
{
Debug.LogError($"SaveManager: 清空存档数据失败: {ex.Message}");
}
// 清空所有注册单例的Savable属性设置为默认值
foreach (var singletonEntry in _savableSingletons)
{
var singletonType = singletonEntry.Key;
var singletonInstance = singletonEntry.Value;
foreach (var prop in GetSavableProperties(singletonType))
{
prop.SetValue(singletonInstance, GetDefaultValue(prop.PropertyType));
}
}
}
/// <summary>
@@ -144,6 +125,12 @@ namespace Managers
try
{
var directoryPath = Path.GetDirectoryName(SaveFilePath);
if (!string.IsNullOrEmpty(directoryPath) && !Directory.Exists(directoryPath))
{
Directory.CreateDirectory(directoryPath);
// DEBUG: Debug.Log($"SaveManager: 文件夹 '{directoryPath}' 已创建。");
}
var settings = new JsonSerializerSettings
{
Formatting = Formatting.Indented,