GFramework/GFramework.Core.Godot/architecture/ArchitectureAnchorNode.cs
GwWuYou eae45625a7 feat(godot): 集成Godot生命周期管理
- 新增ArchitectureAnchorNode类用于监听场景树销毁事件
- 在AbstractArchitecture中实现AttachToGodotLifecycle方法
- 自动绑定架构销毁逻辑到Godot节点退出时机
- 防止架构组件在热重载或多次初始化时重复挂载
- 完善系统注册与销毁流程,确保资源正确释放
2025-12-17 19:52:25 +08:00

33 lines
862 B
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Godot;
namespace GFramework.Core.Godot.architecture;
/// <summary>
/// 架构锚点节点类用于在Godot场景树中作为架构组件的根节点
/// 该类提供了退出时的回调绑定功能,可以在节点从场景树中移除时执行清理操作
/// </summary>
public partial class ArchitectureAnchorNode : Node
{
private Action? _onExit;
/// <summary>
/// 绑定节点退出时的回调动作
/// </summary>
/// <param name="onExit">当节点从场景树退出时要执行的动作</param>
public void Bind(Action onExit)
{
_onExit = onExit;
}
/// <summary>
/// 当节点从场景树中移除时调用此方法
/// 执行绑定的退出回调并清理引用
/// </summary>
public override void _ExitTree()
{
_onExit?.Invoke();
_onExit = null;
}
}