protected internal void SetLevelInPropsIfSynced(object levelId)
{
if (!PhotonNetwork.automaticallySyncScene || !PhotonNetwork.isMasterClient || PhotonNetwork.room == null)
{
return;
}
if (levelId == null)
{
Debug.LogError("Parameter levelId can't be null!");
return;
}
// check if "current level" is already set in props
if (PhotonNetwork.room.customProperties.ContainsKey(NetworkingPeer.CurrentSceneProperty))
{
object levelIdInProps = PhotonNetwork.room.customProperties[NetworkingPeer.CurrentSceneProperty];
if (levelIdInProps is int && SceneManagerHelper.ActiveSceneBuildIndex == (int)levelIdInProps)
{
return;
}
if (levelIdInProps is string && SceneManagerHelper.ActiveSceneName != null && SceneManagerHelper.ActiveSceneName.Equals((string)levelIdInProps))
{
return;
}
}
// current level is not yet in props, so this client has to set it
Hashtable setScene = new Hashtable();
if (levelId is int) setScene[NetworkingPeer.CurrentSceneProperty] = (int)levelId;
else if (levelId is string) setScene[NetworkingPeer.CurrentSceneProperty] = (string)levelId;
else Debug.LogError("Parameter levelId must be int or string!");
PhotonNetwork.room.SetCustomProperties(setScene);
this.SendOutgoingCommands(); // send immediately! because: in most cases the client will begin to load and not send for a while
}