Пример #1
0
        /// <summary>
        /// Unloads a scene asynchronously, dispatching the appropriate unload events.
        /// </summary>
        static public AsyncOperation UnloadAsync(SceneBinding inScene, object inContext = null, UnloadSceneOptions inOptions = UnloadSceneOptions.None)
        {
            if (!inScene.IsValid())
            {
                Debug.LogErrorFormat("Cannot unload invalid scene '{0}'", inScene.Path);
                return(null);
            }

            inScene.BroadcastUnload(inContext);
            return(SceneManager.UnloadSceneAsync(inScene.Scene, inOptions));
        }
Пример #2
0
        /// <summary>
        /// Returns if the given scene is ignored by filters.
        /// </summary>
        static public bool IsIgnored(SceneBinding inScene)
        {
            for (int i = 0; i < s_IgnoredSceneFilters.Count; ++i)
            {
                if (s_IgnoredSceneFilters[i].Match(inScene))
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #3
0
        /// <summary>
        /// Returns all active scenes.
        /// </summary>
        static public IEnumerable <SceneBinding> AllLoadedScenes(bool inbIncludeIgnored = false)
        {
            int sceneCount = SceneManager.sceneCount;

            for (int i = 0; i < sceneCount; ++i)
            {
                SceneBinding sceneBinding = SceneManager.GetSceneAt(i);
                if (inbIncludeIgnored || !IsIgnored(sceneBinding))
                {
                    yield return(sceneBinding);
                }
            }
        }
Пример #4
0
            public bool Match(SceneBinding inScene)
            {
                if (!string.IsNullOrEmpty(Name))
                {
                    return(StringUtils.WildcardMatch(inScene.Name, Name));
                }

                if (!string.IsNullOrEmpty(Path))
                {
                    return(StringUtils.WildcardMatch(inScene.Path, Path));
                }

                return(false);
            }
Пример #5
0
        /// <summary>
        /// Returns all scenes in the build.
        /// </summary>
        static public IEnumerable <SceneBinding> AllBuildScenes(bool inbIncludeIgnored = false)
        {
            int buildSceneCount = SceneManager.sceneCountInBuildSettings;

            for (int i = 0; i < buildSceneCount; ++i)
            {
                string       path    = SceneUtility.GetScenePathByBuildIndex(i);
                SceneBinding binding = new SceneBinding(i, path);
                if (inbIncludeIgnored || !IsIgnored(binding))
                {
                    yield return(binding);
                }
            }
        }
Пример #6
0
        /// <summary>
        /// Finds scenes, filtering by category.
        /// </summary>
        static public IEnumerable <SceneBinding> FindScenes(SceneCategories inCategories)
        {
            bool bBuild          = (inCategories & SceneCategories.Build) == SceneCategories.Build;
            bool bLoaded         = (inCategories & SceneCategories.Loaded) == SceneCategories.Loaded;
            bool bActive         = (inCategories & SceneCategories.ActiveOnly) == SceneCategories.ActiveOnly;
            bool bIncludeIgnored = (inCategories & SceneCategories.IncludeIgnored) == SceneCategories.IncludeIgnored;

            if (bActive)
            {
                SceneBinding active = SceneManager.GetActiveScene();
                if (!bIncludeIgnored && IsIgnored(active))
                {
                    yield break;
                }

                if (bBuild && active.BuildIndex < 0)
                {
                    yield break;
                }

                if (bLoaded && !active.IsLoaded())
                {
                    yield break;
                }

                yield return(active);
            }
            else if (bBuild)
            {
                foreach (var scene in AllBuildScenes(bIncludeIgnored))
                {
                    if (bLoaded && !scene.IsLoaded())
                    {
                        continue;
                    }

                    yield return(scene);
                }
            }
            else if (bLoaded)
            {
                foreach (var scene in AllLoadedScenes(bIncludeIgnored))
                {
                    yield return(scene);
                }
            }
        }
Пример #7
0
        /// <summary>
        /// Returns all active scenes.
        /// </summary>
        static public int AllLoadedScenes(ICollection <SceneBinding> outScenes, bool inbIncludeIgnored = false)
        {
            int sceneCount = SceneManager.sceneCount;

            int returnedCount = 0;

            for (int i = 0; i < sceneCount; ++i)
            {
                SceneBinding sceneBinding = SceneManager.GetSceneAt(i);
                if (inbIncludeIgnored || !IsIgnored(sceneBinding))
                {
                    outScenes.Add(sceneBinding);
                    ++returnedCount;
                }
            }

            return(returnedCount);
        }
Пример #8
0
        /// <summary>
        /// Gathers all scenes in the build.
        /// </summary>
        static public int AllBuildScenes(ICollection <SceneBinding> outScenes, bool inbIncludeIgnored = false)
        {
            int buildSceneCount = SceneManager.sceneCountInBuildSettings;

            int returnedCount = 0;

            for (int i = 0; i < buildSceneCount; ++i)
            {
                string       path    = SceneUtility.GetScenePathByBuildIndex(i);
                SceneBinding binding = new SceneBinding(i, path);
                if (inbIncludeIgnored || !IsIgnored(binding))
                {
                    outScenes.Add(binding);
                    ++returnedCount;
                }
            }
            return(returnedCount);
        }
Пример #9
0
        /// <summary>
        /// Loads a scene asynchronously, dispatching the appropriate load and unload events.
        /// </summary>
        static public AsyncOperation LoadAsync(SceneBinding inScene, object inContext = null, LoadSceneMode inMode = LoadSceneMode.Single)
        {
            if (!inScene.IsValid())
            {
                Debug.LogErrorFormat("Cannot load invalid scene '{0}'", inScene.Path);
                return(null);
            }

            if (inMode == LoadSceneMode.Single)
            {
                foreach (var scene in FindScenes(SceneCategories.Loaded))
                {
                    scene.BroadcastUnload(inContext);
                }
            }

            AsyncOperation loadOp = SceneManager.LoadSceneAsync(inScene.Path, inMode);

            loadOp.completed += (AsyncOperation op) =>
            {
                inScene.BroadcastLoaded(inContext);
            };
            return(loadOp);
        }