45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Encompass
|
|
{
|
|
public struct Entity
|
|
{
|
|
public readonly Guid id;
|
|
|
|
private ComponentManager componentManager;
|
|
|
|
internal Entity(Guid id, ComponentManager componentManager)
|
|
{
|
|
this.id = id;
|
|
this.componentManager = componentManager;
|
|
}
|
|
|
|
public Guid AddComponent<TComponent>(TComponent component) where TComponent : struct, IComponent
|
|
{
|
|
return componentManager.AddComponent<TComponent>(id, component);
|
|
}
|
|
|
|
public IEnumerable<KeyValuePair<Guid, TComponent>> GetComponents<TComponent>() where TComponent : struct, IComponent
|
|
{
|
|
return componentManager.GetComponentsByEntityAndType<TComponent>(id);
|
|
}
|
|
|
|
public KeyValuePair<Guid, 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);
|
|
}
|
|
}
|
|
}
|