GetSceneByBuildIndex() 공개 정적인 메소드

Get a scene struct from a build index.

public static GetSceneByBuildIndex ( int buildIndex ) : Scene
buildIndex int Build index as shown in the Build Settings window.
리턴 Scene
예제 #1
0
        public static void LoadSceneById(int id, bool force = false)
        {
            if (id >= GetSceneCount())
            {
                throw new Exception("Scene Index outisde of Range");
            }

            int   index = 1 + id;
            Scene scene = SCM.GetSceneByBuildIndex(index);

            if (force)
            {
                if (!scene.isLoaded)
                {
                    SCM.LoadScene(index);
                }
                else
                {
                    SCM.LoadScene(scene.name);
                }
            }
            else
            if (!scene.isLoaded)
            {
                SCM.LoadSceneAsync(index);
            }
            else
            {
                SCM.LoadSceneAsync(scene.name);
            }
        }
예제 #2
0
    private IEnumerator AnimateUnloadAdditiveScene(SceneAnimationEventsManager animEventsManager, Action onUnloaded = null)
    {
        if (additiveScenes.Count > 0)
        {
            if (animEventsManager == null)
            {
                animEventsManager = FindObjectsOfType <SceneAnimationEventsManager>()
                                    .FirstOrDefault(m => m.gameObject.scene == UnitySceneManager.GetSceneByBuildIndex((int)additiveScenes.Peek()));
            }

            // Found
            if (animEventsManager != null)
            {
                animEventsManager.FadeOut();

                yield return(new WaitUntil(() => animEventsManager.FadedOut));
            }

            var scene = additiveScenes.Pop();

            UnloadScene((int)scene);
            onUnloaded?.Invoke();
        }

        this.RemoveCoroutine(nameof(AnimateUnloadAdditiveScene));
    }
예제 #3
0
        public static async Task UnloadSceneAsycn(int sceneIndex)
        {
            TaskCompletionSource <bool> taskCompletionSource = new TaskCompletionSource <bool>();

            AsyncOperation asyncOperation = USceneManager.UnloadSceneAsync(sceneIndex);

            asyncOperation.completed += (AsyncOperation ao) => taskCompletionSource.SetResult(ao.isDone);

            await taskCompletionSource.Task;

            FLog.Info(CLASS_TYPE.Name, $"Scene `{USceneManager.GetSceneByBuildIndex(sceneIndex).name}` has been unloaded.");
        }
        private void RenderTabScenes()
        {
            using (new GUILayout.VerticalScope("Box"))
            {
                GUILayout.Label("All scenes", "header");

                using (GUILayout.ScrollViewScope scroll = new GUILayout.ScrollViewScope(sceneScrollPos))
                {
                    sceneScrollPos = scroll.scrollPosition;

                    for (int i = 0; i < USceneManager.sceneCountInBuildSettings; i++)
                    {
                        Scene  currentScene = USceneManager.GetSceneByBuildIndex(i);
                        string path         = SceneUtility.GetScenePathByBuildIndex(i);
                        bool   isSelected   = selectedScene.IsValid() && currentScene == selectedScene;
                        bool   isLoaded     = currentScene.isLoaded;

                        using (new GUILayout.HorizontalScope("Box"))
                        {
                            if (GUILayout.Button($"{(isSelected ? ">> " : "")}{i}: {path.TruncateLeft(35)}", isLoaded ? "sceneLoaded" : "label"))
                            {
                                selectedScene = currentScene;
                                ActiveTab     = GetTab("Hierarchy");
                            }

                            if (isLoaded)
                            {
                                if (GUILayout.Button("Unload", "loadScene"))
                                {
                                    USceneManager.UnloadSceneAsync(i);
                                }
                            }
                            else
                            {
                                if (GUILayout.Button("Load", "loadScene"))
                                {
                                    USceneManager.LoadSceneAsync(i);
                                }
                            }
                        }
                    }
                }
            }
        }