static IEnumerator ProcessAllScenesCoroutine(ProcessAllScenesDelegate callback)
    {
        var sceneCount = EditorSceneManager.sceneCountInBuildSettings;

        Debug.Log(string.Format("Processing {0} scenes", sceneCount));

        var paths = EditorBuildSettings.scenes.Select(s => s.path).ToList();

        for (int i = 0; i < paths.Count; i++)
        {
            EditorSceneManager.OpenScene(paths[i], OpenSceneMode.Single);
            string sceneName = EditorSceneManager.GetActiveScene().name;
            EditorUtility.DisplayProgressBar("Procesnado escenas", $"Procesando {sceneName} ", (float)i / sceneCount);


            try
            {
                callback(sceneName);
            }
            catch (Exception e)
            {
                Debug.LogError($"Error while processing scene  '{sceneName}'");
                Debug.LogException(e);
            }
            yield return(null);
        }

        EditorUtility.ClearProgressBar();
        EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
    }
Exemple #2
0
 public void processAllScenes(
     ProcessAllScenesDelegate _callback)
 {
     processAllScenes(
         "Processing {0} Scenes",
         "Processing scene {1}/{0} : {2}",
         _callback);
 }
    public static void ProcessAllScenes(ProcessAllScenesDelegate _callback)
    {
        if (!EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
        {
            return;
        }

        EditorCoroutine.Start(ProcessAllScenesCoroutine(_callback));
    }
Exemple #4
0
    /// <summary>
    /// Format {0} : scene count
    /// Format {1} : scene index
    /// Format {2} : scene path
    /// </summary>
    public void processAllScenes(
        string _titleFormat,
        string _messageFormat,
        ProcessAllScenesDelegate _callback)
    {
        if (!EditorApplication.SaveCurrentSceneIfUserWantsTo())
        {
            return;
        }

        EditorCoroutine.start(
            processAllScenesCoroutine(_titleFormat, _messageFormat, _callback));
    }
Exemple #5
0
    IEnumerator processAllScenesCoroutine(
        string _titleFormat,
        string _messageFormat,
        ProcessAllScenesDelegate _callback)
    {
        var scenePaths = WriteConstantLists.Instance.GetAllScenesPaths();
        var sceneCount = scenePaths.Count;

        Debug.Log(string.Format("Processing {0} scenes", sceneCount));

        for (int i = 0; i < sceneCount; i++)
        {
            var scenePath = scenePaths[i];

            EditorUtility.DisplayProgressBar(
                string.Format(_titleFormat, sceneCount, i, scenePath),
                string.Format(_messageFormat, sceneCount, i, scenePath),
                (float)i / sceneCount);

            UnityEngine.Object sceneObject = AssetDatabase.LoadMainAssetAtPath(scenePath);

            if (EditorApplication.OpenScene(scenePath))
            {
                // delay one frame to give a chance for all Awake/Start/OnEnable callbacks to trigger
                yield return(null);

                try
                {
                    _callback(scenePath, sceneObject);
                }
                catch (Exception e)
                {
                    Debug.LogError(string.Format("Error while processing scene  '{0}'", scenePath), sceneObject);
                    Debug.LogException(e);
                }
            }
            else
            {
                Debug.LogError(string.Format("Failed to open scene '{0}'", scenePath), sceneObject);
            }
        }

        EditorUtility.ClearProgressBar();
        EditorApplication.NewScene();
    }
        /// <summary>
        /// Format {0} : scene count
        /// Format {1} : scene index
        /// Format {2} : scene path
        /// </summary>
        public static void processAllScenes(
            string _titleFormat,
            string _messageFormat,
            ProcessAllScenesDelegate _callback,
            System.Action _postProcess = null)
        {
            if (!EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
            {
                return;
            }

            if (runner == null)
            {
                runner = new SceneUtilityRunner();
            }
            runner.StartCoroutine(
                processAllScenesCoroutine(_titleFormat, _messageFormat, _callback, _postProcess));
        }
        static IEnumerator processAllScenesCoroutine(string _titleFormat, string _messageFormat, ProcessAllScenesDelegate _callback, System.Action _postProcess)
        {
            SceneSetup[] beforeSetup = EditorSceneManager.GetSceneManagerSetup();

            var scenePaths = findAllScenePaths();
            var sceneCount = scenePaths.Length;

            Debug.Log(string.Format("Processing {0} scenes", sceneCount));

            for (int i = 0; i < sceneCount; i++)
            {
                var scenePath = scenePaths[i];

                EditorUtility.DisplayProgressBar(
                    string.Format(_titleFormat, sceneCount, i, scenePath),
                    string.Format(_messageFormat, sceneCount, i, scenePath),
                    (float)i / sceneCount);

                SceneAsset sceneAsset  = AssetDatabase.LoadAssetAtPath(scenePath, typeof(SceneAsset)) as SceneAsset;
                Scene      sceneObject = EditorSceneManager.OpenScene(scenePath);

                if (sceneObject.IsValid())
                {
                    // delay one frame to give a chance for all Awake/Start/OnEnable callbacks to trigger
                    yield return(null);

                    try {
                        _callback(scenePath, sceneObject, sceneAsset);
                    } catch (Exception e) {
                        Debug.LogError(string.Format("Error while processing scene  '{0}'", scenePath), sceneAsset);
                        Debug.LogException(e);
                    }
                }
                else
                {
                    Debug.LogError(string.Format("Failed to open scene '{0}'", scenePath), sceneAsset);
                }
            }

            EditorUtility.ClearProgressBar();
            EditorSceneManager.RestoreSceneManagerSetup(beforeSetup);

            if (_postProcess != null)
            {
                _postProcess();
            }
        }