mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-23 03:04:29 +08:00
- 在ArchitectureContext中添加ECS世界和系统调度器支持 - 添加IEcsWorld和IEcsSystem接口定义 - 实现EcsWorld、EcsSystemBase和EcsSystemRunner核心类 - 添加Position和Velocity示例组件及MovementSystem示例 - 创建ECS使用示例代码 - 将多个项目的TargetFramework从netstandard2.0升级到netstandard2.1 - 添加Arch和Arch.System包依赖到核心项目 - 在测试项目中添加ECS相关接口的模拟实现
31 lines
814 B
C#
31 lines
814 B
C#
using Arch.Core;
|
||
using GFramework.Core.ecs.components;
|
||
|
||
namespace GFramework.Core.ecs.systems;
|
||
|
||
/// <summary>
|
||
/// 移动系统示例 - 根据速度更新位置
|
||
/// </summary>
|
||
public class MovementSystem : EcsSystemBase
|
||
{
|
||
private QueryDescription _query;
|
||
|
||
public override int Priority => 0;
|
||
|
||
protected override void OnEcsInit()
|
||
{
|
||
// 创建查询:查找所有同时拥有Position和Velocity组件的实体
|
||
_query = new QueryDescription()
|
||
.WithAll<Position, Velocity>();
|
||
}
|
||
|
||
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;
|
||
});
|
||
}
|
||
} |