예제 #1
0
    /// <summary>A thread which runs independent from the Update() calls. Keeps connections online while loading or in background. See PhotonNetwork.BackgroundTimeout.</summary>
    public static bool FallbackSendAckThread()
    {
        if (sendThreadShouldRun && !PhotonNetworkManager.offlineMode && PhotonNetworkManager.networkingPeer != null)
        {
            // check if the client should disconnect after some seconds in background
            if (timerToStopConnectionInBackground != null && PhotonNetworkManager.BackgroundTimeout > 0.1f)
            {
                if (timerToStopConnectionInBackground.ElapsedMilliseconds > PhotonNetworkManager.BackgroundTimeout * 1000)
                {
                    if (PhotonNetworkManager.connected)
                    {
                        PhotonNetworkManager.Disconnect();
                    }
                    timerToStopConnectionInBackground.Stop();
                    timerToStopConnectionInBackground.Reset();
                    return(sendThreadShouldRun);
                }
            }

            if (!PhotonNetworkManager.isMessageQueueRunning || PhotonNetworkManager.networkingPeer.ConnectionTime - PhotonNetworkManager.networkingPeer.LastSendOutgoingTime > 200)
            {
                PhotonNetworkManager.networkingPeer.SendAcksOnly();
            }
        }

        return(sendThreadShouldRun);
    }
    // called in editor, opens wizard for initial setup, keeps scene PhotonViews up to date and closes connections when compiling (to avoid issues)
    private static void EditorUpdate()
    {
        if (PhotonNetworkManager.PhotonServerSettings == null)
        {
            PhotonNetworkManager.CreateSettings();
        }
        if (PhotonNetworkManager.PhotonServerSettings == null)
        {
            return;
        }

        // serverSetting is null when the file gets deleted. otherwise, the wizard should only run once and only if hosting option is not (yet) set
        if (!PhotonNetworkManager.PhotonServerSettings.DisableAutoOpenWizard && PhotonNetworkManager.PhotonServerSettings.HostType == ServerSettings.HostingOption.NotSet)
        {
            ShowRegistrationWizard();
            PhotonNetworkManager.PhotonServerSettings.DisableAutoOpenWizard = true;
            PhotonEditor.SaveSettings();
        }

        // Workaround for TCP crash. Plus this surpresses any other recompile errors.
        if (EditorApplication.isCompiling)
        {
            if (PhotonNetworkManager.connected)
            {
                if (lastWarning > EditorApplication.timeSinceStartup - 3)
                {
                    // Prevent error spam
                    Debug.LogWarning(CurrentLang.WarningPhotonDisconnect);
                    lastWarning = EditorApplication.timeSinceStartup;
                }

                PhotonNetworkManager.Disconnect();
            }
        }
    }
    private void OnGUI()
    {
        if (this.HideUI)
        {
            return;
        }

        GUILayout.BeginArea(new Rect(0, 0, 300, Screen.height));
        GUILayout.FlexibleSpace();
        GUILayout.BeginHorizontal();
        if (!PhotonNetworkManager.connected)
        {
            if (GUILayout.Button("Connect", GUILayout.Width(100)))
            {
                PhotonNetworkManager.ConnectUsingSettings(null);
            }
        }
        else
        {
            if (GUILayout.Button("Disconnect", GUILayout.Width(100)))
            {
                PhotonNetworkManager.Disconnect();
            }
        }
        GUILayout.Label(PhotonNetworkManager.connectionStateDetailed.ToString());
        GUILayout.EndHorizontal();
        GUILayout.EndArea();
    }
예제 #4
0
    public void OnGUI()
    {
        if (this.Skin != null)
        {
            GUI.skin = this.Skin;
        }

        if (PhotonNetworkManager.isMasterClient)
        {
            GUILayout.Label("Controlling client.\nPing: " + PhotonNetworkManager.GetPing());
            if (GUILayout.Button("disconnect", GUILayout.ExpandWidth(false)))
            {
                PhotonNetworkManager.Disconnect();
            }
        }
        else if (PhotonNetworkManager.isNonMasterClientInRoom)
        {
            GUILayout.Label("Receiving updates.\nPing: " + PhotonNetworkManager.GetPing());
            if (GUILayout.Button("disconnect", GUILayout.ExpandWidth(false)))
            {
                PhotonNetworkManager.Disconnect();
            }
        }
        else
        {
            GUILayout.Label("Not in room yet\n" + PhotonNetworkManager.connectionStateDetailed);
        }
        if (!PhotonNetworkManager.connected && !PhotonNetworkManager.connecting)
        {
            if (GUILayout.Button("connect", GUILayout.Width(80)))
            {
                PhotonNetworkManager.ConnectUsingSettings(null);   // using null as parameter, re-uses previously set version.
            }
        }
    }
예제 #5
0
 void Start()
 {
     if (PhotonNetworkManager.connected || PhotonNetworkManager.connecting)
     {
         PhotonNetworkManager.Disconnect();
     }
     m_Headline         = new GUIStyle(this.Skin.label);
     m_Headline.padding = new RectOffset(3, 0, 0, 0);
 }
예제 #6
0
    public void OnGUI()
    {
        bool sceneZeroLoaded = false;

                #if UNITY_5 && !UNITY_5_0 && !UNITY_5_1 && !UNITY_5_2 || UNITY_5_4_OR_NEWER
        sceneZeroLoaded = SceneManager.GetActiveScene().buildIndex == 0;
        #else
        sceneZeroLoaded = Application.loadedLevel == 0;
        #endif

        if (!sceneZeroLoaded)
        {
            int w = this.ButtonTexture.width + 4;
            int h = this.ButtonTexture.height + 4;

            this.ButtonRect = new Rect(Screen.width - w, Screen.height - h, w, h);
            if (GUI.Button(this.ButtonRect, this.ButtonTexture, GUIStyle.none))
            {
                PhotonNetworkManager.Disconnect();
                SceneManager.LoadScene(0);
            }
        }
    }
예제 #7
0
 /// <summary>Called by Unity when the application is closed. Disconnects.</summary>
 protected void OnApplicationQuit()
 {
     PhotonMenuManager.AppQuits = true;
     PhotonMenuManager.StopFallbackSendAckThread();
     PhotonNetworkManager.Disconnect();
 }
예제 #8
0
 public void BackToHub()
 {
     PhotonNetworkManager.Disconnect();
     SceneManager.LoadScene(0);
 }