Пример #1
0
        private void PlaymodeStateChangedHandler()
        {
            if (ShadowManager.IsDestroyed)
            {
                return;
            }

            ShadowManager shadowManager = ShadowManager.Instance;

            if (EditorApplication.isPlaying && !EditorApplication.isPaused)
            {
                shadowManager.Clear(false, true);
                shadowManager.UpdateStaticShadows();
                _updateFrameCount = 1;

                _isClearedOnPlaymodeChange      = false;
                _isPausedOnPlaymodeChangeToPlay = _isPausedOnPlaymodeChangeLast;
            }

            _isPausedOnPlaymodeChangeLast = EditorApplication.isPaused;
        }
Пример #2
0
        private void EditorUpdate()
        {
            string currentScene       = Application.loadedLevelName;
            string currentEditorScene = EditorApplication.currentScene;

            ShadowManager shadowManager = ShadowManager.Instance;

            // Re-attach camera events and repaint when
            // some frames have passed
            if (_updateFrameCount > 0)
            {
                _updateFrameCount--;

                EditorApplication.delayCall += () => {
                    shadowManager.UpdateCameraEvents(Camera.allCameras);
                    shadowManager.UpdateCameraEvents(SceneView.GetAllSceneCameras());
                    shadowManager.UpdateStaticShadows();

                    SceneView.RepaintAll();
                };
            }

            // Clear before entering Play mode
            if (!_isPausedOnPlaymodeChangeToPlay &&
                !_isClearedOnPlaymodeChange &&
                _reloadMarker != null &&
                EditorApplication.isPlayingOrWillChangePlaymode &&
                !ShadowManager.IsDestroyed)
            {
                ShadowManager.Instance.Clear(false, true);
                ShadowManager.Instance.UpdateStaticShadows();

                _isClearedOnPlaymodeChange = true;
            }

            // When current scene has changed
            if (_reloadMarker != null && (_lastScene != currentScene || _lastEditorScene != currentEditorScene) && !ShadowManager.IsDestroyed)
            {
                // Destroy ShadowManager if there are no shadows in the scene
                if (ShadowManager.Instance.ShadowManagers.Count == 0)
                {
                    DestroyImmediate(ShadowManager.Instance.gameObject);
                }
                else if (!EditorApplication.isPlaying && !EditorApplication.isPlayingOrWillChangePlaymode)
                {
                    // Otherwise just clean
                    ShadowManager.Instance.Clear(false, true);
                    ShadowManager.Instance.UpdateStaticShadows();
                    EditorApplication.delayCall += () => {
                        shadowManager.UpdateCameraEvents(Camera.allCameras);
                    };
                }
            }

            if (_reloadMarker == null)
            {
                _reloadMarker = new object();
                SetIsMustUpdate();
            }

            _lastScene       = currentScene;
            _lastEditorScene = currentEditorScene;
        }