This MonoBehaviour is a basic GUI for the Photon client's statistics features. The shown health values can help identify problems with connection losses or performance. Example: If the time delta between two consecutive SendOutgoingCommands calls is a second or more, chances rise for a disconnect being caused by this (because acknowledgements to the server need to be sent in due time).
Inheritance: MonoBehaviour
    void Update()
    {
        if (Input.GetButtonDown("ShowNetworkGUI"))
        {
            PhotonStatsGui statsGui = GameObject.FindObjectOfType <PhotonStatsGui>();
            if (statsGui == null)
            {
                GameObject go = new GameObject("PhotonStatsGUI");
                statsGui = go.AddComponent <PhotonStatsGui>();
            }
            else
            {
                statsGui.enabled = !statsGui.enabled;
            }
        }

        if (Input.GetButtonDown("ShowLagSimulation"))
        {
            PhotonLagSimulationGui lagSimulationGui = GameObject.FindObjectOfType <PhotonLagSimulationGui>();
            if (lagSimulationGui == null)
            {
                GameObject go = new GameObject("PhotonLagSimulationGUI");
                lagSimulationGui = go.AddComponent <PhotonLagSimulationGui>();
            }
            else
            {
                lagSimulationGui.enabled = !lagSimulationGui.enabled;
            }
        }
    }
Esempio n. 2
0
    /// <summary>
    /// This Unity window wraps up buttons for additional feature showcases. As such they
    /// would not be part of a regular game.
    /// </summary>
    /// <param name="id">the window's id. we only use one window.</param>
    private void OnGUIWindowOptions(int id)
    {
        GUILayout.BeginArea(new Rect(2, 20, Screen.width / 3, Screen.height / 3));

        if (GUILayout.Button("Close Options"))
        {
            this.showOptions = false;
        }

        // This button controls the encryption showcase. First off, encryption keys must be exchanged.
        if (!this.GameInstance.PeerIsEncryptionAvailable)
        {
            if (GUILayout.Button("Encryption: Exchange keys"))
            {
                this.GameInstance.OpExchangeKeysForEncryption();
            }
        }
        else
        {
            // After encryption keys were exchanged, you can use encryption. As demo, this is used on positon data.
            if (GUILayout.Button(Game.RaiseEncrypted ? "Enrcyption: Dont" : "Encryption: Do use"))
            {
                Game.RaiseEncrypted = !Game.RaiseEncrypted;
            }
        }

        // Toggle between reliable and unreliable sending of the position updates.
        if (GUILayout.Button(Player.isSendReliable ? "Send pos unreliable" : "Send pos reliable"))
        {
            Player.isSendReliable = !Player.isSendReliable;
        }

        // Toggle visibility of PhotonStatsGui
        PhotonNetSimSettingsGui pnssg = FindObjectOfType(typeof(PhotonNetSimSettingsGui)) as PhotonNetSimSettingsGui;   // better cache this to avoid Find

        if (pnssg != null && GUILayout.Button(pnssg.Visible ? "Hide Network Simulation Settings" : "Show Network Simulation Settings"))
        {
            pnssg.Visible = !pnssg.Visible;
        }

        // Toggle visibility of PhotonNetSimSettingsGui
        PhotonStatsGui psg = FindObjectOfType(typeof(PhotonStatsGui)) as PhotonStatsGui;    // better cache this to avoid Find

        if (psg != null && GUILayout.Button(psg.Visible ? "Hide Photon statistics" : "Show Photon statistics"))
        {
            psg.Visible = !psg.Visible;
        }

        GUILayout.EndArea();
    }
Esempio n. 3
0
    /// <summary>The "helper" gui scripts need to knwo the peer, so we set them. This is optional.</summary>
    public void SetPeerForGuiElements()
    {
        PhotonNetSimSettingsGui pnssg = FindObjectOfType(typeof(PhotonNetSimSettingsGui)) as PhotonNetSimSettingsGui;

        if (pnssg != null)
        {
            pnssg.Peer = this.Peer;
        }

        PhotonStatsGui psg = FindObjectOfType(typeof(PhotonStatsGui)) as PhotonStatsGui;

        if (psg != null)
        {
            psg.Peer = this.Peer;
        }
    }
Esempio n. 4
0
        private void Awake()
        {
            if (FindObjectOfType <PhotonSingletonManager>() == null)
            {
                return;
            }

            if (Application.isEditor)
            {
                m_FullscreenButton.interactable  = false;
                m_ScreenResolutions.interactable = false;
            }
            else
            {
                m_ScreenWidth          = Screen.width;
                m_ScreenHeight         = Screen.height;
                m_FullScreenResolution = Screen.currentResolution;

                PlayerPrefs.SetInt("Screenmanager Resolution Width", m_ScreenWidth);
                PlayerPrefs.SetInt("Screenmanager Resolution Height", m_ScreenHeight);
                PlayerPrefs.SetInt("Screenmanager Is Fullscreen mode", Screen.fullScreen ? 1 : 0);

                m_FullscreenButton.onClick.AddListener(OnFullScreenButtonClick);
                m_ScreenResolutions.onValueChanged.AddListener(OnResolutionChange);
                SetStartValueOfScreenResolutions();
            }
            m_DisconnectButton.onClick.AddListener(DisconnectFromServer);
            m_DisconnectButton.interactable = false;

            m_StastGUIToggle.onValueChanged.AddListener(OnStatsGuiToggleClick);
            m_LagSimGUIToggle.onValueChanged.AddListener(OnLagSimGuiToggleClick);

            m_StatsGUI          = GetComponent <PhotonStatsGui>();
            m_LaggSimulationGUI = GetComponent <PhotonLagSimulationGui>();

            UpdateClientStateText(shownState);
        }