mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 10:34:30 +08:00
- 在ArchitectureContext中添加ECS世界和系统调度器支持 - 添加IEcsWorld和IEcsSystem接口定义 - 实现EcsWorld、EcsSystemBase和EcsSystemRunner核心类 - 添加Position和Velocity示例组件及MovementSystem示例 - 创建ECS使用示例代码 - 将多个项目的TargetFramework从netstandard2.0升级到netstandard2.1 - 添加Arch和Arch.System包依赖到核心项目 - 在测试项目中添加ECS相关接口的模拟实现
66 lines
1.3 KiB
C#
66 lines
1.3 KiB
C#
using Arch.Core;
|
||
using GFramework.Core.Abstractions.ecs;
|
||
|
||
namespace GFramework.Core.ecs;
|
||
|
||
/// <summary>
|
||
/// ECS世界实现,封装Arch的World实例
|
||
/// </summary>
|
||
public sealed class EcsWorld : IEcsWorld
|
||
{
|
||
private readonly World _world = World.Create();
|
||
private bool _disposed;
|
||
|
||
/// <summary>
|
||
/// 获取内部的Arch World实例
|
||
/// </summary>
|
||
public World InternalWorld => _world;
|
||
|
||
/// <summary>
|
||
/// 当前实体数量
|
||
/// </summary>
|
||
public int EntityCount => _world.Size;
|
||
|
||
/// <summary>
|
||
/// 创建一个新实体
|
||
/// </summary>
|
||
public Entity CreateEntity(params ComponentType[] types)
|
||
{
|
||
return _world.Create(types);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 销毁指定实体
|
||
/// </summary>
|
||
public void DestroyEntity(Entity entity)
|
||
{
|
||
_world.Destroy(entity);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 检查实体是否存活
|
||
/// </summary>
|
||
public bool IsAlive(Entity entity)
|
||
{
|
||
return _world.IsAlive(entity);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 清空所有实体
|
||
/// </summary>
|
||
public void Clear()
|
||
{
|
||
_world.Clear();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 释放资源
|
||
/// </summary>
|
||
public void Dispose()
|
||
{
|
||
if (_disposed) return;
|
||
|
||
World.Destroy(_world);
|
||
_disposed = true;
|
||
}
|
||
} |