private void Update() { if (NetworkManager.net != null) { currentState = NetworkManager.net.State; GetComponentInChildren <TMPro.TextMeshPro>().text = currentState.ToString(); } }
protected void Update() { ExitGames.Client.Photon.LoadBalancing.LoadBalancingPeer voicePeer = PhotonVoiceNetwork.Client.loadBalancingPeer; if (voicePeer == null) { UnityEngine.Debug.LogError("[PUNVoice]: LoadBalancingPeer broke!"); return; } ExitGames.Client.Photon.LoadBalancing.ClientState clientState = PhotonVoiceNetwork.Client.State; bool connected = true; switch (clientState) { case ExitGames.Client.Photon.LoadBalancing.ClientState.PeerCreated: case ExitGames.Client.Photon.LoadBalancing.ClientState.Disconnected: case ExitGames.Client.Photon.LoadBalancing.ClientState.Disconnecting: case ExitGames.Client.Photon.LoadBalancing.ClientState.ConnectedToNameServer: connected = false; break; } if (!connected) { return; } bool doDispatch = true; while (PhotonNetwork.isMessageQueueRunning && doDispatch) { // DispatchIncomingCommands() returns true of it found any command to dispatch (event, result or state change) Profiler.BeginSample("[PUNVoice]: DispatchIncomingCommands"); doDispatch = voicePeer.DispatchIncomingCommands(); Profiler.EndSample(); } int currentMsSinceStart = (int)(Time.realtimeSinceStartup * 1000); // avoiding Environment.TickCount, which could be negative on long-running platforms if (currentMsSinceStart > nextSendTickCount) { bool doSend = true; while (PhotonNetwork.isMessageQueueRunning && doSend) { // Send all outgoing commands Profiler.BeginSample("[PUNVoice]: SendOutgoingCommands"); doSend = voicePeer.SendOutgoingCommands(); Profiler.EndSample(); } nextSendTickCount = currentMsSinceStart + updateInterval; } }
/// <summary>A thread which runs independent from the Update() calls. Keeps connections online while loading or in background. See PhotonVoiceNetwork.BackgroundTimeout.</summary> private static bool FallbackSendAckThread() { if (sendThreadShouldRun && PhotonVoiceNetwork.Client != null && PhotonVoiceNetwork.Client.loadBalancingPeer != null) { ExitGames.Client.Photon.LoadBalancing.LoadBalancingPeer voicePeer = PhotonVoiceNetwork.Client.loadBalancingPeer; ExitGames.Client.Photon.LoadBalancing.ClientState clientState = PhotonVoiceNetwork.Client.State; // check if the client should disconnect after some seconds in background if (timerToStopConnectionInBackground != null && PhotonVoiceNetwork.BackgroundTimeout > 0.1f) { if (timerToStopConnectionInBackground.ElapsedMilliseconds > PhotonVoiceNetwork.BackgroundTimeout * 1000) { bool connected = true; switch (clientState) { case ExitGames.Client.Photon.LoadBalancing.ClientState.PeerCreated: case ExitGames.Client.Photon.LoadBalancing.ClientState.Disconnected: case ExitGames.Client.Photon.LoadBalancing.ClientState.Disconnecting: case ExitGames.Client.Photon.LoadBalancing.ClientState.ConnectedToNameServer: connected = false; break; } if (connected) { PhotonVoiceNetwork.Disconnect(); } timerToStopConnectionInBackground.Stop(); timerToStopConnectionInBackground.Reset(); return(sendThreadShouldRun); } } if (voicePeer.ConnectionTime - voicePeer.LastSendOutgoingTime > 200) { voicePeer.SendAcksOnly(); } } return(sendThreadShouldRun); }