Beispiel #1
0
    public void Update()
    {
        GameApp.CameraStack.Update();


#if UNITY_EDITOR
        // Ugly hack to force focus to game view when using scriptable renderloops.
        if (Time.frameCount < 4)
        {
            try
            {
                var gameViewType = typeof(UnityEditor.EditorWindow).Assembly.GetType("UnityEditor.GameView");
                var gameView     = (EditorWindow)Resources.FindObjectsOfTypeAll(gameViewType)[0];
                gameView.Focus();
            }
            catch (System.Exception) { /* too bad */ }
        }
#endif

        frameTime  = (double)m_Clock.ElapsedTicks / m_StopwatchFrequency;
        frameCount = Time.frameCount;

        GameDebug.SetFrameCount(frameCount);
        Console.SetFrameTime(frameTime);;

        Console.ConsoleUpdate();

        //bool menusShowing = (clientFrontend != null && clientFrontend.menuShowing != ClientFrontend.MenuShowing.None);
        InputSystem.WindowFocusUpdate(false);

        UpdateCPUStats();
        UpdateEntityStats();

        endUpdateEvent?.Invoke();
    }
Beispiel #2
0
    public void Update()
    {
        if (!m_isHeadless)
        {
            RenderSettings.Update();
        }

        // TODO (petera) remove this hack once we know exactly when renderer is available...
        if (!pipeSetup)
        {
            var hdpipe = RenderPipelineManager.currentPipeline as HDRenderPipeline;
            if (hdpipe != null)
            {
                var layer = LayerMask.NameToLayer("PostProcess Volumes");
                if (layer == -1)
                {
                    GameDebug.LogWarning("Unable to find layer mask for camera fader");
                }
                else
                {
                    var gameObject = new GameObject()
                    {
                        name      = "Game Quick Volume",
                        layer     = layer,
                        hideFlags = HideFlags.HideAndDontSave
                    };

                    m_ExposureVolume          = gameObject.AddComponent <Volume>();
                    m_ExposureVolume.priority = 100.0f;
                    m_ExposureVolume.isGlobal = true;
                    var profile = m_ExposureVolume.profile;

                    m_Exposure        = profile.Add <Exposure>();
                    m_Exposure.active = false;
                    m_Exposure.mode.Override(ExposureMode.Automatic);
                    m_Exposure.compensation.Override(0);
                }

                pipeSetup = true;
            }
        }
        if (m_ExposureReleaseCount > 0)
        {
            m_ExposureReleaseCount--;
            if (m_ExposureReleaseCount == 0)
            {
                BlackFade(false);
            }
        }

        GameApp.CameraStack.Update();


#if UNITY_EDITOR
        // Ugly hack to force focus to game view when using scriptable renderloops.
        if (Time.frameCount < 4)
        {
            try
            {
                var gameViewType = typeof(UnityEditor.EditorWindow).Assembly.GetType("UnityEditor.GameView");
                var gameView     = (EditorWindow)Resources.FindObjectsOfTypeAll(gameViewType)[0];
                gameView.Focus();
            }
            catch (System.Exception) { /* too bad */ }
        }
#endif

        frameTime  = (double)m_Clock.ElapsedTicks / m_StopwatchFrequency;
        frameCount = Time.frameCount;

        GameDebug.SetFrameCount(frameCount);
        Console.SetFrameTime(frameTime);;

        // Switch game loop if needed
        if (m_RequestedGameLoopTypes.Count > 0)
        {
            // Multiple running gameloops only allowed in editor
#if !UNITY_EDITOR
            ShutdownGameLoops();
#endif
            bool initSucceeded = false;
            for (int i = 0; i < m_RequestedGameLoopTypes.Count; i++)
            {
                try
                {
                    IGameLoop gameLoop = (IGameLoop)System.Activator.CreateInstance(m_RequestedGameLoopTypes[i]);
                    initSucceeded = gameLoop.Init(m_RequestedGameLoopArguments[i]);
                    Debug.Log("Game initialization succeeded: " + initSucceeded);
                    if (!initSucceeded)
                    {
                        break;
                    }

                    m_gameLoops.Add(gameLoop);
                }
                catch (System.Exception e)
                {
                    GameDebug.LogError(string.Format("Game loop initialization threw exception : ({0})\n{1}", e.Message, e.StackTrace));
                }
            }


            if (!initSucceeded)
            {
                ShutdownGameLoops();

                GameDebug.LogError("Game loop initialization failed ... reverting to boot loop");
            }

            m_RequestedGameLoopTypes.Clear();
            m_RequestedGameLoopArguments.Clear();
        }

        try
        {
            if (!m_ErrorState)
            {
                foreach (var gameLoop in m_gameLoops)
                {
                    gameLoop.Update();
                }
                levelManager.Update();
            }
        }
        catch (System.Exception e)
        {
            HandleGameloopException(e);
            throw;
        }

        if (SoundSystem.Instance != null)
        {
            SoundSystem.Instance.Update();
        }

        if (clientFrontend != null)
        {
            clientFrontend.UpdateGame();
        }

        Console.ConsoleUpdate();

        bool menusShowing = (clientFrontend != null && clientFrontend.menuShowing != ClientFrontend.MenuShowing.None);
        InputSystem.WindowFocusUpdate(menusShowing);

        UpdateCPUStats();
        UpdateEntityStats();

        sqpClient.Update();

        endUpdateEvent?.Invoke();

        /* HACKY WAY TO LOOK AT MONOBEHAVIOURS LEFT
         * if (Time.frameCount % 1000 == 100)
         * {
         *  var mbs = FindObjectsOfType(typeof(MonoBehaviour));
         *  numMBS = mbs.Length;
         *  var h = new HashSet<Type>();
         *  foreach (var mb in mbs)
         *  {
         *      h.Add(mb.GetType());
         *  }
         *  foreach(var t in h)
         *      GameDebug.Log(":" + t);
         *  numUMBS = h.Count();
         * }
         * Overlay.Managed.Write(2, 4, "Monobehaviours left {0} ({1})", numMBS, numUMBS);
         */
    }