Created
February 7, 2014 04:29
-
-
Save ZachMassia/8857374 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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