Photon Bolt Engine API 1.3

Public Member Functions | Properties | List of all members
Photon.Bolt.EntityBehaviour Class Reference

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

Inheritance diagram for Photon.Bolt.EntityBehaviour:
Photon.Bolt.IEntityBehaviour Photon.Bolt.Internal.EntityEventListenerBase

Public Member Functions

virtual void Attached ()
 Invoked when Bolt is aware of this entity and all internal state has been setup More...
 
virtual void ControlGained ()
 Invoked when you gain control of this entity More...
 
virtual void ControlLost ()
 Invoked when you lost control of this entity More...
 
virtual void Detached ()
 Invoked when this entity is removed from Bolt's awareness More...
 
virtual void ExecuteCommand (Bolt.Command command, bool resetState)
 Invoked on both the owner and controller to execute a command More...
 
virtual void Initialized ()
 Invoked when the entity has been initialized, before Attached More...
 
virtual bool LocalAndRemoteResultEqual (Bolt.Command command)
 Utility callback used to signal to the user that this entity is about to be reset by a Command Result. Using this method, you are able to signal Bolt that the Result of the Command is equaled the current state of your entity, skipping all the recomputation needed when a Reset command arrives. More...
 
virtual void MissingCommand (Bolt.Command previous)
 Invoked on the owner when a remote connection is controlling this entity but we have not received any command for the current simulation frame. More...
 
virtual void SimulateController ()
 Invoked each simulation step on the controller More...
 
virtual void SimulateOwner ()
 Invoked each simulation step on the owner More...
 

Properties

BoltEntity entity [get, set]
 The entity for this behaviour More...
 

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(&quot;name&quot;, NameChanged);
state.AddCallback(&quot;team&quot;, TeamChanged);
}
public override void ControlGained() {
GameCamera.instance.AddFollowTarget(this.transform);
MiniMap.instance.SetControlledPlayer(this.entity);
}
public override SimulateOwner() {
if(state.health < 100)
{
state.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;
}
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);
}
}
}
}

Member Function Documentation

◆ Attached()

virtual void Photon.Bolt.EntityBehaviour.Attached ( )
inlinevirtual

Invoked when Bolt is aware of this entity and all internal state has been setup

Example: Overriding the Attached() method to add state change callbacks to the newly valid state.

public override void Attached() {
state.AddCallback("name", NameChanged);
state.AddCallback("team", TeamChanged);
}

◆ ControlGained()

virtual void Photon.Bolt.EntityBehaviour.ControlGained ( )
inlinevirtual

Invoked when you gain control of this entity

Example: Using the ControlGained() callback to set up a GameCamera and MiniMap to focus on this entity.

public override void ControlGained() {
GameCamera.instance.AddFollowTarget(this.transform);
MiniMap.instance.ControlGained(this.entity);
}

◆ ControlLost()

virtual void Photon.Bolt.EntityBehaviour.ControlLost ( )
inlinevirtual

Invoked when you lost control of this entity

Example: Using the ControlLost() callback to remove the focus of a GameCamera and MiniMap.

public override void ControlLost() {
GameCamera.instance.RemoveFollowTarget();
MiniMap.instance.ControlLost(this.entity);
}


◆ Detached()

virtual void Photon.Bolt.EntityBehaviour.Detached ( )
inlinevirtual

Invoked when this entity is removed from Bolt's awareness

Example: Notifying the game minimap to remove the entity upon detaching from the simulation.

public override void Detached() {
MiniMap.instance.RemoveKnownPlayer(this.entity);
{

◆ ExecuteCommand()

virtual void Photon.Bolt.EntityBehaviour.ExecuteCommand ( Bolt.Command  command,
bool  resetState 
)
inlinevirtual

Invoked on both the owner and controller to execute a command

Parameters
commandThe command to execute
resetStateIndicates if we should reset the state of the local motor or not

Example: Executing a simple WASD movement command. On the client this method can be called multiple times per fixed frame, beginning with a reset to the last confirmed state (resetState == true), and then again for each unverified input command in the queue (resetState == false);

Use the cmd.isFirstExecution property to do any type of one-shot behaviour such as playing sound or animations. This will prevent it from being called each time the input is replayed on the client.

Remember to create and compile a Command asset before using this method!

public override ExecuteCommand(Bolt.Command command, bool resetState) {
WASDCommand cmd = (WASDCommand)command;
if(resetState) {
motor.SetState(cmd.Result.position);
}
else {
cmd.Result.position = motor.Move(cmd.Input.forward, cmd.Input.backward, cmd.Input.left, cmd.Input.right);
if (cmd.IsFirstExecution) {
AnimatePlayer(cmd);
}
}
}

◆ Initialized()

virtual void Photon.Bolt.EntityBehaviour.Initialized ( )
inlinevirtual

Invoked when the entity has been initialized, before Attached

Example: Notifying a MiniMap class to draw this gameObject by overriding the Initialized() method.

public override void Initialized() {
MiniMap.instance.AddKnownPlayer(this.gameObject);
}

Reimplemented in Photon.Bolt.Internal.EntityEventListenerBase.

◆ LocalAndRemoteResultEqual()

virtual bool Photon.Bolt.EntityBehaviour.LocalAndRemoteResultEqual ( Bolt.Command  command)
inlinevirtual

Utility callback used to signal to the user that this entity is about to be reset by a Command Result. Using this method, you are able to signal Bolt that the Result of the Command is equaled the current state of your entity, skipping all the recomputation needed when a Reset command arrives.

Parameters
commandThe Command with ResetState flag as true for ExecuteCommand callback
Returns
True if you want to not recompute everything when local and remote Result match. False otherwise (default always recompute)

◆ MissingCommand()

virtual void Photon.Bolt.EntityBehaviour.MissingCommand ( Bolt.Command  previous)
inlinevirtual

Invoked on the owner when a remote connection is controlling this entity but we have not received any command for the current simulation frame.

Parameters
previousThe last valid command received

Example: Handling missing input commands by using the last received input command to continue moving in the same direction.

public override void MissingCommand(Bolt.Command previous)
{
WASDCommand cmd = (WASDCommand)command;
cmd.Result.position motor.Move(cmd.Input.forward, cmd.Input.backward, cmd.Input.left, cmd.Input.right);
}

◆ SimulateController()

virtual void Photon.Bolt.EntityBehaviour.SimulateController ( )
inlinevirtual

Invoked each simulation step on the controller

Example: Creating a simple WASD-style movement input command and adding it to the queue of inputs. One input command should be added to the queue per execution and remember to create and compile a Command asset before using this method!

bool forward;
bool backward;
bool left;
bool right;
public override void SimulateController() {
IPlayerCommandInput input = PlayerCommand.Create();
PollKeys();
input.forward = forward;
input.backward = backward;
input.left = left;
input.right = right;
}

◆ SimulateOwner()

virtual void Photon.Bolt.EntityBehaviour.SimulateOwner ( )
inlinevirtual

Invoked each simulation step on the owner

Example: Implementing an authoritative health regeneration update every 10th frame. Also fires the DeathTrigger() on the state if health falls below zero.

public override SimulateOwner() {
if(state.alive &amp;&amp; state.Health.Current <= 0) {
state.Health.alive = false;
state.DeathTrigger();
}
else if(state.alive &amp;&amp; (BoltNetwork.frame % 10) == 0)
{
state.Health.Current = Mathf.Clamp (state.Health.Current + (state.Health.RegenPer10 * BoltNetwork.frameDeltaTime),
// clamp from 0 to max health
0, state.Health.Max);
}
}

Property Documentation

◆ entity

BoltEntity Photon.Bolt.EntityBehaviour.entity
getset

The entity for this behaviour

Use the entity property to access the internal BoltEntity of the gameObject that this script is attached to.

Example: Passing the entity of this gameObject to a MiniMap, giving it the position, facing direction and the entity state (such as team, alive/dead, hostile, etc).

public class PlayerController : Bolt.EntityBehaviour {
public override void ControlGained() {
GameCamera.instance.AddFollowTarget(this.transform);
MiniMap.instance.SetControlledPlayer(this.entity);
}
}
Photon.Bolt.BoltEntity.QueueInput
bool QueueInput(INetworkCommandData data, bool force=false)
Queue an input data on this entity for execution. This is called on a client which is controlling a p...
Definition: BoltEntity.cs:852
Photon.Bolt.EntityBehaviour.MissingCommand
virtual void MissingCommand(Bolt.Command previous)
Invoked on the owner when a remote connection is controlling this entity but we have not received any...
Definition: EntityBehaviour.cs:272
Photon.Bolt.EntityBehaviour.entity
BoltEntity entity
The entity for this behaviour
Definition: EntityBehaviour.cs:93
Photon.Bolt.EntityBehaviour.Detached
virtual void Detached()
Invoked when this entity is removed from Bolt's awareness
Definition: EntityBehaviour.cs:171
Photon.Bolt.EntityBehaviour.ControlGained
virtual void ControlGained()
Invoked when you gain control of this entity
Definition: EntityBehaviour.cs:239
Photon.Bolt.EntityBehaviour.Attached
virtual void Attached()
Invoked when Bolt is aware of this entity and all internal state has been setup
Definition: EntityBehaviour.cs:157
Photon.Bolt.EntityBehaviour.SimulateOwner
virtual void SimulateOwner()
Invoked each simulation step on the owner
Definition: EntityBehaviour.cs:195
Photon.Bolt.EntityBehaviour.ControlLost
virtual void ControlLost()
Invoked when you lost control of this entity
Definition: EntityBehaviour.cs:254
Photon.Bolt.EntityBehaviour.Initialized
virtual void Initialized()
Invoked when the entity has been initialized, before Attached
Definition: EntityBehaviour.cs:142
Photon.Bolt.EntityBehaviour.SimulateController
virtual void SimulateController()
Invoked each simulation step on the controller
Definition: EntityBehaviour.cs:224
Photon.Bolt.EntityBehaviour.ExecuteCommand
virtual void ExecuteCommand(Bolt.Command command, bool resetState)
Invoked on both the owner and controller to execute a command
Definition: EntityBehaviour.cs:304