/// <summary> /// Removes a <see cref="IComponent"/> from an <see cref="Entity"/>. /// </summary> /// <typeparam name="T">The type of component.</typeparam> /// <param name="entity">The entity.</param> public void RemoveComponent <T>(Entity entity) where T : IComponent { IComponentArray array = GetComponentArray <T>(false); array.Remove(entity); }
/// <summary> /// Adds a <see cref="IComponent"/> to a given <see cref="Entity"/>. /// </summary> /// <typeparam name="T">The type of component.</typeparam> /// <param name="entity">The entity.</param> /// <param name="component">The component.</param> public void AddComponent <T>(Entity entity, T component) where T : IComponent { Type componentType = typeof(T); IComponentArray array = GetComponentArray <T>(true); array.Add(entity, component); }
/// <summary> /// Reads and overwrites the current state of all component data from a binary source, basing incoming data on a previous component array's data. /// </summary> void IComponentArray.Deserialize(IComponentArray previousComponentArray, IReader reader) { this.Deserialize((ComponentArray <TComponent>)previousComponentArray, reader); }
/// <summary> /// Writes the state of all component data to a binary source, only writing data that has changed from a previous component array. /// </summary> void IComponentArray.Serialize(IComponentArray previousComponentArray, IWriter writer) { this.Serialize((ComponentArray <TComponent>)previousComponentArray, writer); }
/// <summary> /// Updates all component data to interpolated values between two other components. /// </summary> void IComponentArray.Interpolate(IComponentArray otherA, IComponentArray otherB, float amount) { this.Interpolate((ComponentArray <TComponent>)otherA, (ComponentArray <TComponent>)otherB, amount); }
/// <summary> /// Copies a single entity's component data to another entity's components in another component array. /// </summary> void IComponentArray.CopyEntityTo(int thisEntityID, IComponentArray otherComponentArray, int otherEntityID) { this.CopyEntityTo(thisEntityID, (ComponentArray <TComponent>)otherComponentArray, otherEntityID); }
/// <summary> /// Copies all component data to another component array. /// </summary> void IComponentArray.CopyTo(IComponentArray other) { this.CopyTo((ComponentArray <TComponent>)other); }
public void CopyFrom(IComponentArray source, int sourceIndex, int destIndex) { var sourceArray = (ComponentArray <T>)source; this[destIndex] = sourceArray[sourceIndex]; }
/// <summary> /// Checks to see if an <see cref="Entity"/> has a component. /// </summary> /// <typeparam name="T">The type of component.</typeparam> /// <param name="entity">The entity.</param> /// <returns>True if has component, otherwise false.</returns> public bool HasComponent <T>(Entity entity) where T : IComponent { IComponentArray array = GetComponentArray <T>(false); return(array.Contains(entity)); }
/// <summary> /// Gets a <see cref="IComponent"/> from an <see cref="Entity"/>. /// </summary> /// <typeparam name="T">The type of component.</typeparam> /// <param name="entity">The entity.</param> /// <returns>An <see cref="IComponent"/>.</returns> public T GetComponent <T>(Entity entity) where T : IComponent { IComponentArray array = GetComponentArray <T>(false); return((T)array.GetComponent(entity)); }