Skip to content

Instantly share code, notes, and snippets.

@ZachMassia
Created February 7, 2014 04:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZachMassia/8857374 to your computer and use it in GitHub Desktop.
Save ZachMassia/8857374 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
namespace ECS
{
public sealed class Entity
{
// A unique ID representing the Entity. Will not be reused if
// the entity is deleted.
public long UniqueID { get; internal set; }
// The entity's components mapped to their type.
private Dictionary<Type, IComponent> components;
internal Entity(int id)
{
UniqueID = id;
}
public T GetComponent<T>() where T:IComponent
{
if (components.ContainsKey(typeof(T)))
{
return (T)components[typeof(T)];
}
return default(T);
}
public void AddComponent<T>(T component) where T:IComponent
{
if (!components.ContainsKey(typeof(T)))
{
components[typeof(T)] = component;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment