44 lines
1.2 KiB
C#
44 lines
1.2 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Encompass
|
|
{
|
|
public struct Entity
|
|
{
|
|
public readonly uint id;
|
|
|
|
private ComponentManager componentManager;
|
|
|
|
internal Entity(uint id, ComponentManager componentManager)
|
|
{
|
|
this.id = id;
|
|
this.componentManager = componentManager;
|
|
}
|
|
|
|
public void AddComponent<TComponent>(TComponent component) where TComponent : struct, IComponent
|
|
{
|
|
componentManager.AddComponent<TComponent>(id, component);
|
|
}
|
|
|
|
public IEnumerable<TComponent> GetComponents<TComponent>() where TComponent : struct, IComponent
|
|
{
|
|
return componentManager.GetComponentsByEntityAndType<TComponent>(id);
|
|
}
|
|
|
|
public TComponent GetComponent<TComponent>() where TComponent : struct, IComponent
|
|
{
|
|
return GetComponents<TComponent>().First();
|
|
}
|
|
|
|
public bool HasComponent<TComponent>() where TComponent : struct, IComponent
|
|
{
|
|
return componentManager.EntityHasComponentOfType<TComponent>(id);
|
|
}
|
|
|
|
internal void RemoveAllComponents()
|
|
{
|
|
componentManager.RemoveAllComponentsFromEntity(id);
|
|
}
|
|
}
|
|
}
|