text
stringlengths
0
1.11k
The PhotonNetworkMessenger class is defined in /Assets/Discover/Scripts/Colocation/PhotonNetworkMessenger.cs. It contains the FindRPCToCallServerRPC member function, which relates to the host player (also called the server here).
[Rpc(RpcSources.All, RpcTargets.StateAuthority)]
private void FindRPCToCallServerRPC(byte eventCode, int playerId, ulong oculusIdAnchorOwner,
ulong oculusIdAnchorRequester, Guid headsetIdRequester, string uuid,
NetworkBool anchorFlowSucceeded, RpcInfo info = default)
{
Debug.Log("FindRPCToCallServerRPC");
PlayerRef playerRef = playerId;
FindRPCToCallClientRPC(playerRef, eventCode, oculusIdAnchorOwner, oculusIdAnchorRequester, headsetIdRequester, uuid, anchorFlowSucceeded);
}
[Rpc(RpcSources.All, RpcTargets.StateAuthority)]
private void FindRPCToCallServerRPC(byte eventCode, int playerId)
{
Debug.Log("FindRPCToCallServerRPC: Null");
PlayerRef playerRef = playerId;
FindRPCToCallClientRPC(playerRef, eventCode);
}
There is also the corresponding FindRPCToCallClientRPC function for client players:
[Rpc(RpcSources.All, RpcTargets.All)]
private void FindRPCToCallClientRPC(
[RpcTarget] PlayerRef player,
byte eventCode,
ulong oculusIdAnchorOwner, ulong oculusIdAnchorRequester, Guid headsetIdRequester,
string uuid, NetworkBool anchorFlowSucceeded)
{
Debug.Log("FindRPCToCallClientRPC");
var data = new ShareAndLocalizeParams(oculusIdAnchorOwner, oculusIdAnchorRequester, headsetIdRequester, uuid)
{
anchorFlowSucceeded = anchorFlowSucceeded
};
m_callbackDictionary[eventCode](data);
}
[Rpc(RpcSources.All, RpcTargets.All)]
private void FindRPCToCallClientRPC(
[RpcTarget] PlayerRef player,
byte eventCode
)
{
Debug.Log("FindRPCToCallClientRPC: null");
m_callbackDictionary[eventCode](null);
}
Depending on the messages, these are all Photon Fusion attributes to RPCs.
Server and client messages
The INetworkMessenger interface invokes the SendMessageUsingOculusId function. This is a member function of the PhotonNetworkMessenger class, as defined in /Assets/Discover/Scripts/Colocation/PhotonNetworkMessenger.cs. It uses a dictionary and implements the PhotonPlayerIDDictionary player ID dictionary class.
When using the SendMessageUsingOculusId function, the following translates the association between the Oculus ID and the Photon Fusion ID:
var networkId = (int)m_idDictionary.GetNetworkId(oculusId);
By using this, Discover sends any referenced RPC by this message data object (called messageData):
if (messageData != null)
{
var data = (ShareAndLocalizeParams)messageData;
FindRPCToCallServerRPC(eventCode, networkId, data.oculusIdAnchorOwner, data.oculusIdAnchorRequester, data.headsetIdAnchorRequester, data.uuid.ToString(), data.anchorFlowSucceeded);
}
This forwards all networking information through the network.
ColocationDriverNetObj initialization walkthrough
Focusing back on theColocationDriverNetObj class discussed above, here is a more in-depth look of the process followed in the class.
It sets up the following objects:
m_ovrCameraRigTransform
m_oculusUser
m_headsetGuid
It adds the current Oculus user ID to the dictionary:
AddToIdDictionary(m_oculusUser?.ID ?? default, Runner.LocalPlayer.PlayerId, m_headsetGuid);
This is run either by the client or the host. This gets the Oculus user ID and associates it with the local player ID, as well as with a headset Guid, which is also used for referencing the Oculus player.
It initializes the Messenger class with:
messenger.Init(PlayerIDDictionary);
It then starts the colocation flow.
It creates an alignment anchor manager called m_alignmentAnchorManager with the following:
```
m_alignmentAnchorManager = Instantiate(m_alignmentAnchorManagerPrefab).GetComponent<AlignmentAnchorManager>();
``` 2. It then creates a colocation launcher as follows:
```
m_colocationLauncher = new ColocationLauncher();
``` 3. This is initialized with this invocation with the `Init` function of the `ColocationLauncher` class from the Colocation package:
```
m_colocationLauncher.Init(
m_oculusUser?.ID ?? default,