using Arch.Core;
using GFramework.Core.Abstractions.ecs;
namespace GFramework.Core.ecs;
///
/// ECS世界实现,封装Arch的World实例
///
public sealed class EcsWorld : IEcsWorld
{
private bool _disposed;
///
/// 获取内部的Arch World实例
///
public World InternalWorld { get; } = World.Create();
///
/// 当前实体数量
///
public int EntityCount => InternalWorld.Size;
///
/// 创建一个新实体
///
public Entity CreateEntity(params ComponentType[] types)
{
return InternalWorld.Create(types);
}
///
/// 销毁指定实体
///
public void DestroyEntity(Entity entity)
{
InternalWorld.Destroy(entity);
}
///
/// 检查实体是否存活
///
public bool IsAlive(Entity entity)
{
return InternalWorld.IsAlive(entity);
}
///
/// 清空所有实体
///
public void Clear()
{
InternalWorld.Clear();
}
///
/// 释放资源
///
public void Dispose()
{
if (_disposed) return;
World.Destroy(InternalWorld);
_disposed = true;
}
}