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.

1 public class PlayerController : Bolt.EntityBehaviour<IPlayerState> {
2 
3 bool forward;
4 bool backward;
5 bool left;
6 bool right;
7 
8 public override void Initialized() {
9  MiniMap.instance.AddKnownPlayer(this.gameObject);
10 }
11 
12 public override void Attached() {
13  state.AddCallback("name", NameChanged);
14  state.AddCallback("team", TeamChanged);
15 }
16 
17  public override void ControlGained() {
18  GameCamera.instance.AddFollowTarget(this.transform);
19  MiniMap.instance.SetControlledPlayer(this.entity);
20  }
21 }
22 public override SimulateOwner() {
23  if(state.health < 100)
24  {
25  state.Modify().health += state.healthRegen * BoltNetwork.frameDeltaTime;
26  }
27 }
28 
29 public override void SimulateController() {
30  IPlayerCommandInput input = PlayerCommand.Create();
31 
32  PollKeys();
33 
34  input.forward = forward;
35  input.backward = backward;
36  input.left = left;
37  input.right = right;
38 
39  entity.QueueInput(input);
40 }
41 public override ExecuteCommand(Bolt.Command command, bool resetState) {
42  if(resetState) {
43  motor.SetState(cmd.Result.position);
44  }
45  else {
46  cmd.Result.position = motor.Move(cmd.Input.forward, cmd.Input.backward, command.Input.left, command.Input.right);
47 
48  if (cmd.IsFirstExecution) {
49  AnimatePlayer(cmd);
50  }
51  }
52 }