INetworkingRemoteEventsService

Networking Service

Interface

This interface allows sending and receiving custom network messages.

Supported event argument types: byte, bool, short, int, long, float, double, string, Vector2, Vector3, Quaternion, Color, Color32, Vector4, DateTime

Methods

RaiseEvent(IReadOnlyCollection<int>, byte, params object[])

Raise a remote event to specific set of actors

RaiseEventAll(byte, params object[])

Raise a remote event to all actors connected to the current server. Note that this will also raise the event on the current actor, which triggers the onEvent callback.

RaiseEventOthers(byte, params object[])

Raise a remote event to all actors connected to the current server, except the current actor.

Events

onEvent

Event that triggers when a remote event is received

Examples

const byte EVENT_ID = 8;// A byte unique to this event

void OnEnable()
{
// Register listener for incoming network events
SpatialBridge.networkingService.remoteEvents.onEvent += HandleEvent;
}

void OnDisable()
{
SpatialBridge.networkingService.remoteEvents.onEvent -= HandleEvent;
}

void HandleEvent(NetworkingRemoteEventArgs args)
{
// Parse all incoming network events. Check for the correct ID
if (args.eventID == EVENT_ID)
{
// Display the message
SpatialBridge.coreGUIService.DisplayToastMessage((string)args.eventArgs[0]);
}
}

public void SendEventToAllPlayers()
{
// Send a network event to all players
SpatialBridge.networkingService.remoteEvents.RaiseEventAll(EVENT_ID, "Greetings!");
}
const byte EVENT_ID = 8;// A byte unique to this event

void OnEnable()
{
// Register listener for incoming network events
SpatialBridge.networkingService.remoteEvents.onEvent += HandleEvent;
}

void OnDisable()
{
SpatialBridge.networkingService.remoteEvents.onEvent -= HandleEvent;
}

void HandleEvent(NetworkingRemoteEventArgs args)
{
// Parse all incoming network events. Check for the correct ID
if (args.eventID == EVENT_ID)
{
// Display the message
SpatialBridge.coreGUIService.DisplayToastMessage((string)args.eventArgs[0]);
}
}

public void SendEventToAllPlayers()
{
// Send a network event to all players
SpatialBridge.networkingService.remoteEvents.RaiseEventAll(EVENT_ID, "Greetings!");
}