class MAGES::NetworkingModule¶
Overview¶
The networking module base class. More…
class NetworkingModule: public MAGES::HubModule { public: // classes class PlayerDescription; // properties bool AutomaticSceneSetup; Type NetworkIdType; IMAGESNetworkIntegration Integration; bool IsInitialized; bool IsHost; UnityEventOnUserConnected; UnityEvent OnUserDisconnected; UnityEvent OnUserOwnedGameObjectSpawned; UnityEvent OnConnectedToRoom; // methods bool EstablishConnectionToMainServer(string args); void DisconnectFromMainServer(); bool CreateRoom(string roomName); bool JoinRoom(string roomName = null); bool ExitCurrentRoom(); List GetAvailableRooms(); string GetCurrentConnectedRoom(); void OnDisconnected(string cause); void OnConnected(string info); bool OwnershipRequest(MAGESObject obj); int GetPrefabIDFromNetwork(GameObject prefab, out bool isUnique); bool LinkNetworkObject(GameObject networkPrefab, GameObject localPrefab); GameObject NetworkSpawn( GameObject prefab, Transform prefabParent = null, bool spawnedByHost = true ); void RemoteDestroyComponent(GameObject gameObject, string componentType); void RequestChangeState(byte changeState, string actionID); int GetConnectedUsersToRoom(string roomName); int GetConnectedUsersToCurrentRoom(); void AddSyncTransform(GameObject objectToBeSynchronized); void SyncMessage(GameObject netObject, string message); void AddMessageRemoteAction(GameObject netObject, UnityAction action); void RegisterActivatedObject(GameObject grabbableObject, bool isActivated); bool IsRemoteActivated(GameObject grabbableObject); bool HasAuthority(GameObject networkObject); int GetLocalPlayerID(); void NetworkButtonAction( GameObject networkObject, UnityAction action, int index ); void InvokeButtonRemoteCalls(GameObject networkObject, int index); void AddInteractableNetworkingEvents(GameObject interactable); IEnumerable<PlayerDescription> GetConnectedPlayers(); }; // direct descendants class MAGESNetworking; class StubNetworking;
Inherited Members¶
public: // properties int Version; // methods void Startup(); void Shutdown(); virtual void UpdateModule(UpdatePhase updatePhase);
Detailed Documentation¶
The networking module base class.
Properties¶
bool AutomaticSceneSetup
Gets or sets a value indicating whether all grabbable objects in the scene will automatically be configured for multiplayer. This will enforce the default configuration.
Type NetworkIdType
Gets or sets the class type of the networking id.
IMAGESNetworkIntegration Integration
Gets or sets the plugin that will handle the networking logic.
bool IsInitialized
Gets or sets a value indicating whether the networking module has been initialized.
Returns:
True after connection has been established with the server.
bool IsHost
Gets or sets a value indicating whether this user is host.
Returns:
True if user is host. False if user is not host or has not joined a room yet.
UnityEventOnUserConnected
Gets the event that is triggered when a user connects.
UnityEventOnUserDisconnected
Gets the event that is triggered when a user disconnects.
UnityEventOnUserOwnedGameObjectSpawned
Gets the event that is triggered when a user spawns a gameobject.
UnityEvent OnConnectedToRoom
Gets the event that is triggered when the local user connects to a room.
Methods¶
bool EstablishConnectionToMainServer(string args)
Establish connection to the main server.
Parameters:
args |
Connect arguments. Regions eu, us etc. |
Returns:
Return true if connection succeed.
void DisconnectFromMainServer()
Disconnect from main server. Does nothing if client is not already connected.
bool CreateRoom(string roomName)
Creates a room with the provided name.
Parameters:
roomName |
Room name. |
Returns:
True if room was created successfully.
bool JoinRoom(string roomName = null)
Attempts to join a room with the provided name.
Parameters:
roomName |
The room name to join. |
Returns:
True if room was created successfully.
bool ExitCurrentRoom()
Exits the current room.
Returns:
True if exited successfully.
ListGetAvailableRooms()
Find and return all available rooms.
Returns:
Return a list with all available rooms.
string GetCurrentConnectedRoom()
Return current connected room.
Returns:
Returns name of current room. Null if user is not connected to a room.
void OnDisconnected(string cause)
Called on disconnected.
Parameters:
cause |
Disconnect cause. |
void OnConnected(string info)
Called on connected to a room.
Parameters:
info |
Connection info. |
bool OwnershipRequest(MAGESObject obj)
Request ownership for a MAGESObject.
Parameters:
obj |
The obj to take ownership. |
Returns:
Returns true if request succeed.
int GetPrefabIDFromNetwork(GameObject prefab, out bool isUnique)
Gets the prefab id from an object that was spawned from the network.
Parameters:
prefab |
The object to be checked. |
isUnique |
Whether this object should be unique. |
Returns:
A positive integer in case the object is from network. Else, returns -1.
bool LinkNetworkObject(GameObject networkPrefab, GameObject localPrefab)
Links network object with the remote object.
Parameters:
networkPrefab |
The remote object will be linked with the local prefab. At the end it is destroyed. |
localPrefab |
The local object that will be marked as remote. |
Returns:
True if linking was successful. False otherwise.
GameObject NetworkSpawn( GameObject prefab, Transform prefabParent = null, bool spawnedByHost = true )
Spawns a gameobject over the network. Only required to be called from one user, preferably the host.
///
Parameters:
prefab |
Network object to be spawned. |
prefabParent |
The parent that will be spawned with. |
spawnedByHost |
If the object will be spawned by the host to all users. True by default. |
Returns:
The spawned object.
void RemoteDestroyComponent(GameObject gameObject, string componentType)
Destroys component in all other users.
Parameters:
gameObject |
The gameobject that has that component. |
componentType |
The type of component. |
void RequestChangeState(byte changeState, string actionID)
Request a change in scenegraph’s state.
Parameters:
changeState |
The change keycode that will be requested. |
actionID |
The ID of the action that will change. |
int GetConnectedUsersToRoom(string roomName)
Gets connected users to a specific room.
Parameters:
roomName |
The name ID of the room. |
Returns:
The number of the connected users. Returns -1 if the room does not exist.
int GetConnectedUsersToCurrentRoom()
Gets connected users to the current room.
Returns:
The number of the connected users in the current room. Returns -1 if not connected to a room.
void AddSyncTransform(GameObject objectToBeSynchronized)
Adds default sync transform to a gameobject.
Parameters:
objectToBeSynchronized |
The change keycode that will be requested. |
void SyncMessage(GameObject netObject, string message)
Call to sync a message among clients.
Parameters:
netObject |
The object that synces the message. |
message |
The message to be synced. |
void AddMessageRemoteAction(GameObject netObject, UnityActionaction)
Subscribe a unity action to message recieved event.
Parameters:
netObject |
The network object that holds the event. |
action |
An action to subscribe on message recieved event, invoke. |
void RegisterActivatedObject(GameObject grabbableObject, bool isActivated)
Register an object that was remotely activated.
Parameters:
grabbableObject |
Object that is remotely activated. |
isActivated |
If true the object is added, if false the object is removed. |
bool IsRemoteActivated(GameObject grabbableObject)
Returns true if object is remotely activated.
Parameters:
grabbableObject |
Object to check. |
Returns:
Returns true if object is activated from another user.
bool HasAuthority(GameObject networkObject)
Checks if local user has authority over a network object.
Parameters:
networkObject |
The network object that will be checked. |
Returns:
True if user has authority else false. If the user is not connected in a session.
int GetLocalPlayerID()
Gets the identifying number of the local player instance, while inside a networked session.
Returns:
The local player’s identifier.
void NetworkButtonAction( GameObject networkObject, UnityAction action, int index )
Adds to a specific button the apropriate network action.
Parameters:
networkObject |
The network object that holds the buttons list. |
action |
The action that will be attached to the button. |
index |
The index of the button in the list of buttons. |
void InvokeButtonRemoteCalls(GameObject networkObject, int index)
Invoke calls of a specific network button from the list attched to the object.
Parameters:
networkObject |
The network object that holds the buttons list. |
index |
The index of the button in the list of buttons. |
void AddInteractableNetworkingEvents(GameObject interactable)
Adds the networking events to an interactable object.
Parameters:
interactable |
The interactable. |
IEnumerable<PlayerDescription> GetConnectedPlayers()
Gets all of the connected players.
Returns:
A list of connected players.