Interface IComponentsCollection
A collection of componenets: allows you to add, remove, get and iterate components.
Inherited Members
Namespace: AGS.API
Assembly: AGS.API.dll
Syntax
public interface IComponentsCollection : IEnumerable<IComponent>, IEnumerable, IDisposable
Properties
| Improve this Doc View SourceComponentsInitialized
Gets a value indicating whether the components were already initialized.
Declaration
bool ComponentsInitialized { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
|
Count
Gets the number of components.
Declaration
int Count { get; }
Property Value
Type | Description |
---|---|
System.Int32 | The count. |
OnComponentsChanged
An event which is triggered whenever a component is added/removed.
Declaration
IBlockingEvent<AGSListChangedEventArgs<IComponent>> OnComponentsChanged { get; }
Property Value
Type | Description |
---|---|
IBlockingEvent<AGSListChangedEventArgs<IComponent>> | The event. |
OnComponentsInitialized
An event that fires after all components were initialized.
Declaration
IBlockingEvent OnComponentsInitialized { get; }
Property Value
Type | Description |
---|---|
IBlockingEvent | The event. |
Methods
| Improve this Doc View SourceAddComponent(Type)
Adds a new component with the specified type.
Declaration
IComponent AddComponent(Type componentType)
Parameters
Type | Name | Description |
---|---|---|
System.Type | componentType | The component type. |
Returns
Type | Description |
---|---|
IComponent | The component, if added successfully, null otherwise (if a component with this type already exists). |
AddComponent<TComponent>()
Adds a new component with the specified type.
Declaration
TComponent AddComponent<TComponent>()
where TComponent : IComponent
Returns
Type | Description |
---|---|
TComponent | The component, if added successfully, null otherwise (if a component with this type already exists). |
Type Parameters
Name | Description |
---|---|
TComponent | The component type. |
AddComponent<TComponent>(IComponent)
Adds the specified component.
Declaration
bool AddComponent<TComponent>(IComponent component)
where TComponent : IComponent
Parameters
Type | Name | Description |
---|---|---|
IComponent | component | Component. |
Returns
Type | Description |
---|---|
System.Boolean |
|
Type Parameters
Name | Description |
---|---|
TComponent | The component type (with which it will be registered and can be queried by other components). |
Examples
The type parameter is used to specify under which type the component will be registed in the entity.
Suppose you want to replace an existing component in the entity, for example the rotation component.
By using IRotateComponent
as your type parameter, other components will get your component back when querying for IRotateComponent
.
Your component should implement IRotateComponent
.
public class MyRotateComponent : AGSComponent, IRotateComponent
{
...
}
var myRotate = new MyRotateComponent();
var existingRotate = obj.GetComponent<IRotateComponent>();
Console.WriteLine(myRotate == existingRotate); //Writes "false"
obj.RemoveComponent<IRotateComponent>();
obj.AddComponent<IRotateComponent>(myRotate);
existingRotate = obj.GetComponent<IRotateComponent>();
Console.WriteLine(myRotate == existingRotate); //Writes "true"
|
Improve this Doc
View Source
Bind<TComponent>(Action<TComponent>, Action<TComponent>)
Bind actions to when a component is added/removed.
Declaration
IComponentBinding Bind<TComponent>(Action<TComponent> onAdded, Action<TComponent> onRemoved)
where TComponent : IComponent
Parameters
Type | Name | Description |
---|---|---|
System.Action<TComponent> | onAdded | Callback to be called when component is added. |
System.Action<TComponent> | onRemoved | Callback to be called when component is removed. |
Returns
Type | Description |
---|---|
IComponentBinding | The binding. |
Type Parameters
Name | Description |
---|---|
TComponent | The 1st type parameter. |
GetComponent(Type)
Gets the component of the specified type.
Declaration
IComponent GetComponent(Type componentType)
Parameters
Type | Name | Description |
---|---|---|
System.Type | componentType |
Returns
Type | Description |
---|---|
IComponent | The component if found, null if no components of this type in the collection. |
GetComponent<TComponent>()
Gets the component of the specified type.
Declaration
TComponent GetComponent<TComponent>()
where TComponent : IComponent
Returns
Type | Description |
---|---|
TComponent | The component if found, null if no components of this type in the collection. |
Type Parameters
Name | Description |
---|---|
TComponent | The component type. |
HasComponent(IComponent)
Is the specified component in the collection?
Declaration
bool HasComponent(IComponent component)
Parameters
Type | Name | Description |
---|---|---|
IComponent | component |
Returns
Type | Description |
---|---|
System.Boolean |
|
HasComponent(Type)
Is there a component of the specified type in the collection?
Declaration
bool HasComponent(Type componentType)
Parameters
Type | Name | Description |
---|---|---|
System.Type | componentType |
Returns
Type | Description |
---|---|
System.Boolean |
|
HasComponent<TComponent>()
Is there a component of the specified type in the collection?
Declaration
bool HasComponent<TComponent>()
where TComponent : IComponent
Returns
Type | Description |
---|---|
System.Boolean |
|
Type Parameters
Name | Description |
---|---|
TComponent | The component type. |
OnDisposed(Action)
Subscribe to actions that will happen once the entity is disposed. If then entity was already disposed when calling this, the action will be executed immediately.
Declaration
void OnDisposed(Action onDisposed)
Parameters
Type | Name | Description |
---|---|---|
System.Action | onDisposed | The action to perform on entity disposal. |
PopComponent<TComponent>()
Removes the component with the specified type and returns it (if it exists).
Declaration
TComponent PopComponent<TComponent>()
where TComponent : IComponent
Returns
Type | Description |
---|---|
TComponent | The component if it was found and removed, |
Type Parameters
Name | Description |
---|---|
TComponent | The component type. |
RemoveComponent(IComponent)
Removes the specified component.
Declaration
bool RemoveComponent(IComponent component)
Parameters
Type | Name | Description |
---|---|---|
IComponent | component | Component. |
Returns
Type | Description |
---|---|
System.Boolean |
|
RemoveComponent(Type)
Removes the component with the specified type (if it exists).
Declaration
bool RemoveComponent(Type componentType)
Parameters
Type | Name | Description |
---|---|---|
System.Type | componentType | The component type. |
Returns
Type | Description |
---|---|
System.Boolean |
|
RemoveComponent<TComponent>()
Removes the component with the specified type (if it exists).
Declaration
bool RemoveComponent<TComponent>()
where TComponent : IComponent
Returns
Type | Description |
---|---|
System.Boolean |
|
Type Parameters
Name | Description |
---|---|
TComponent | The component type. |