using System.Collections.Generic;
namespace Otter {
///
/// Base Component class. Components can be added to Entities.
///
public abstract class Component {
#region Public Fields
///
/// The parent Entity of the Component.
///
public Entity Entity;
///
/// Determines if the Component should render after the Entity has rendered.
///
public bool RenderAfterEntity = true;
///
/// Determines if the Component will render.
///
public bool Visible = true;
///
/// How long the Component has been alive (added to an Entity and updated.)
///
public float Timer = 0;
///
/// The Component's id for the Entity its attached to.
///
public int InstanceId { get; internal set; }
#endregion
#region Public Properties
///
/// The Scene that the parent Entity is in.
///
public Scene Scene {
get {
return Entity.Scene;
}
}
///
/// The first Collider of the parent Entity.
///
public Collider Collider {
get {
return Entity.Collider;
}
}
///
/// The first Graphic of the parent Entity.
///
public Graphic Graphic {
get {
return Entity.Graphic;
}
}
///
/// The list of Graphics from the parent Entity.
///
public List Graphics {
get {
return Entity.Graphics;
}
}
///
/// The list of Colliders from the parent Entity.
///
public List Colliders {
get {
return Entity.Colliders;
}
}
#endregion
#region Constructors
public Component() {
InstanceId = -1;
}
#endregion
#region Public Methods
///
/// Get the Entity as a specific Type.
///
/// The Type to get.
/// The Entity as Type T
public T GetEntity() where T : Entity {
return (T)Entity;
}
///
/// Called when the Component is added to the Entity.
///
public virtual void Added() {
}
///
/// Called when the Component is removed from the Entity.
///
public virtual void Removed() {
}
///
/// Removes the Component from its parent Entity.
///
public void RemoveSelf() {
if (Entity != null) {
Entity.RemoveComponent(this);
}
}
///
/// Called during the UpdateFirst on the parent Entity.
///
public virtual void UpdateFirst() {
}
///
/// Called during the Update on the parent Entity.
///
public virtual void Update() {
}
///
/// Called during the Render on the parent Entity.
///
public virtual void Render() {
}
///
/// Called during the UpdateLast on the parent Entity.
///
public virtual void UpdateLast() {
}
///
/// Gets the first Component of type T from this Component's Entity.
///
/// The type of the Component.
/// The first Component of type T from the Entity's Components.
public T GetComponent() where T : Component {
return Entity.GetComponent();
}
///
/// Gets a list of Components of type T from this Component's Entity.
///
/// The type of the Components.
/// A list of Components of type T from the Entity's Components.
public List GetComponents() where T : Component {
return Entity.GetComponents();
}
#endregion
}
}