mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 10:34:30 +08:00
- 将Init方法统一重命名为Initialize方法以提高一致性 - 修改Architecture类中的组件注册逻辑,优化去重判断 - 更新ECS系统基础类以使用新的初始化接口 - 重构EcsWorld类使用属性自动实现而非私有字段 - 移除过时的EcsUsageExample示例文件 - 更新相关测试类以匹配新的初始化方法命名 - 改进代码注释和文档字符串格式
63 lines
1.5 KiB
C#
63 lines
1.5 KiB
C#
using Arch.Core;
|
||
using GFramework.Core.Abstractions.ecs;
|
||
using GFramework.Core.extensions;
|
||
using GFramework.Core.system;
|
||
|
||
namespace GFramework.Core.ecs;
|
||
|
||
/// <summary>
|
||
/// ECS系统基类,继承自AbstractSystem以集成到现有架构
|
||
/// </summary>
|
||
public abstract class EcsSystemBase : AbstractSystem, IEcsSystem
|
||
{
|
||
/// <summary>
|
||
/// ECS世界实例
|
||
/// </summary>
|
||
protected EcsWorld EcsWorld { get; private set; } = null!;
|
||
|
||
/// <summary>
|
||
/// 快捷访问内部World
|
||
/// </summary>
|
||
protected World World => EcsWorld.InternalWorld;
|
||
|
||
/// <summary>
|
||
/// 系统优先级,默认为0
|
||
/// </summary>
|
||
public virtual int Priority => 0;
|
||
|
||
/// <summary>
|
||
/// 每帧更新(子类实现)
|
||
/// </summary>
|
||
public abstract void Update(float deltaTime);
|
||
|
||
/// <summary>
|
||
/// 系统初始化
|
||
/// </summary>
|
||
protected override void OnInit()
|
||
{
|
||
EcsWorld = this.GetService<EcsWorld>() ?? throw new InvalidOperationException(
|
||
"EcsWorld not found in context. Make sure ECS is properly initialized.");
|
||
|
||
OnEcsInit();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 系统销毁
|
||
/// </summary>
|
||
protected override void OnDestroy()
|
||
{
|
||
OnEcsDestroy();
|
||
}
|
||
|
||
/// <summary>
|
||
/// ECS系统初始化(子类实现)
|
||
/// </summary>
|
||
protected abstract void OnEcsInit();
|
||
|
||
/// <summary>
|
||
/// ECS系统销毁(子类可选实现)
|
||
/// </summary>
|
||
protected virtual void OnEcsDestroy()
|
||
{
|
||
}
|
||
} |