mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-23 03:04:29 +08:00
- 将Init方法统一重命名为Initialize方法以提高一致性 - 修改Architecture类中的组件注册逻辑,优化去重判断 - 更新ECS系统基础类以使用新的初始化接口 - 重构EcsWorld类使用属性自动实现而非私有字段 - 移除过时的EcsUsageExample示例文件 - 更新相关测试类以匹配新的初始化方法命名 - 改进代码注释和文档字符串格式
65 lines
1.3 KiB
C#
65 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 bool _disposed;
|
||
|
||
/// <summary>
|
||
/// 获取内部的Arch World实例
|
||
/// </summary>
|
||
public World InternalWorld { get; } = World.Create();
|
||
|
||
/// <summary>
|
||
/// 当前实体数量
|
||
/// </summary>
|
||
public int EntityCount => InternalWorld.Size;
|
||
|
||
/// <summary>
|
||
/// 创建一个新实体
|
||
/// </summary>
|
||
public Entity CreateEntity(params ComponentType[] types)
|
||
{
|
||
return InternalWorld.Create(types);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 销毁指定实体
|
||
/// </summary>
|
||
public void DestroyEntity(Entity entity)
|
||
{
|
||
InternalWorld.Destroy(entity);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 检查实体是否存活
|
||
/// </summary>
|
||
public bool IsAlive(Entity entity)
|
||
{
|
||
return InternalWorld.IsAlive(entity);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 清空所有实体
|
||
/// </summary>
|
||
public void Clear()
|
||
{
|
||
InternalWorld.Clear();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 释放资源
|
||
/// </summary>
|
||
public void Dispose()
|
||
{
|
||
if (_disposed) return;
|
||
|
||
World.Destroy(InternalWorld);
|
||
_disposed = true;
|
||
}
|
||
} |