Photon Bolt Engine API  1.2.10
Static Public Attributes | Properties | List of all members
BoltNetwork Class Reference

Holds global methods and properties for starting and stopping bolt, instantiating prefabs and other utils More...

Static Public Attributes

static bool IsRunning => BoltCore.IsRunning
 If bolt is running More...
 

Properties

static IEnumerable< BoltConnectionClients [get]
 All clients connected to this host More...
 
static IEnumerable< BoltConnectionConnections [get]
 All the connections connected to this host More...
 
static AsyncOperation CurrentAsyncOperation [get]
 Gets the current async operation. More...
 
static string CurrentVersion [get]
 Gets the current Bolt version as string. More...
 
static IEnumerable< BoltEntityEntities [get]
 The current server simulation frame number More...
 
static int Frame [get]
 The current local simulation frame number More...
 
static float FrameAlpha [get]
 Normalized value of how much time have passed since the last FixedUpdate More...
 
static float FrameBeginTime [get]
 The time the last fixed update begain, same as Time.fixedTime More...
 
static float FrameDeltaTime [get]
 The fixed frame delta, same as Time.fixedDeltaTime More...
 
static int FramesPerSecond [get]
 How many FixedUpdate frames per second bolt is configured to run More...
 
static GameObject GlobalObject [get]
 The global object that all global behaviours will be attached to More...
 
static bool IsClient [get]
 Returns true if this host is a client More...
 
static bool IsConnected [get]
 Returns true if this instance is a server or a client with at least one valid connection. More...
 
static bool IsDebugMode [get]
 Returns true if Bolt was compiled in debug mode More...
 
static bool IsServer [get]
 Returns true if this host is a server More...
 
static bool IsSinglePlayer [get]
 Returns true if this host is running in single player mode. More...
 
static int? MaxConnections [get]
 The max number of client connections to the server More...
 
static IEnumerable< BoltEntitySceneObjects [get]
 A list of all BoltEntities in the server simulation More...
 
static ScopeMode ScopeMode [get]
 The scoping mode active More...
 
static BoltConnection Server [get]
 The server connection More...
 
static int ServerFrame [get]
 On the server this returns the local frame, on a client this returns the currently estimated frame of all server objects we have received More...
 
static float ServerTime [get]
 The current server simulation time More...
 
static Map< Guid, UdpSessionSessionList [get]
 Gets the list of UdpSession received by the system. More...
 
static float Time [get]
 The local time, same as Time.time More...
 
static UdpSocket UdpSocket [get]
 Gets the current UDP socket. More...
 
static Version Version [get]
 The current Photon Bolt assembly version number. More...
 
static string??? VersionConfiguration [get]
 Gets the Bolt Version description. More...
 
static string??? VersionInfo [get]
 

Detailed Description

Holds global methods and properties for starting and stopping bolt, instantiating prefabs and other utils

Example: How to load a map on the server and instantiate a server controlled player.

void LoadMap(string mapName) {
BoltNetwork.LoadScene(mapName);
var serverPlayer = BoltNetwork.Instantiate(BoltPrefabs.Player) as GameObject;
Configure(serverPlayer);
}

Example: How to connect to a server with known IP and port number.

void ConnectToServer(string host, int port) {
UdpEndPoint serverAddr = UdpEndPoint(UdpIPv4Address.Parse(host), (ushort)port);
BoltNetwork.Connect(server);
}

Example: How to use the BoltNetwork frame property in an Update loop. Here we recalculate the player path 3 times per second.

void Update() {
if(BoltNetwork.frame % 20) == 0) {
playerMotor.Repath(targetPos);
}
}

Member Data Documentation

◆ IsRunning

bool BoltNetwork.IsRunning => BoltCore.IsRunning
static

If bolt is running

Example: How to use the isRunning property to detect a downtime and restart the server.

void Update() {
if(!BoltNetwork.isRunning &amp;&amp; BoltNetwork.time > lastRestart + 30f) {
RestartServer();
lastRestart = BoltNetwork.time;
}
}

Property Documentation

◆ Clients

IEnumerable<BoltConnection> BoltNetwork.Clients
staticget

All clients connected to this host

Example: Disconnecting all current clients.

void DisconnectAllClients() {
foreach(var client in BoltNetwork.clients) {
client.Disconnect();
}
}

◆ Connections

IEnumerable<BoltConnection> BoltNetwork.Connections
staticget

All the connections connected to this host

Example: Terminating all connections.

void DisconnectAll() {
foreach(var connection in BoltNetwork.connections) {
connection.Disconnect();
}
}

◆ CurrentAsyncOperation

AsyncOperation BoltNetwork.CurrentAsyncOperation
staticget

Gets the current async operation.

The current async operation.

◆ CurrentVersion

string BoltNetwork.CurrentVersion
staticget

Gets the current Bolt version as string.

◆ Entities

IEnumerable<BoltEntity> BoltNetwork.Entities
staticget

The current server simulation frame number

Example: A post-game method to destroy all minions/npcs in the server simulation.

void PostGameCleanup() {
foreach(var entity in BoltNetwork.entities) {
if(entity.IsOwner && entity.StateIs<MinionState>) {
BoltNetwork.Destroy(entity);
}
}
}

◆ Frame

int BoltNetwork.Frame
staticget

The current local simulation frame number

Example: Using the BoltNetwork frame in a loop to recalculate the player path once every 20 frames.

void FixedUpdate() {
if(BoltNetwork.frame % 20) == 0) {
playerMotor.Repath(targetPos);
}
}

◆ FrameAlpha

float BoltNetwork.FrameAlpha
staticget

Normalized value of how much time have passed since the last FixedUpdate

◆ FrameBeginTime

float BoltNetwork.FrameBeginTime
staticget

The time the last fixed update begain, same as Time.fixedTime

◆ FrameDeltaTime

float BoltNetwork.FrameDeltaTime
staticget

The fixed frame delta, same as Time.fixedDeltaTime

Example: How to use frameDeltaTime to translate a player's per-second health regeneration rate into a per-frame value.

protected override void SimulateOwner() {
float hpRegen = BoltNetwork.frameDeltaTime * state.HealthRegen;
state.Modify().HP = Mathf.Clamp(state.HP + hpRegen, 0, 100);
}

◆ FramesPerSecond

int BoltNetwork.FramesPerSecond
staticget

How many FixedUpdate frames per second bolt is configured to run

Example: Calculating the number of frames between footsteps from a time interval.

int FootstepFrameInterval(float stepTimeInterval) {
return Mathf.Round(stepTimeInterval / BoltNetwork.framesPerSecond);
}

◆ GlobalObject

GameObject BoltNetwork.GlobalObject
staticget

The global object that all global behaviours will be attached to

Example: The globalObject can be used as a root for attaching new scripts such as GlobalEventListener callbacks.

protected override void SceneLoadLocalDone(string map) {
if(map.Equals("GameScene")) {
BoltNetwork.globalObject.AddComponent<ClientGameCallbacks>();
}
}

◆ IsClient

bool BoltNetwork.IsClient
staticget

Returns true if this host is a client

Example: Implementing a client-side score sheet display to show the scores at the end of a game.

void GameOver(string winTeam) {
if(BoltNetwork.isClient) {
DisplayScoreSheet("Game Over", winTeam + " Team Wins!";
}
}

◆ IsConnected

bool BoltNetwork.IsConnected
staticget

Returns true if this instance is a server or a client with at least one valid connection.

Example: Using the isConnected property to do an automatic reconnect loop.

void Update() {
if(!BoltNetwork.connected && BoltNetwork.time - lastReconnectTime > 30f) {
BoltNetwork.Connect(serverAddr);
lastReconnectTime = BoltNetwork.time;
}
}

◆ IsDebugMode

bool BoltNetwork.IsDebugMode
staticget

Returns true if Bolt was compiled in debug mode

Example: Showing an FPS and ping counter when in debug mode.

public override void BoltStartDone() {
if(BoltNetwork.isDebugMode) {
PingView.instance.Show();
FPSCounter.instance.Show();
}
}

◆ IsServer

bool BoltNetwork.IsServer
staticget

Returns true if this host is a server

Example: Using the isServer property to implement server specific logic such as spawning NPCs after a new map has been generated.

public override void SceneLoadLocalDone(string map) {
GenerateMap();
if(BoltNetwork.isServer)
{
SpawnNPCs();
}
}

◆ IsSinglePlayer

bool BoltNetwork.IsSinglePlayer
staticget

Returns true if this host is running in single player mode.

true if is single player; otherwise, false.

◆ MaxConnections

int? BoltNetwork.MaxConnections
staticget

The max number of client connections to the server

Example: Using the max connections value to enforce server connection limits on an incoming client connection.

public override void ConnectRequest(UdpEndPoint clientAddr)
{
if(BoltNetwork.connections.Count == BoltNetwork.maxConnections)
{
BoltNetwork.Refuse(clientAddr);
return;
}
}

◆ SceneObjects

IEnumerable<BoltEntity> BoltNetwork.SceneObjects
staticget

A list of all BoltEntities in the server simulation

Example: Destroying all player entities using a foreach loop over BoltNetwork.SceneObjects and finding the players with StateIs().

void DestroyAllPlayers()
{
foreach(var entity in BoltNetwork.SceneObjects)
{
if(entity.StateIs<IPlayerState>())
{
BoltNetwork.Destroy(entity.gameObject);
}
}
}

◆ ScopeMode

ScopeMode BoltNetwork.ScopeMode
staticget

The scoping mode active

◆ Server

BoltConnection BoltNetwork.Server
staticget

The server connection

Example: Displaying the current server IP address and port to the client.

void ShowServerEndpoint() {
UdpEndPoint serverEndPoint = BoltNetwork.server.remoteEndPoint;
Message.Show("Current Server", string.Format("({0}:{1}", serverEndPoint.Address, serverEndPoint.Port);
}

◆ ServerFrame

int BoltNetwork.ServerFrame
staticget

On the server this returns the local frame, on a client this returns the currently estimated frame of all server objects we have received

Example: Predicting the next possible fire frame on the client using the estimated serverFrame.

void ClientFireWeapon(PlayerCommand cmd) {
if(weapon.nextFireFrame <= BoltNEtwork.serverFrame) {
state.Modify().FireTrigger();
weapon.nextFireFrame = BoltNetwork.serverFrame + weapon.refireRate;
}
}

◆ ServerTime

float BoltNetwork.ServerTime
staticget

The current server simulation time

Example: Using the serverTime property to display a message when the max game time has expired.

void Update() {
if((BoltNetwork.serverTime - gameStartTime >= MAX_GAME_TIME) {
Message.Show("Game Over", "Time Has Expired!");
}
}

◆ SessionList

Map<Guid, UdpSession> BoltNetwork.SessionList
staticget

Gets the list of UdpSession received by the system.

The session list.

◆ Time

float BoltNetwork.Time
staticget

The local time, same as Time.time

Example: Using the time property to periodically play footstep sounds on the client.

void Footsteps() {
if(BoltNetwork.time >= lastFootstep + footstepInterval) {
audio.PlayOneShot(footstepSound);
lastFootstep = BoltNetwork.time;
}
}

◆ UdpSocket

UdpSocket BoltNetwork.UdpSocket
staticget

Gets the current UDP socket.

The UDP socket.

◆ Version

Version BoltNetwork.Version
staticget

The current Photon Bolt assembly version number.

◆ VersionConfiguration

string??? BoltNetwork.VersionConfiguration
staticget

Gets the Bolt Version description.

The Bolt Version description.

◆ VersionInfo

string??? BoltNetwork.VersionInfo
staticget
BoltNetwork.SceneObjects
static IEnumerable< BoltEntity > SceneObjects
A list of all BoltEntities in the server simulation
Definition: BoltNetwork.cs:395
BoltNetwork
Holds global methods and properties for starting and stopping bolt, instantiating prefabs and other u...
Definition: BoltNetwork.cs:54