Controls
Overview
The ControlsSystem
provides a mechanism for entities to control another entity and forwarding input to the controlled entity's controller.
Setup
The first step is to create an entity which can be controlled by others. For this the controllable entity's controller has to implement the IControllableObjectController
interface.
C#
public interface IControllableObjectController
{
bool CanControl(Frame frame, EntityRef entity, EntityRef controllingEntity);
void OnControlStarted(Frame frame, EntityRef entity, EntityRef controllingEntity);
void OnControlStopped(Frame frame, EntityRef entity, EntityRef controllingEntity);
}
The entity that has the ability to control another one has to:
- have the
Controls
component; and, - have a controller implementing
IControllingObjectController
interface.
C#
public interface IControllingObjectController
{
bool CanControl(Frame frame, EntityRef entity, EntityRef controllableEntity);
void OnControlStarted(Frame frame, EntityRef entity, EntityRef controllableEntity);
void OnControlStopped(Frame frame, EntityRef entity, EntityRef controllableEntity);
}
If an entity controller implements IControllingObjectController
, the entity with that controller can start and stop the control of others. A human agent would initiate and cancel control by sending StartControlCommand()
and StopControlCommand()
respectively while an AI agent would do this via the InputDesires
properties or directly through ControlsDesires
. When the control is started or stopped, both the controlling and controllable entities will be receiving a call to OnControlStarted()
and OnControlStopped()
respectively.
Note: The CanControl()
method found in each interface allow an entity to decide whether the other is valid; i.e. can this entity take control of or be controlled by the other entity.
Example
The FPS Template provides an example of this interaction by implementing:
IControllableObjectController
in theTurretController
; and,IControllingObjectController
in theAgentController
.
On the Unity side, these controllers are used by the Turret and Agent prototypes respectively.
Back to top