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

43 lines
1.3 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 Arch.Core;
using GFramework.Core.ecs.components;
namespace GFramework.Core.ecs.systems;
/// <summary>
/// 移动系统,负责更新具有位置和速度组件的实体的位置。
/// 根据速度和时间增量计算实体的新位置。
/// </summary>
public class MovementSystem : EcsSystemBase
{
private QueryDescription _query;
/// <summary>
/// 获取系统的优先级,数值越小优先级越高。
/// </summary>
public override int Priority => 0;
/// <summary>
/// ECS初始化回调方法在系统初始化时调用。
/// 创建查询描述符用于查找同时拥有Position和Velocity组件的实体。
/// </summary>
protected override void OnEcsInit()
{
// 创建查询查找所有同时拥有Position和Velocity组件的实体
_query = new QueryDescription()
.WithAll<Position, Velocity>();
}
/// <summary>
/// 系统更新方法,每帧调用一次。
/// </summary>
/// <param name="deltaTime">帧间隔时间,用于计算位置变化量</param>
public override void Update(float deltaTime)
{
// 查询并更新所有符合条件的实体
World.Query(in _query, (ref Position pos, ref Velocity vel) =>
{
pos.X += vel.X * deltaTime;
pos.Y += vel.Y * deltaTime;
});
}
}