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.
public Brine2D.ECS.Entity AddBehavior<T>()
where T : Brine2D.ECS.Behavior;
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<PlayerMovementBehavior>()
.AddBehavior<PlayerShootingBehavior>();
Entity.AddBehavior\<T>(Action\<T>) Method¶
Creates, configures, and adds a behavior of the specified type.
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) but before OnAttached() is called, so configured values are available during attachment.