private static void OnPlayModeStateChanged(PlayModeStateChange change)
        {
            if (ValidationSettings.ValidateScenesBeforePlayMode && change == PlayModeStateChange.ExitingEditMode)
            {
                var  validator = new SceneValidator();
                bool hasErrors = false;

                for (int i = 0; i < EditorSceneManager.sceneCount; i++)
                {
                    var scene = EditorSceneManager.GetSceneAt(i);
                    if (scene.isLoaded)
                    {
                        var validationReport = validator.CreateValidationReport(scene);
                        validationReport.LogErrors();

                        if (validationReport.HasErrors)
                        {
                            hasErrors = true;
                        }
                    }
                }

                // Abort entering play mode.
                if (hasErrors)
                {
                    EditorApplication.isPlaying = false;

                    var sceneView = SceneView.lastActiveSceneView;
                    if (sceneView != null)
                    {
                        sceneView.ShowNotification(new UnityEngine.GUIContent("- Play Mode Validation Failed -\nSee the console window for details."), 3.0);
                    }
                }
            }
        }
Example #2
0
        private static ValidationReport RunValidation()
        {
            var   validator   = new SceneValidator();
            Scene activeScene = EditorSceneManager.GetActiveScene();

            return(validator.CreateValidationReport(activeScene));
        }
        public static void ValidateOpenScenes()
        {
            SceneValidator validator = new SceneValidator();

            for (int i = 0; i < EditorSceneManager.sceneCount; i++)
            {
                Scene scene = EditorSceneManager.GetSceneAt(i);
                validator.CreateValidationReport(scene).LogErrors();
            }
        }
 public void TearDown()
 {
     sceneValidator = null;
 }
 public void Setup()
 {
     sceneValidator = new SceneValidator();
 }