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; }