示例#1
0
    void OnGUI()
    {
        int width  = 150;
        int height = 30;
        int top    = 70;
        int i      = 0;

        bool init             = false;
        bool shutdown         = false;
        bool requestAuthToken = false;
        bool setAuthToken     = false;
        bool logOut           = false;
        bool start            = false;
        bool stop             = false;
        bool pause            = false;
        bool resume           = false;
        bool runCommercial    = false;
        bool startIngestTest  = false;
        bool skipIngestServer = false;
        bool cancelIngestTest = false;
        bool gamePause        = false;
        bool gameResume       = false;
        bool loadNextScene    = false;
        bool enterFullScreen  = false;
        bool exitFullScreen   = false;

        if (m_BroadcastController.IsInitialized)
        {
            if (m_BroadcastController.IsBroadcasting)
            {
                runCommercial = GUI.Button(new Rect(10, top + height * i++, width, height), "Run Commercial");

                if (m_BroadcastController.IsPaused)
                {
                    resume = GUI.Button(new Rect(10, top + height * i++, width, height), "Resume");
                }
                else
                {
                    pause = GUI.Button(new Rect(10, top + height * i++, width, height), "Pause");
                }

                stop = GUI.Button(new Rect(10, top + height * i++, width, height), "Stop");
            }
            else
            {
                if (m_BroadcastController.IsLoggedIn)
                {
                    if (m_BroadcastController.IsReadyToBroadcast)
                    {
                        start           = GUI.Button(new Rect(10, top + height * i++, width, height), "Start");
                        startIngestTest = GUI.Button(new Rect(10, top + height * i++, width, height), "Start Ingest Test");
                        logOut          = GUI.Button(new Rect(10, top + height * i++, width, height), "Log Out");
                    }
                    else if (m_BroadcastController.IsIngestTesting)
                    {
                        skipIngestServer = GUI.Button(new Rect(10, top + height * i++, width, height), "Skip Server");
                        cancelIngestTest = GUI.Button(new Rect(10, top + height * i++, width, height), "Cancel Ingest Test");
                    }
                }
                else
                {
                    requestAuthToken = GUI.Button(new Rect(10, top + height * i++, width, height), "Request Auth Token");
                    setAuthToken     = GUI.Button(new Rect(10, top + height * i++, width, height), "Use Existing Auth Token");
                }

                if (!m_BroadcastController.IsIngestTesting)
                {
                    shutdown = GUI.Button(new Rect(10, top + height * i++, width, height), "Shutdown");
                }
            }
        }
        else
        {
            init = GUI.Button(new Rect(10, top + height * i++, width, height), "Init");
        }

        if (m_GamePaused)
        {
            gameResume = GUI.Button(new Rect(10, top + height * i++, width, height), "Resume Game");
        }
        else
        {
            gamePause = GUI.Button(new Rect(10, top + height * i++, width, height), "Pause Game");
        }

        loadNextScene = GUI.Button(new Rect(10, top + height * i++, width, height), "Load Next Scene");

        if (Screen.fullScreen)
        {
            exitFullScreen = GUI.Button(new Rect(10, top + height * i++, width, height), "Exit Full Screen");
        }
        else
        {
            enterFullScreen = GUI.Button(new Rect(10, top + height * i++, width, height), "Go Full Screen");
        }

        if (init)
        {
            if (!m_BroadcastController.Initialize())
            {
                DebugOverlay.Instance.AddViewportText("Error initializing Twitch", 2);
            }
        }
        else if (shutdown)
        {
            m_BroadcastController.Shutdown();
        }
        else if (start)
        {
            VideoParams videoParams = null;

            if (m_CalculateParamsFromBitrate)
            {
                videoParams = m_BroadcastController.GetRecommendedVideoParams((uint)m_TargetBitrate, (uint)m_BroadcastFramesPerSecond, m_BroadcastBitsPerPixel, m_BroadcastAspectRatio);
            }
            else
            {
                videoParams = m_BroadcastController.GetRecommendedVideoParams((uint)m_BroadcastWidth, (uint)m_BroadcastHeight, (uint)m_BroadcastFramesPerSecond);
            }

            if (!m_BroadcastController.StartBroadcasting(videoParams))
            {
                return;
            }
        }
        else if (requestAuthToken)
        {
            m_BroadcastController.RequestAuthToken(m_UserName, m_Password);
        }
        else if (setAuthToken)
        {
            string token    = PlayerPrefs.GetString(s_TwitchAuthTokenKey, null);
            string username = PlayerPrefs.GetString(s_TwitchUserNameKey, null);

            if (token != null && username != null)
            {
                m_BroadcastController.SetAuthToken(username, new AuthToken(token));
            }
        }
        else if (logOut)
        {
            m_BroadcastController.Logout();
        }
        else if (stop)
        {
            m_BroadcastController.StopBroadcasting();
        }
        else if (pause)
        {
            m_BroadcastController.PauseBroadcasting();
        }
        else if (resume)
        {
            m_BroadcastController.ResumeBroadcasting();
        }
        else if (runCommercial)
        {
            m_BroadcastController.RunCommercial();
        }
        else if (startIngestTest)
        {
            m_IngestTester = m_BroadcastController.StartIngestTest();
            if (m_IngestTester != null)
            {
                m_IngestTester.OnTestStateChanged += OnIngestTesterStateChanged;
            }
        }
        else if (skipIngestServer)
        {
            m_BroadcastController.IngestTester.SkipCurrentServer();
        }
        else if (cancelIngestTest)
        {
            m_BroadcastController.IngestTester.Cancel();
        }

        if (gamePause)
        {
            m_GamePaused   = true;
            Time.timeScale = 0;
        }
        else if (gameResume)
        {
            m_GamePaused   = false;
            Time.timeScale = 1;
        }
        else if (loadNextScene)
        {
            string scene = "SampleScene";
            if (Application.loadedLevelName == "SampleScene")
            {
                scene = "SampleScene2";
            }
            Application.LoadLevel(scene);
        }
        else if (enterFullScreen)
        {
            Screen.SetResolution(1080, 1024, true);
        }
        else if (exitFullScreen)
        {
            Screen.SetResolution(1080, 1024, false);
        }
    }
示例#2
0
    void OnGUI()
    {
        if (m_AutoBroadcast)
        {
            return;
        }

        int width  = 150;
        int height = 30;
        int top    = 70;
        int i      = 0;

        bool init             = false;
        bool shutdown         = false;
        bool requestAuthToken = false;
        bool setAuthToken     = false;
        bool logOut           = false;
        bool start            = false;
        bool stop             = false;
        bool pause            = false;
        bool resume           = false;
        bool runCommercial    = false;
        bool startIngestTest  = false;
        bool skipIngestServer = false;
        bool cancelIngestTest = false;
        bool gamePause        = false;
        bool gameResume       = false;
        bool loadNextScene    = false;
        bool enterFullScreen  = false;
        bool exitFullScreen   = false;
        bool toggleSound      = false;

        if (m_BroadcastController.IsInitialized)
        {
            if (m_BroadcastController.IsBroadcasting)
            {
                runCommercial = GUI.Button(new Rect(10, top + height * i++, width, height), "Run Commercial");

                if (m_BroadcastController.IsPaused)
                {
                    resume = GUI.Button(new Rect(10, top + height * i++, width, height), "Resume");
                }
                else
                {
                    pause = GUI.Button(new Rect(10, top + height * i++, width, height), "Pause");
                }

                stop = GUI.Button(new Rect(10, top + height * i++, width, height), "Stop");
            }
            else
            {
                if (m_BroadcastController.IsLoggedIn)
                {
                    if (m_BroadcastController.IsReadyToBroadcast)
                    {
                        start           = GUI.Button(new Rect(10, top + height * i++, width, height), "Start");
                        startIngestTest = GUI.Button(new Rect(10, top + height * i++, width, height), "Start Ingest Test");
                        logOut          = GUI.Button(new Rect(10, top + height * i++, width, height), "Log Out");
                    }
                    else if (m_BroadcastController.IsIngestTesting)
                    {
                        skipIngestServer = GUI.Button(new Rect(10, top + height * i++, width, height), "Skip Server");
                        cancelIngestTest = GUI.Button(new Rect(10, top + height * i++, width, height), "Cancel Ingest Test");
                    }
                }
                else
                {
                    requestAuthToken = GUI.Button(new Rect(10, top + height * i++, width, height), "Request Auth Token");
                    setAuthToken     = GUI.Button(new Rect(10, top + height * i++, width, height), "Use Existing Auth Token");
                }

                if (!m_BroadcastController.IsIngestTesting)
                {
                    shutdown = GUI.Button(new Rect(10, top + height * i++, width, height), "Shutdown");
                }
            }
        }
        else
        {
            init = GUI.Button(new Rect(10, top + height * i++, width, height), "Init");
        }

        if (m_GamePaused)
        {
            gameResume = GUI.Button(new Rect(10, top + height * i++, width, height), "Resume Game");
        }
        else
        {
            gamePause = GUI.Button(new Rect(10, top + height * i++, width, height), "Pause Game");
        }

        loadNextScene = GUI.Button(new Rect(10, top + height * i++, width, height), "Load Next Scene");

#if !UNITY_IPHONE
        if (Screen.fullScreen)
        {
            exitFullScreen = GUI.Button(new Rect(10, top + height * i++, width, height), "Exit Full Screen");
        }
        else
        {
            enterFullScreen = GUI.Button(new Rect(10, top + height * i++, width, height), "Go Full Screen");
        }
#endif

        // Find an AudioSource
        AudioSource          audioSource = null;
        UnityEngine.Object[] arr         = GameObject.FindObjectsOfType(typeof(AudioSource));
        if (arr != null && arr.Length > 0)
        {
            audioSource = arr[0] as AudioSource;
        }

        if (audioSource != null)
        {
            if (audioSource.isPlaying)
            {
                toggleSound = GUI.Button(new Rect(10, top + height * i++, width, height), "Stop Sound");
            }
            else
            {
                toggleSound = GUI.Button(new Rect(10, top + height * i++, width, height), "Play Sound");
            }
        }

        if (init)
        {
            if (!m_BroadcastController.Initialize())
            {
                DebugOverlay.Instance.AddViewportText("Error initializing Twitch", 2);
            }
        }
        else if (shutdown)
        {
            m_BroadcastController.Shutdown();
        }
        else if (start)
        {
            StartBroadcasting();
        }
        else if (requestAuthToken)
        {
            m_BroadcastController.RequestAuthToken(m_UserName, m_Password);
        }
        else if (setAuthToken)
        {
            string token    = PlayerPrefs.GetString(s_TwitchAuthTokenKey, null);
            string username = PlayerPrefs.GetString(s_TwitchUserNameKey, null);

            if (token != null && username != null)
            {
                m_BroadcastController.SetAuthToken(username, new AuthToken(token));
            }
        }
        else if (logOut)
        {
            m_BroadcastController.Logout();
        }
        else if (stop)
        {
            m_BroadcastController.StopBroadcasting();
        }
        else if (pause)
        {
            m_BroadcastController.PauseBroadcasting();
        }
        else if (resume)
        {
            m_BroadcastController.ResumeBroadcasting();
        }
        else if (runCommercial)
        {
            m_BroadcastController.RunCommercial();
        }
        else if (startIngestTest)
        {
            m_IngestTester = m_BroadcastController.StartIngestTest();
            if (m_IngestTester != null)
            {
                m_IngestTester.OnTestStateChanged += OnIngestTesterStateChanged;
            }
        }
        else if (skipIngestServer)
        {
            m_BroadcastController.IngestTester.SkipCurrentServer();
        }
        else if (cancelIngestTest)
        {
            m_BroadcastController.IngestTester.Cancel();
        }

        if (gamePause)
        {
            m_GamePaused   = true;
            Time.timeScale = 0;
        }
        else if (gameResume)
        {
            m_GamePaused   = false;
            Time.timeScale = 1;
        }
        else if (loadNextScene)
        {
            string scene = "SampleScene";
            if (Application.loadedLevelName == "SampleScene")
            {
                scene = "SampleScene2";
            }
            Application.LoadLevel(scene);
        }
        else if (enterFullScreen)
        {
            Screen.SetResolution(1080, 1024, true);
        }
        else if (exitFullScreen)
        {
            Screen.SetResolution(1080, 1024, false);
        }
        else if (toggleSound)
        {
            if (audioSource.isPlaying)
            {
                audioSource.Stop();
            }
            else
            {
                audioSource.Play();
            }
        }

        DebugOverlay.Instance.AddViewportText("Audio sample rate: " + AudioSettings.outputSampleRate, 0);
    }