This commit is contained in:
CortexCore
2024-04-16 04:15:21 +08:00
parent 337840ebb3
commit 3ffbaae6c8
26 changed files with 505 additions and 25 deletions

View File

@@ -28,6 +28,12 @@ public partial class Entity : Node,IEntity
/// 所有EntityComponent
/// </summary>
IEntityComponent[] IEntity.Components => Components.OfType<IEntityComponent>().ToArray();
public void WaitForInitializationComplete()
{
throw new NotImplementedException();
}
/// <summary>
/// IEntity.Id实现
/// </summary>

View File

@@ -48,6 +48,22 @@ public partial class GodotEntitiesService : Node,IEntitiesService
throw new NotImplementedException();
}
public bool TryGetEntity(ulong id, out IEntity entity)
{
return _entities.TryGetValue(id, out entity);
}
public IEntity GetOrAdd(ulong id, Func<ulong, IEntity> factory)
{
if (_entities.TryGetValue(id, out var entity))
{
return entity;
}
entity = factory(id);
Register(entity);
return entity;
}
public IEntity[] Query<T>()
{
return _entities.Values.Where(x => x.TryGetComponent<T>(out _)).ToArray();