Photon Bolt Engine API
Networking Middleware
Bolt.EntityBehaviour Class Reference

Base class for unity behaviours that want to access Bolt methods More...

Inheritance diagram for Bolt.EntityBehaviour:
Bolt.EntityBehaviour< TState > BoltInternal.EntityEventListenerBase< TState >

Detailed Description

Base class for unity behaviours that want to access Bolt methods

Example: Using Bolt.EntityBehaviour to write a simple PlayerController class. Attach to a valid bolt entity / prefab.

public class PlayerController : Bolt.EntityBehaviour<IPlayerState> {
bool forward;
bool backward;
bool left;
bool right;
public override void Initialized() {
MiniMap.instance.AddKnownPlayer(this.gameObject);
}
public override void Attached() {
state.AddCallback("name", NameChanged);
state.AddCallback("team", TeamChanged);
}
public override void ControlGained() {
GameCamera.instance.AddFollowTarget(this.transform);
MiniMap.instance.SetControlledPlayer(this.entity);
}
}
public override SimulateOwner() {
if(state.health < 100)
{
state.Modify().health += state.healthRegen * BoltNetwork.frameDeltaTime;
}
}
public override void SimulateController() {
IPlayerCommandInput input = PlayerCommand.Create();
PollKeys();
input.forward = forward;
input.backward = backward;
input.left = left;
input.right = right;
entity.QueueInput(input);
}
public override ExecuteCommand(Bolt.Command command, bool resetState) {
if(resetState) {
motor.SetState(cmd.Result.position);
}
else {
cmd.Result.position = motor.Move(cmd.Input.forward, cmd.Input.backward, command.Input.left, command.Input.right);
if (cmd.IsFirstExecution) {
AnimatePlayer(cmd);
}
}
}