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

65 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.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;
}
}