This commit is contained in:
CortexCore
2024-06-25 13:47:32 +08:00
parent cda86975a0
commit 4b8586110e

View File

@@ -130,7 +130,7 @@ public class UnityEntitiesService : MonoBehaviour,IEntitiesService
public static event Action<IEntity> OnAdd; public static event Action<IEntity> OnAdd;
public static event Action<IEntity> OnRemove; public static event Action<IEntity> OnRemove;
IEntity[] IEntitiesService.Entities => Entities; IEntity[] IEntitiesService.Entities => Entities;
public static IEntity[] Entities => Dictionary.Values.ToArray(); public static IEntity[] Entities { get; private set; }
bool IEntitiesService.Register(IEntity entity) => Register(entity); bool IEntitiesService.Register(IEntity entity) => Register(entity);
bool IEntitiesService.UnRegister(IEntity entity) => UnRegister(entity); bool IEntitiesService.UnRegister(IEntity entity) => UnRegister(entity);
@@ -141,12 +141,14 @@ public class UnityEntitiesService : MonoBehaviour,IEntitiesService
if (Dictionary.TryRemove(entity.Id)) if (Dictionary.TryRemove(entity.Id))
{ {
OnRemove?.Invoke(entity); OnRemove?.Invoke(entity);
Entities = Dictionary.Values.ToArray();
} }
} }
while (RegisterQueue.TryDequeue(out var entity)) while (RegisterQueue.TryDequeue(out var entity))
{ {
Dictionary.GetOrAdd(entity.Id,entity); Dictionary.GetOrAdd(entity.Id,entity);
OnAdd?.Invoke(entity); OnAdd?.Invoke(entity);
Entities = Dictionary.Values.ToArray();
} }
} }