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