Entity.AddBehavior Method
Definition
Namespace: Brine2D.ECS
| Overloads | |
|---|---|
| AddBehavior<T>() | Adds a behavior to this entity with automatic dependency injection. |
| AddBehavior<T>\(Action<T>\) | Creates, configures, and adds a behavior of the specified type. |
Entity.AddBehavior\<T>() Method
Adds a behavior to this entity with automatic dependency injection.
Type parameters
T
The behavior type.
Returns
Entity
This entity for method chaining.
Exceptions
System.InvalidOperationException
Thrown if entity is not in a world.
Example
Entity.AddBehavior\<T>\(Action\<T\>\) Method
Creates, configures, and adds a behavior of the specified type.
C#
public Brine2D.ECS.Entity AddBehavior<T>(System.Action<T> configure)
where T : Brine2D.ECS.Behavior;
Type parameters
T
The behavior type.
Parameters
configure System.Action<T>
An action to configure the behavior before it is attached.
Returns
Entity
This entity for method chaining.
Exceptions
System.InvalidOperationException
Thrown if entity is not in a world.
Remarks
configure is invoked after the behavior is constructed \(via DI\) and after Entity has been set to this entity, but before OnAdded() is called, so both the owning entity and configured values are available during attachment.