/// <summary> /// Adds the specified component using the <see cref="EntityComponent.DefaultKey" />. /// </summary> /// <param name="component">The component.</param> /// <exception cref="System.ArgumentNullException">component</exception> public void Add(EntityComponent component) { if (component == null) { throw new ArgumentNullException("component"); } Components.SetObject(component.GetDefaultKey(), component); }
/// <summary> /// Gets or create a component with the specified key. /// </summary> /// <typeparam name="T">Type of the entity component</typeparam> /// <returns>A new or existing instance of {T}</returns> public T GetOrCreate <T>() where T : EntityComponent, new() { var key = EntityComponent.GetDefaultKey <T>(); var component = Components.Get(key); if (component == null) { component = new T(); Components.SetObject(key, component); } return((T)component); }
/// <summary> /// Gets a component by the specified key. /// </summary> /// <typeparam name="T">Type of the component</typeparam> /// <returns>The component or null if does no exist</returns> /// <exception cref="System.ArgumentNullException">key</exception> public T Get <T>() where T : EntityComponent, new() { return((T)Components.Get(EntityComponent.GetDefaultKey <T>())); }