Networking

csharp
public static class Networking

Namespace NodeWorld.Flux.

The network of the room: the owners of objects and the master, synced transforms, objects spawned for the room, and the server's clock.

Properties

masterId

csharp
public static int masterId { get; }

The master of the room: the player in it for the longest time.

isMaster

csharp
public static bool isMaster { get; }

The local player is the master of the room (false on the server).

serverTimeMilliseconds

csharp
public static int serverTimeMilliseconds { get; }

The clock of the server, in ms (the same for every player, give or take the latency); wraps around like an int.

serverTime

csharp
public static double serverTime { get; }

The clock of the server, in seconds.

Methods

Instantiate

csharp
public static GameObject Instantiate(GameObject template, Vector3 position, Quaternion rotation)

Spawns a copy of template for the whole room, at position and rotation, and returns it at once. template is an object of the scene marked as a network template (the "Network template" box of its FL# Script component, in the editor): every player has it in the world. The server gives the copy a network id of its own in the room and tells every player, those who arrive later too, with its last synced state. Its scripts live as those of an object of the scene: Awake, Start, synced state, network events, ownership. The owner is the player who spawned it (the master for a copy spawned by a server script); when that player leaves, the copy stays and goes to the master. No limit on the count: only the 120 messages a second of each player slow a burst down.

Destroy

csharp
public static void Destroy(GameObject spawned)

Removes a spawned copy (Networking.Instantiate) for the whole room: its scripts get OnDestroy everywhere. The owner of the copy, the master or a server script may do it.

IsSpawned

csharp
public static bool IsSpawned(GameObject gameObject)

The object is a copy spawned by Networking.Instantiate (by any player or by the server).

IsOwner

csharp
public static bool IsOwner(GameObject gameObject)

The local player owns the network state of the object (it is the one that sends it).

GetOwner

csharp
public static int GetOwner(GameObject gameObject)

The owner of the object: the player that took it last, or the master when nobody did.

RequestOwnership

csharp
public static void RequestOwnership(GameObject gameObject)

The local player takes the ownership of the object: its scripts (OnOwnershipRequest here, then on the current owner) may refuse. IsOwner is true at once unless refused here; refused by the owner, it goes back.

SyncTransform

csharp
public static void SyncTransform(GameObject gameObject, float updatesPerSecond = 20f)

Synchronizes the transform of the object (it needs a network id in the scene): its owner sends it updatesPerSecond times a second, the other players follow it. 0 stops.

FlagDiscontinuity

csharp
public static void FlagDiscontinuity(GameObject gameObject)

The next synced transform of the object is a jump (teleport): the others place it at once.