Photon Bolt Engine API  1.2.7
Public Member Functions | List of all members
Bolt.GlobalEventListener Class Reference

Base class for all BoltCallbacks objects More...

Inheritance diagram for Bolt.GlobalEventListener:
BoltInternal.GlobalEventListenerBase

Public Member Functions

virtual void BoltShutdownBegin (Bolt.AddCallback registerDoneCallback)
 Callback triggered when the Bolt simulation is shutting down. More...
 
virtual void BoltShutdownBegin (Bolt.AddCallback registerDoneCallback, UdpConnectionDisconnectReason disconnectReason)
 Callback triggered when the Bolt simulation is shutting down. More...
 
virtual void BoltStartBegin ()
 Callback triggered before the Bolt simulation starts. More...
 
virtual void BoltStartDone ()
 Callback triggered after the Bolt simulation starts. More...
 
virtual void BoltStartFailed ()
 Callback triggered when Bolt was not able to initialize completely. More...
 
virtual void ConnectAttempt (UdpEndPoint endpoint, Bolt.IProtocolToken token)
 Callback triggered when trying to connect to a remote endpoint More...
 
virtual void Connected (BoltConnection connection)
 Callback triggered when a client has become connected to this instance More...
 
virtual void ConnectFailed (UdpEndPoint endpoint, Bolt.IProtocolToken token)
 Callback triggered when a connection to remote server has failed More...
 
virtual void ConnectRefused (UdpEndPoint endpoint, Bolt.IProtocolToken token)
 Callback triggered when the connection to a remote server has been refused. More...
 
virtual void ConnectRequest (UdpEndPoint endpoint, Bolt.IProtocolToken token)
 Callback triggered when this instance receives an incoming client connection More...
 
virtual void ControlOfEntityGained (BoltEntity entity)
 Callback triggered when this instance of bolt receieves control of a bolt entity More...
 
virtual void ControlOfEntityLost (BoltEntity entity)
 Callback triggered when this instance of Bolt loses control of a Bolt entity More...
 
virtual void Disconnected (BoltConnection connection)
 Callback triggered when disconnected from remote server More...
 
virtual void EntityAttached (BoltEntity entity)
 Callback triggered when a new entity is attached to the bolt simulation More...
 
virtual void EntityDetached (BoltEntity entity)
 Callback triggered when a new entity is detached from the bolt simulation More...
 
virtual void EntityFrozen (BoltEntity entity)
 Callback triggered when a bolt entity is frozen. More...
 
virtual void EntityReceived (BoltEntity entity)
 Callback triggered when a bolt entity is recieved from the network More...
 
virtual void EntityThawed (BoltEntity entity)
 Callback triggered when a bolt entity is thawed. More...
 
virtual bool PersistBetweenStartupAndShutdown ()
 Override this method and return true if you want the event listener to keep being attached to Bolt even when Bolt shuts down and starts again. More...
 
virtual void SceneLoadLocalBegin (string scene)
 Callback triggered before the new local scene is loaded. More...
 
virtual void SceneLoadLocalBegin (string scene, Bolt.IProtocolToken token)
 Callback triggered before the new local scene is loaded. More...
 
virtual void SceneLoadLocalDone (string scene)
 Callback triggered after the new local scene has been completely loaded. More...
 
virtual void SceneLoadLocalDone (string scene, Bolt.IProtocolToken token)
 Callback triggered after the new local scene has been completely loaded. More...
 
virtual void SceneLoadRemoteDone (BoltConnection connection)
 Callback triggered when a remote connection has completely loaded the current scene More...
 
virtual void SceneLoadRemoteDone (BoltConnection connection, Bolt.IProtocolToken token)
 Callback triggered when a remote connection has completely loaded the current scene More...
 
virtual void SessionConnectFailed (UdpSession session, Bolt.IProtocolToken token)
 Callback triggered when connecting to a session has failed. More...
 
virtual void SessionCreated (UdpSession session)
 Callback triggered when the requested session creation was successful. More...
 
virtual void SessionCreationFailed (UdpSession session)
 Callback triggered when the requested session creation has failed. More...
 
virtual void SessionListUpdated (Map< System.Guid, UdpSession > sessionList)
 Callback triggered when the session list is updated. More...
 
virtual void StreamDataReceived (BoltConnection connection, UdpStreamData data)
 Callback triggered when binary stream data is received. More...
 

Detailed Description

Base class for all BoltCallbacks objects

Example: Accepting an incoming remote connection.

public override void ConnectRequest(BoltConnection connection) {
BoltNetwork.Accept(connection.remoteEndPoint);
}

Member Function Documentation

◆ BoltShutdownBegin() [1/2]

virtual void BoltInternal.GlobalEventListenerBase.BoltShutdownBegin ( Bolt.AddCallback  registerDoneCallback)
inlinevirtualinherited

Callback triggered when the Bolt simulation is shutting down.

Example: Logging a message in the Bolt console when the server has shut down unexpectedly.

public override void BoltShutdown(Bolt.AddCallback registerDoneCallback) {
BoltLog.Warn("Bolt is shutting down");
registerDoneCallback(() =>
{
BoltLog.Warn("Bolt is down");
SceneManager.LoadScene(0);
});
}

◆ BoltShutdownBegin() [2/2]

virtual void BoltInternal.GlobalEventListenerBase.BoltShutdownBegin ( Bolt.AddCallback  registerDoneCallback,
UdpConnectionDisconnectReason  disconnectReason 
)
inlinevirtualinherited

Callback triggered when the Bolt simulation is shutting down.

Example: Logging a message in the Bolt console when the server has shut down unexpectedly.

public override void BoltShutdown(Bolt.AddCallback registerDoneCallback, UdpConnectionDisconnectReason disconnectReason = UdpConnectionDisconnectReason.Disconnected) {
BoltLog.Warn("Bolt is shutting down");
registerDoneCallback(() =>
{
BoltLog.Warn("Bolt is down");
SceneManager.LoadScene(0);
});
}

◆ BoltStartBegin()

virtual void BoltInternal.GlobalEventListenerBase.BoltStartBegin ( )
inlinevirtualinherited

Callback triggered before the Bolt simulation starts.

Example: Logging a message in the console when Bolt is starting.

public override void BoltStartBegin() {
BoltLog.Debug("Warning: Bolt is Starting...");
}

◆ BoltStartDone()

virtual void BoltInternal.GlobalEventListenerBase.BoltStartDone ( )
inlinevirtualinherited

Callback triggered after the Bolt simulation starts.

Example: Logging a message in the console when Bolt is already started.

public override void BoltStartDone() {
BoltLog.Debug("Warning: Bolt started...");
}

◆ BoltStartFailed()

virtual void BoltInternal.GlobalEventListenerBase.BoltStartFailed ( )
inlinevirtualinherited

Callback triggered when Bolt was not able to initialize completely.

Example: Logging a message in the console when Bolt failed to start.

public override void BoltStartFailed() {
BoltLog.Debug("Warning: Bolt failed to start.");
}

◆ ConnectAttempt()

virtual void BoltInternal.GlobalEventListenerBase.ConnectAttempt ( UdpEndPoint  endpoint,
Bolt.IProtocolToken  token 
)
inlinevirtualinherited

Callback triggered when trying to connect to a remote endpoint

Parameters
endpointThe remote server address
tokenToken passed by the client when trying to connect to a server.

Example: Logging a message when initializing a connection to server.

public override void ConnectAttempt((UdpEndPoint endpoint) {
BoltLog.Info(string.Format("To Remote Server At ({0}:{1})", endpoint.Address, endpoint.Port);
}

◆ Connected()

virtual void BoltInternal.GlobalEventListenerBase.Connected ( BoltConnection  connection)
inlinevirtualinherited

Callback triggered when a client has become connected to this instance

Parameters
connectionEndpoint of the connected client

Example: Instantiating and configuring a player entity when a client connects to the server.

public override void Connected(BoltConnection connection) {
BoltLog.Info("Accept Token {0} using Connect Token {1}", connection.AcceptToken, connection.ConnectToken);
var player = BoltNetwork.Instantiate(BoltPrefabs.Player);
player.transform.position = spawnPoint.transform.position;
var initData = prototype.GetNewPlayer(GameLogic.PlayableClass.Mercenary);
Configure(player, initData);
player.AssignControl(connection);
}

◆ ConnectFailed()

virtual void BoltInternal.GlobalEventListenerBase.ConnectFailed ( UdpEndPoint  endpoint,
Bolt.IProtocolToken  token 
)
inlinevirtualinherited

Callback triggered when a connection to remote server has failed

Parameters
endpointThe remote address
tokenConnect token sent by the client when trying to connect.

Example: Logging an error message when the remote connection has failed.

public override void ConnectFailed(UdpEndPoint endpoint, Bolt.IProtocolToken token) {
BoltLog.Info(string.Format("Connection To ({0}:{1}) has failed", endpoint.Address.ToString(), endpoint.ToString()));
}

◆ ConnectRefused()

virtual void BoltInternal.GlobalEventListenerBase.ConnectRefused ( UdpEndPoint  endpoint,
Bolt.IProtocolToken  token 
)
inlinevirtualinherited

Callback triggered when the connection to a remote server has been refused.

Parameters
endpointThe remote server endpoint
tokenData token sent by the refusing server

Example: Logging an error message when the remote connection has been refused using an error message token from the server.

public override void ConnectRefused(UdpEndPoint endpoint, Bolt.IProtocolToken token) {
ServerMessage.message = (ServerMessage)token;
BoltLog.Info(string.Format("Connection To ({0}:{1}) has been refused. Reason was {3}",
endpoint.Address.ToString(), endpoint.ToString(), serverMessage.errorDescription));
}

◆ ConnectRequest()

virtual void BoltInternal.GlobalEventListenerBase.ConnectRequest ( UdpEndPoint  endpoint,
Bolt.IProtocolToken  token 
)
inlinevirtualinherited

Callback triggered when this instance receives an incoming client connection

Parameters
endpointThe incoming client endpoint
tokenA data token sent from the incoming client

Example: Accepting an incoming connection with user credentials in the data token.

public override void ConnectRequest(UdpEndPoint endpoint, Bolt.IProtocolToken token) {
UserCredentials creds = (UserCredentials)token);
if(Authenticate(creds.username, creds.password)) {
BoltNetwork.Accept(connection.remoteEndPoint);
}
}

◆ ControlOfEntityGained()

virtual void BoltInternal.GlobalEventListenerBase.ControlOfEntityGained ( BoltEntity  entity)
inlinevirtualinherited

Callback triggered when this instance of bolt receieves control of a bolt entity

Parameters
entityThe controlled entity

Example: Setting up the game minimap and other components to use a specific entity as the player's controlled entity.

public override void ControlOfEntityGained(BoltEntity entity) {
GameInput.instance.SetControlledEntity(entity);
MiniMap.instance.SetControlledEntity(entity);
}

◆ ControlOfEntityLost()

virtual void BoltInternal.GlobalEventListenerBase.ControlOfEntityLost ( BoltEntity  entity)
inlinevirtualinherited

Callback triggered when this instance of Bolt loses control of a Bolt entity

Parameters
entityThe controlled entity

Example: Setting up game components to no longer control an entity.

public override void ControlOfEntityLost(BoltEntity entity) {
BoltLog.Info("Control lost with Token {0}", entity.controlLostToken);
GameInput.instance.RemoveControlledEntity(entity);
MiniMap.instance.RemoveControlledEntity(entity);
}

◆ Disconnected()

virtual void BoltInternal.GlobalEventListenerBase.Disconnected ( BoltConnection  connection)
inlinevirtualinherited

Callback triggered when disconnected from remote server

Parameters
connectionThe remote server endpoint

Example: Logging a disconnect message and returning to the main menu scene.

public override void Disconnected(BoltConnection connection) {
BoltLog.Info("Disconnected with Token {0}", connection.DisconnectToken);
BoltLog.Info("Returning to main menu...");
Application.LoadLevel("MainMenu");
}

◆ EntityAttached()

virtual void BoltInternal.GlobalEventListenerBase.EntityAttached ( BoltEntity  entity)
inlinevirtualinherited

Callback triggered when a new entity is attached to the bolt simulation

Parameters
entityThe attached entity

Example: Setting up the game minimap to show a newly attached entity.

public override void EntityAttached(BoltEntity entity) {
MiniMap.instance.SetKnownEntity(entity);
}

◆ EntityDetached()

virtual void BoltInternal.GlobalEventListenerBase.EntityDetached ( BoltEntity  entity)
inlinevirtualinherited

Callback triggered when a new entity is detached from the bolt simulation

Parameters
entityThe detached entity

Example: Removing the newly detached entity from the game minimap.

public override void EntityDetached(BoltEntity entity) {
MiniMap.instance.RemoveKnownEntity(entity);
}

◆ EntityFrozen()

virtual void BoltInternal.GlobalEventListenerBase.EntityFrozen ( BoltEntity  entity)
inlinevirtualinherited

Callback triggered when a bolt entity is frozen.

Parameters
entityThe recieved bolt entity

Example: Loggging connections from remote players in the client bolt console

public override void EntityFrozen(BoltEntity entity) {
string name = entity.GetState<PlayerState>().Name;
BoltLog.Info(string.Format("{0} Has been frozen", name));
}

◆ EntityReceived()

virtual void BoltInternal.GlobalEventListenerBase.EntityReceived ( BoltEntity  entity)
inlinevirtualinherited

Callback triggered when a bolt entity is recieved from the network

Parameters
entityThe recieved bolt entity

Example: Loggging connections from remote players in the client bolt console

public override void EntityReceived(BoltEntity entity) {
string name = entity.GetState<PlayerState>().Name;
BoltLog.Info(string.Format("{0} Has Connected", name));
}

◆ EntityThawed()

virtual void BoltInternal.GlobalEventListenerBase.EntityThawed ( BoltEntity  entity)
inlinevirtualinherited

Callback triggered when a bolt entity is thawed.

Parameters
entityThe recieved bolt entity

Example: Loggging connections from remote players in the client bolt console

public override void EntityThawed(BoltEntity entity) {
string name = entity.GetState<PlayerState>().Name;
BoltLog.Info(string.Format("{0} Has been thawed", name));
}

◆ PersistBetweenStartupAndShutdown()

virtual bool BoltInternal.GlobalEventListenerBase.PersistBetweenStartupAndShutdown ( )
inlinevirtualinherited

Override this method and return true if you want the event listener to keep being attached to Bolt even when Bolt shuts down and starts again.

Returns
True/False

Example: Configuring the persistence behaviour to keep this listener alive between startup and shutdown.

public override bool PersistBetweenStartupAndShutdown() {
return true;
}

◆ SceneLoadLocalBegin() [1/2]

virtual void BoltInternal.GlobalEventListenerBase.SceneLoadLocalBegin ( string  scene)
inlinevirtualinherited

Callback triggered before the new local scene is loaded.

Parameters
sceneName of scene being loaded

Example: Showing a splash screen when clients are loading the game scene.

public override void SceneLoadLocalBegin(string scene) {
if(BoltNetwork.isClient && scene.Equals("GameScene") {
SplashScreen.Show(SplashScreens.GameLoad);
}
}

◆ SceneLoadLocalBegin() [2/2]

virtual void BoltInternal.GlobalEventListenerBase.SceneLoadLocalBegin ( string  scene,
Bolt.IProtocolToken  token 
)
inlinevirtualinherited

Callback triggered before the new local scene is loaded.

Parameters
sceneName of scene being loaded
tokenToken passed by the Server when loading the new scene.

Example: Showing a splash screen when clients are loading the game scene.

public override void SceneLoadLocalBegin(string scene, Bolt.IProtocolToken token) {
if(BoltNetwork.isClient && map.Equals("GameScene") {
SplashScreen.Show(SplashScreens.GameLoad);
}
}

◆ SceneLoadLocalDone() [1/2]

virtual void BoltInternal.GlobalEventListenerBase.SceneLoadLocalDone ( string  scene)
inlinevirtualinherited

Callback triggered after the new local scene has been completely loaded.

Parameters
sceneName of scene that has loaded

Example: Hiding a splash screen that was shown during loading.

public override void SceneLoadLocalDone(string scene) {
if(BoltNetwork.isClient && scene.Equals("GameScene") {
SplashScreen.Hide();
}
}

◆ SceneLoadLocalDone() [2/2]

virtual void BoltInternal.GlobalEventListenerBase.SceneLoadLocalDone ( string  scene,
Bolt.IProtocolToken  token 
)
inlinevirtualinherited

Callback triggered after the new local scene has been completely loaded.

Parameters
sceneName of scene that has loaded
tokenToken passed by the Server when loading the new scene.

Example: Hiding a splash screen that was shown during loading.

public override void SceneLoadLocalDone(string scene, Bolt.IProtocolToken token) {
if(BoltNetwork.isClient && scene.Equals("GameScene") {
SplashScreen.Hide();
}
}

◆ SceneLoadRemoteDone() [1/2]

virtual void BoltInternal.GlobalEventListenerBase.SceneLoadRemoteDone ( BoltConnection  connection)
inlinevirtualinherited

Callback triggered when a remote connection has completely loaded the current scene

Parameters
connectionThe remote connection

Example: Instantiating and configuring a player entity on the server and then assigning control to the client.

public override void SceneLoadRemoteDone(BoltConnection connection) {
var player = BoltNetwork.Instantiate(BoltPrefabs.Player);
player.transform.position = spawnPoint.transform.position;
var initData = prototype.GetNewPlayer(GameLogic.PlayableClass.Mercenary);
Configure(player, initData);
player.AssignControl(connection);
}

◆ SceneLoadRemoteDone() [2/2]

virtual void BoltInternal.GlobalEventListenerBase.SceneLoadRemoteDone ( BoltConnection  connection,
Bolt.IProtocolToken  token 
)
inlinevirtualinherited

Callback triggered when a remote connection has completely loaded the current scene

Parameters
connectionThe remote connection
tokenToken passed by the Server when loading the new scene.

Example: Instantiating and configuring a player entity on the server and then assigning control to the client.

public override void SceneLoadRemoteDone(BoltConnection connection, Bolt.IProtocolToken token) {
var player = BoltNetwork.Instantiate(BoltPrefabs.Player);
player.transform.position = spawnPoint.transform.position;
var initData = prototype.GetNewPlayer(GameLogic.PlayableClass.Mercenary);
Configure(player, initData);
player.AssignControl(connection);
}

◆ SessionConnectFailed()

virtual void BoltInternal.GlobalEventListenerBase.SessionConnectFailed ( UdpSession  session,
Bolt.IProtocolToken  token 
)
inlinevirtualinherited

Callback triggered when connecting to a session has failed.

Parameters
sessionThe session the client was trying to connect to
tokenConnection token

Example: Loggging

public override void SessionConnectFailed(UdpSession session, IProtocolToken token)
{
BoltLog.Error("Failed to connect to session {0} with token {1}", session, token);
}

◆ SessionCreated()

virtual void BoltInternal.GlobalEventListenerBase.SessionCreated ( UdpSession  session)
inlinevirtualinherited

Callback triggered when the requested session creation was successful.

Parameters
sessionThe created session

Example: Loggging

public override void SessionCreated(UdpSession session)
{
BoltLog.Info("UdpSession {0} of type {1} was created", session.HostName, session.Source);
}

◆ SessionCreationFailed()

virtual void BoltInternal.GlobalEventListenerBase.SessionCreationFailed ( UdpSession  session)
inlinevirtualinherited

Callback triggered when the requested session creation has failed.

Parameters
sessionThe failed session

Example: Loggging

public override void SessionCreationFailed(UdpSession session)
{
BoltLog.Info("UdpSession {0} of type {1} has failed to create", session.HostName, session.Source);
}

◆ SessionListUpdated()

virtual void BoltInternal.GlobalEventListenerBase.SessionListUpdated ( Map< System.Guid, UdpSession >  sessionList)
inlinevirtualinherited

Callback triggered when the session list is updated.

Parameters
sessionListThe updated session list

Example: Loggging all sessions from the list.

public override void SessionListUpdated(Map<System.Guid, UdpSession> sessionList) {
BoltLog.Info("Session list updated: {0} total sessions", sessionList.Count);
foreach (var session in sessionList)
{
UdpSession udpSession = session.Value as UdpSession;
BoltLog.Info("UdpSession {0} Source: {1}", udpSession.HostName, udpSession.Source);
}
}

◆ StreamDataReceived()

virtual void BoltInternal.GlobalEventListenerBase.StreamDataReceived ( BoltConnection  connection,
UdpStreamData  data 
)
inlinevirtualinherited

Callback triggered when binary stream data is received.

Parameters
connectionThe sender connection
dataThe binary stream data

Example: Receiving a custom player icon.

public override void StreamDataReceived(BoltConnection connnection, UdpStreamData data) {
Texture2D icon = new Texture2D(4, 4);
icon.LoadImage(data.Data);
PlayerData playerData = (PlayerData)connection.userToken;
playerData.SetIcon(icon);
}