GFramework/GFramework.Core/ecs/EcsSystemRunner.cs
GeWuYou 3db89ab498 refactor(architecture): 重构架构初始化和销毁机制
- 将Init方法统一重命名为Initialize方法以提高一致性
- 修改Architecture类中的组件注册逻辑,优化去重判断
- 更新ECS系统基础类以使用新的初始化接口
- 重构EcsWorld类使用属性自动实现而非私有字段
- 移除过时的EcsUsageExample示例文件
- 更新相关测试类以匹配新的初始化方法命名
- 改进代码注释和文档字符串格式
2026-02-23 12:27:16 +08:00

67 lines
1.5 KiB
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 GFramework.Core.Abstractions.ecs;
using GFramework.Core.extensions;
using GFramework.Core.system;
namespace GFramework.Core.ecs;
/// <summary>
/// ECS系统调度器负责管理和更新所有ECS系统
/// </summary>
public sealed class EcsSystemRunner : AbstractSystem
{
private readonly List<IEcsSystem> _systems = new();
private bool _isRunning;
/// <summary>
/// 初始化调度器从DI容器获取所有ECS系统
/// </summary>
protected override void OnInit()
{
// 从容器获取所有已注册的ECS系统
var systemsList = this.GetService<IReadOnlyList<IEcsSystem>>();
if (systemsList is { Count: > 0 })
{
// 按优先级排序
_systems.AddRange(systemsList.OrderBy(s => s.Priority));
}
}
/// <summary>
/// 更新所有ECS系统
/// </summary>
/// <param name="deltaTime">帧间隔时间</param>
public void Update(float deltaTime)
{
if (!_isRunning) return;
foreach (var system in _systems)
{
system.Update(deltaTime);
}
}
/// <summary>
/// 启动调度器
/// </summary>
public void Start()
{
_isRunning = true;
}
/// <summary>
/// 停止调度器
/// </summary>
public void Stop()
{
_isRunning = false;
}
/// <summary>
/// 销毁调度器
/// </summary>
protected override void OnDestroy()
{
Stop();
_systems.Clear();
}
}