GetSceneByName() public static method

Searches through the scenes added to the SceneManager for a scene with the given name.

public static GetSceneByName ( string name ) : Scene
name string Name of scene to find.
return Scene
        private static IEnumerator LoadInternal(LoadContext context)
        {
            if (context == null)
            {
                yield break;
            }

            var scene = UnitySceneManager.GetSceneByName(context.NextScene.Name);

            if (!scene.isLoaded)
            {
                yield return(UnitySceneManager.LoadSceneAsync(context.NextScene.Name, LoadSceneMode.Additive));
            }
            UnitySceneManager.SetActiveScene(UnitySceneManager.GetSceneByName(context.NextScene.Name));

            var sceneContext = FindSceneContext(context.NextScene.Name);

            if (sceneContext == null)
            {
                yield break;
            }

            yield return(new WaitUntil(() => sceneContext.Initialized));

            var sceneSettings = sceneContext.Container.TryResolve <SceneSettings>();

            if (sceneSettings != null)
            {
                sceneSettings.Subs.ForEach(x => context.AddAdditiveScene(x));
            }
            context.NextScene.Lifecycles = sceneContext.Container.ResolveAll <ISceneLifecycle>();
        }
Esempio n. 2
0
        public void SetCurrentScene(SceneName sceneName)
        {
            var scene = UnitySceneManager.GetSceneByName(sceneName.ToString());

            UnitySceneManager.SetActiveScene(scene);
            loadedSceneNames.Add(sceneName.ToString());
        }
Esempio n. 3
0
    private void Update()
    {
        for (int i = 0; i < sceneLoaderList.Count; i++)
        {
            SceneLoader loader = sceneLoaderList[i];
            bool        loaded = loader.Update();
            if (loaded)
            {
                SceneDefine.SCENE_ID id         = loader.SceneID;
                UnityScene           unityScene = UnitySceneManager.GetSceneByName(loader.Name);
                SceneBase            scene      = GameObject.Find(unityScene.name).GetComponent <SceneBase>();
                sceneList.Add(scene);

                sceneLoaderList.RemoveAt(i);

                UnitySceneManager.SetActiveScene(unityScene);
                scene.Setup(id, unityScene);
                break;
            }
        }

        for (int i = 0; i < sceneList.Count; i++)
        {
            // アンロード処理
            if (sceneList[i] == null)
            {
                sceneList.RemoveAt(i);
                break;
            }
        }
    }
Esempio n. 4
0
        IEnumerator DoAddScene()
        {
            while (mScenesToAdd.Count > 0)
            {
                //wait for scene removes to finish
                while (mSceneRemoveRout != null)
                {
                    yield return(null);
                }

                var sceneName = mScenesToAdd.Dequeue();

                var sync = UnitySceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);

                while (!sync.isDone)
                {
                    yield return(null);
                }

                var sceneAdded = UnitySceneManager.GetSceneByName(sceneName);
                mScenesAdded.Add(sceneAdded);

                if (sceneAddedCallback != null)
                {
                    sceneAddedCallback(sceneAdded);
                }
            }

            mSceneAddRout = null;
        }
        public static void LoadSceneByName(String name, bool force = false)
        {
            Scene scene = SCM.GetSceneByName(name);

            if (force)
            {
                if (!scene.isLoaded)
                {
                    SCM.LoadScene(name);
                }
                else
                {
                    SCM.LoadScene(scene.name);
                }
            }
            else
            if (!scene.isLoaded)
            {
                SCM.LoadSceneAsync(name);
            }
            else
            {
                SCM.LoadSceneAsync(scene.name);
            }
        }
        public static void PatchScene(string sceneName)
        {
            Scene scene = USceneManager.GetSceneByName(sceneName);

            switch (scene.name)
            {
            case "Crossroads_11_alt":
            case "Crossroads_ShamanTemple":
            case "Fungus1_28":
                new[] { "Blocker", "Blocker 1", "Blocker 2" }
                .Select(str => scene.FindGameObject(str))
                .Where(obj => obj != null)
                .ToList()
                .ForEach(PatchBlocker);
                break;

            case "Crossroads_38":
                PatchGrubFather(scene.FindGameObject("Grub King").LocateMyFSM("King Control"));
                break;

            case "Ruins1_05b":
                PatchLemm(scene.FindGameObject("Relic Dealer"));
                break;
            }
        }
Esempio n. 7
0
    IEnumerator LoadSceneGame(int weight)
    {
        Scene scene = SceneManager.GetSceneByName("Game");

        if (scene.isLoaded)
        {
            _asyncOperation = SceneManager.UnloadSceneAsync(scene);
            while (!_asyncOperation.isDone)
            {
                yield return(0);
            }
        }

        _asyncOperation = SceneManager.LoadSceneAsync("Game", LoadSceneMode.Additive);
        _asyncOperation.allowSceneActivation = false;
        yield return(0);

        float progress = 0;

        while (!_asyncOperation.isDone)
        {
            progress = _asyncOperation.progress < 0.9f ? _asyncOperation.progress : 1;

            yield return(progress * weight);

            if (progress >= 0.9f)
            {
                _asyncOperation.allowSceneActivation = true;
            }
        }
    }
Esempio n. 8
0
        public static async Task UnloadSceneAsycn(string sceneName)
        {
            TaskCompletionSource <bool> taskCompletionSource = new TaskCompletionSource <bool>();

            AsyncOperation asyncOperation = USceneManager.UnloadSceneAsync(sceneName);

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

            await taskCompletionSource.Task;

            FLog.Info(CLASS_TYPE.Name, $"Scene `{USceneManager.GetSceneByName(sceneName).name}` has been unloaded.");
        }
Esempio n. 9
0
        private async UniTask Load(string sceneName, Action <DiContainer> extraBindings)
        {
            var currentScene = UnitySceneManager.GetActiveScene();

            await LoadAdditive(sceneName, extraBindings);

            var nextScene = UnitySceneManager.GetSceneByName(sceneName);

            UnitySceneManager.SetActiveScene(nextScene);

            await UnitySceneManager.UnloadSceneAsync(currentScene);
        }
Esempio n. 10
0
        private void ResetScene(Scene arg0, LoadSceneMode arg1)
        {
            _inBattle = false;

            for (int i = 0; i < _lords.Length; i++)
            {
                _lords[i] = null;
            }


            if (arg0.name is "GG_Mantis_Lords" or "GG_Mantis_Lords_V")
            {
                if (BossSequenceController.IsInSequence && !Config.AllowInPantheons)
                {
                    return;
                }

                _inBattle = true;
                StartCoroutine(AddComponents());
            }

            if (arg0.name != "Fungus2_15_boss" || !PlayerData.instance.defeatedMantisLords)
            {
                return;
            }

            _inBattle = true;
            StartCoroutine(AddComponents());

            // Set the mapZone to White Palace so when you die
            // you don't spawn a shade and don't lose geo
            GameManager.instance.sm.mapZone = MapZone.WHITE_PALACE;

            GameObject[] floors =
            {
                GameObject.Find("Mantis Battle/mantis_lord_opening_floors"),
                GameObject.Find("Mantis Battle/mantis_lord_opening_floors (1)")
            };

            GameObject[] roots = USceneManager.GetSceneByName("Fungus2_15").GetRootGameObjects();

            if (MantisGods.Instance.Settings.NormalArena)
            {
                TransformArena(roots, floors);
            }
            else
            {
                CreateArena(roots, floors);
            }
        }
        private static SceneContext FindSceneContext(string sceneName)
        {
            var scene = UnitySceneManager.GetSceneByName(sceneName);

            foreach (var rootObject in scene.GetRootGameObjects())
            {
                var context = rootObject.GetComponent <SceneContext>();
                if (context != null)
                {
                    return(context);
                }
            }
            return(null);
        }
Esempio n. 12
0
        private void OnLoadSceneSuccess(object sender, GameFramework.Scene.LoadSceneSuccessEventArgs e)
        {
            m_MainCamera = Camera.main;
            if (SceneManager.GetActiveScene() == m_GameFrameworkScene)
            {
                Scene scene = SceneManager.GetSceneByName(GetSceneName(e.SceneAssetName));
                if (!scene.IsValid())
                {
                    Log.Error("Loaded scene '{0}' is invalid.", e.SceneAssetName);
                    return;
                }

                SceneManager.SetActiveScene(scene);
            }

            m_EventComponent.Fire(this, LoadSceneSuccessEventArgs.Create(e));
        }
Esempio n. 13
0
    /// <summary>
    /// 更新
    /// </summary>
    public bool Update()
    {
        if (async)
        {
            if (!asyncOperation.isDone)
            {
                return(false);
            }
        }

        UnityScene scene = UnitySceneManager.GetSceneByName(Name);

        if (scene.isLoaded)
        {
            return(true);
        }

        return(false);
    }
        //加载场景成功的回调
        private void OnLoadSceneSuccess(object sender, GameFramework.Scene.LoadSceneSuccessEventArgs e)
        {
            m_MainCamera = Camera.main;                                                    //获取主相机
            if (SceneManager.GetActiveScene() == m_GFScene)                                //如果当前是框架所在场景
            {
                Scene scene = SceneManager.GetSceneByName(GetSceneName(e.SceneAssetName)); //获取加载成功的场景
                if (!scene.IsValid())                                                      //加载的场景不合法
                {
                    Log.Error("[SceneComponent.OnLoadSceneSuccess] Loaded scene '{0}' is invalid.", e.SceneAssetName);
                    return;
                }

                SceneManager.SetActiveScene(scene); //激活场景
            }

            if (m_EnableLoadSceneSuccessEvent)
            {
                m_EventComponent.Fire(this, ReferencePool.Acquire <LoadSceneSuccessEventArgs>().Fill(e));
            }
        }
Esempio n. 15
0
        private void OnLoadSceneSuccess(object sender, GameFramework.Scene.LoadSceneSuccessEventArgs e)
        {
            m_MainCamera = Camera.main;
            if (SceneManager.GetActiveScene() == m_GameFrameworkScene)
            {
                Scene scene = SceneManager.GetSceneByName(GetSceneName(e.SceneAssetName));
                if (!scene.IsValid())
                {
                    Log.Error("Loaded scene '{0}' is invalid.", e.SceneAssetName);
                    return;
                }

                SceneManager.SetActiveScene(scene);
            }

            if (m_EnableLoadSceneSuccessEvent)
            {
                _eventComponent.Fire(this, ReferencePool.Acquire <LoadSceneSuccessEventArgs>().Fill(e));
            }
        }
Esempio n. 16
0
        IEnumerator DoLoadScene(string toScene, LoadSceneMode mode, bool unloadCurrent)
        {
            isLoading = true;

            //make sure the scene is not paused
            Resume();

            //play out transitions
            for (int i = 0; i < mTransitions.Count; i++)
            {
                yield return(mTransitions[i].Out());
            }

            //scene is about to change
            if (sceneChangeCallback != null)
            {
                sceneChangeCallback(toScene);
            }

            bool doLoad = true;

            if (mode == LoadSceneMode.Additive)
            {
                //Debug.Log("unload: "+mCurScene);
                if (unloadCurrent && mCurScene != mRootScene)
                {
                    UnitySceneManager.UnloadScene(mCurScene);

                    //unload added scenes
                    UnloadAddedScenes();
                }

                //load only if it doesn't exist
                doLoad = !UnitySceneManager.GetSceneByName(toScene).IsValid();
            }
            else
            {
                //single mode removes all other scenes
                ClearAddSceneData();
            }

            //load
            if (doLoad)
            {
                var sync = UnitySceneManager.LoadSceneAsync(toScene, mode);

                while (!sync.isDone)
                {
                    yield return(null);
                }
            }
            else
            {
                yield return(null);
            }

            mCurScene = UnitySceneManager.GetSceneByName(toScene);
            UnitySceneManager.SetActiveScene(mCurScene);

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

            //play in transitions
            for (int i = 0; i < mTransitions.Count; i++)
            {
                yield return(mTransitions[i].In());
            }

            isLoading = false;
        }
Esempio n. 17
0
        private void Reset(Scene arg0, LoadSceneMode arg1)
        {
            Log("Reset scene: " + arg0.name);

            if (PlayerData.instance.defeatedMantisLords)
            {
                PlayerData.instance.defeatedMantisLords = false;
            }

            if (arg0.name != "Fungus2_15_boss")
            {
                return;
            }

            GameManager.instance.sm.mapZone = GlobalEnums.MapZone.WHITE_PALACE;
            //foreach (GameObject go in GetObjectsFromScene("Fungus2_15"))
            foreach (GameObject go in USceneManager.GetSceneByName("Fungus2_15").GetRootGameObjects())
            {
                // if (go.name != "Deep Spikes")
                Destroy(go);
            }

            SceneParticlesController spc = FindObjectOfType <SceneParticlesController>();

            spc.DisableParticles();


            plane = new GameObject("Plane");

            // make it able to be walked on
            plane.tag   = "HeroWalkable";
            plane.layer = 8;

            // Dimensions
            MeshFilter meshFilter = (MeshFilter)plane.AddComponent(typeof(MeshFilter));

            meshFilter.mesh = CreateMesh(200, 6.03f);
            MeshRenderer renderer = plane.AddComponent <MeshRenderer>();

            renderer.material.shader = Shader.Find("Particles/Additive");

            // Color
            if (rainbowFloor)
            {
                System.Random rand = new System.Random();
                rainbowPos   = rand.Next(0, 767);
                floorColor   = getNextRainbowColor();
                currentDelay = 0;
            }

            // Texture
            Texture2D tex = new Texture2D(1, 1);

            tex.SetPixel(0, 0, floorColor);
            tex.Apply();

            // Renderer
            renderer.material.mainTexture = tex;
            renderer.material.color       = Color.white;

            // Collider
            BoxCollider2D a = plane.AddComponent <BoxCollider2D>();

            a.isTrigger = false;

            plane.SetActive(true);
        }
Esempio n. 18
0
 /// <summary>
 ///     Returns if the scene exists, checking using <paramref name="sceneName" />
 /// </summary>
 public static bool SceneExists(string sceneName) => SM.GetSceneByName(sceneName).IsValid();
Esempio n. 19
0
        IEnumerator DoLoadScene(string toScene, LoadSceneMode mode, bool unloadCurrent)
        {
            isLoading = true;

            //about to change scene
            if (sceneChangeStartCallback != null)
            {
                sceneChangeStartCallback();
            }

            //play out transitions
            for (int i = 0; i < mTransitions.Count; i++)
            {
                yield return(mTransitions[i].Out());
            }

            //wait for scene add to finish
            while (mSceneAddRout != null)
            {
                yield return(null);
            }

            //unload added scenes
            UnloadAddedScenes();

            //wait for scene remove to finish
            while (mSceneRemoveRout != null)
            {
                yield return(null);
            }

            //scene is about to change
            if (sceneChangeCallback != null)
            {
                sceneChangeCallback(toScene);
            }

            bool doLoad = true;

            if (mode == LoadSceneMode.Additive)
            {
                bool isCurSceneRoot = _rootScene == mCurScene;

                //special case if we are loading the same scene we first instantiated, but is not the root
                if (!isCurSceneRoot && mFirstSceneLoaded == mCurScene)
                {
                    mode = LoadSceneMode.Single;
                }
                else
                {
                    //unload current scene if it's not the root
                    //Debug.Log("unload: "+mCurScene);
                    if (unloadCurrent && !isCurSceneRoot)
                    {
                        var sync = UnitySceneManager.UnloadSceneAsync(mCurScene);
                        if (sync != null)
                        {
                            while (!sync.isDone)
                            {
                                yield return(null);
                            }
                        }
                    }

                    //load only if it doesn't exist
                    doLoad = !UnitySceneManager.GetSceneByName(toScene).IsValid();
                }
            }

            //load
            if (doLoad)
            {
                var sync = UnitySceneManager.LoadSceneAsync(toScene, mode);

                //something went wrong
                if (sync == null)
                {
                    isLoading = false;
                    yield break;
                }

                while (!sync.isDone)
                {
                    yield return(null);
                }
            }
            else
            {
                yield return(null);
            }

            mCurScene = UnitySceneManager.GetSceneByName(toScene);
            UnitySceneManager.SetActiveScene(mCurScene);

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

            //play in transitions
            for (int i = 0; i < mTransitions.Count; i++)
            {
                yield return(mTransitions[i].In());
            }

            isLoading = false;

            if (sceneChangeEndCallback != null)
            {
                sceneChangeEndCallback();
            }
        }
        private IEnumerator Preload()
        {
            // Scene, (Mod, object name, object id)
            Dictionary <string, List <(Mod, string, string)> > toPreload = new();

            foreach (Mod mod in Mod.ModList)
            {
                Logger.API.Log("Fetching preloads from mod " + mod.LogName);
                List <(string, string, string)> modPreloads;
                try
                {
                    modPreloads = mod.GetPreloads();
                }
                catch (Exception e)
                {
                    mod.Log("Failed getting preload names\n" + e);
                    continue;
                }

                foreach ((string scene, string obj, string id) in modPreloads)
                {
                    if (scene == null || obj == null || id == null)
                    {
                        Logger.API.Log($"Given null argument in preload ({scene ?? "null"}, {obj ?? "null"}, {id ?? "null"}), skipping");
                    }

                    if (!toPreload.TryGetValue(scene, out List <(Mod, string, string)> scenePreloads))
                    {
                        scenePreloads    = new();
                        toPreload[scene] = scenePreloads;
                    }

                    scenePreloads.Add((mod, obj, id));
                }
            }

            progressIndicator.gameObject.SetActive(true);
            progressIndicator.minValue = 0;
            progressIndicator.maxValue = toPreload.Count + 1;

            int preloadIdx = 0;

            foreach (string sceneName in toPreload.Keys)
            {
                Logger.API.Log("Preloading objects in scene " + sceneName);

                AsyncOperation loadop = USceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
                while (!loadop.isDone)
                {
                    progressIndicator.value = preloadIdx + loadop.progress / .9f;
                    yield return(null);
                }

                Scene        scene       = USceneManager.GetSceneByName(sceneName);
                GameObject[] rootObjects = scene.GetRootGameObjects();

                foreach ((Mod mod, string objPath, string objId) in toPreload[sceneName])
                {
                    string rootName;
                    string childName;
                    if (objPath.Contains('/'))
                    {
                        int slash = objPath.IndexOf('/');
                        if (slash == 0 || slash == objPath.Length - 1)
                        {
                            Logger.API.Log($"Malformatted object path '{objPath}' given by mod {mod.LogName}, skipping");
                            continue;
                        }

                        rootName  = objPath.Substring(0, slash);
                        childName = objPath.Substring(slash + 1);
                    }
                    else
                    {
                        rootName  = objPath;
                        childName = null;
                    }

                    GameObject obj = rootObjects.FirstOrDefault(o => o.name == rootName);
                    if (childName != null && obj != null)
                    {
                        Transform transform = obj.transform.Find(childName);
                        if (transform != null)
                        {
                            obj = transform.gameObject;
                        }
                    }

                    if (obj == null)
                    {
                        Logger.API.Log($"Couldn't find object with path '{objPath}' requested by mod {mod.LogName}");
                        continue;
                    }

                    obj = Instantiate(obj);
                    DontDestroyOnLoad(obj);
                    obj.SetActive(false);

                    try
                    {
                        mod.SetPreload(objId, obj);
                    }
                    catch (Exception e)
                    {
                        mod.Log($"Failed setting preloaded object '{objId}'\n{e}");
                        continue;
                    }

                    Logger.API.Log($"Successfully preloaded object '{objId}' for mod {mod.LogName}");
                }

                USceneManager.UnloadScene(scene);
                preloadIdx++;
            }

            AsyncOperation menuLoadop = USceneManager.LoadSceneAsync(Constants.MENU_SCENE);

            while (!menuLoadop.isDone)
            {
                progressIndicator.value = preloadIdx + menuLoadop.progress / .9f;
                yield return(null);
            }
        }
        public static void LoadServerScene(byte fromClient, Packet packet)
        {
            string sceneName = packet.ReadString();

            GameManager.instance.StartCoroutine(LoadSceneRoutine());

            IEnumerator LoadSceneRoutine()
            {
                Scene scene = USceneManager.GetSceneByName(sceneName);

                if (!scene.isLoaded)
                {
                    AsyncOperation operation = USceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);

                    yield return(new WaitWhile(() => !operation.isDone));
                }

                Scene loadedScene = USceneManager.GetSceneByName(sceneName);

                GameObject[] rootGOs = loadedScene.GetRootGameObjects();
                if (rootGOs != null)
                {
                    List <GameObject> enemies = new List <GameObject>();
                    foreach (GameObject rootGO in rootGOs)
                    {
                        List <GameObject> childEnemies = rootGO.FindChildEnemies();

                        foreach (GameObject enemy in childEnemies)
                        {
                            enemies.Add(enemy);
                        }
                    }

                    foreach (GameObject enemy in enemies)
                    {
                        var tracker = enemy.GetComponent <EnemyTracker>();
                        if (tracker)
                        {
                            tracker.playerIds.Add(fromClient);
                        }
                        else
                        {
                            tracker = enemy.AddComponent <EnemyTracker>();
                            ServerSend.SyncEnemy(fromClient, enemy.name, tracker.enemyId);
                            tracker.playerIds.Add(fromClient);
                        }

                        bool foundUnusedKey = false;
                        for (int i = 0; i <= Server.Enemies.Count; i++)
                        {
                            if (!Server.Enemies.Keys.Contains(i))
                            {
                                tracker.enemyId = i;
                                Server.Enemies.Add(i, tracker);
                                foundUnusedKey = true;
                                break;
                            }
                        }

                        if (!foundUnusedKey)
                        {
                            for (int i = Server.Enemies.Count + 1; i <= 99999; i++)
                            {
                                if (!Server.Enemies.Keys.Contains(i))
                                {
                                    tracker.enemyId = i;
                                    Server.Enemies.Add(i, tracker);
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }