Exemple #1
0
 private void WaitBattleStart()
 {
     if (!_luaReflect)
     {
         rootGameObjects = SceneManager.GetActiveScene().GetRootGameObjects();
         foreach (var obj in rootGameObjects)
         {
             if (obj.name.ToLowerInvariant().IndexOf("avatarroot", StringComparison.Ordinal) != -1)
             {
                 _luaReflect = obj.GetComponent <LuaReflect>();
                 break;
             }
         }
     }
     if (_luaReflect)
     {
         LoadLuaReflects();
     }
 }
        private IEnumerator RunLoad <T>(string scenePath, object bundle, string transition = TransitionFactory.FadeTransition) where T : IScene
        {
            if (IsLoading)
            {
                Debug.LogWarning("Scenes is loading, do not load again");
                yield break;
            }

            isLoading = true;
            var lst = curScene;

            if (lst != null)
            {
                //VRProfiler.StartWatch(string.Format("[LoadingScene] Scene: {0} UnLoad ", lst.Name));
                Events.DispathMsg(Event_OnUnload, lst.Name);
                lst.Unload();
                //VRProfiler.StopWatch();
            }

            //VRProfiler.StartWatch("[LoadingScene] Transition In ");
            curScene = null;
            if (null == mask)
            {
                mask = TransitionFactory.CreateTransition(transition);
            }
            mask.DontDestroyOnLoad();
            SetRaycast(false);
            yield return(mask.TransitIn(TransitionLength));

            //VRProfiler.StopWatch();


            //VRProfiler.StartWatch("[LoadingScene] Switch To Scene: Loading ");
            //销毁场景物件
            if (lst != null)
            {
                Destroy(lst.UnityObject);
            }
            //切换至空场景
            UnitySceneMgr.LoadScene(VRScene.Loading);
            //VRProfiler.StopWatch();

            //VRProfiler.StartWatch("[LoadingScene] Unload Unused Assets ");
            //资源回收
            yield return(1);

            yield return(Resources.UnloadUnusedAssets());

            GC.Collect();
            //VRProfiler.StopWatch();

            //VRProfiler.StartWatch(string.Format("[LoadingScene] Switch to Scene:{0} ",scenePath));
            //切换下一场景
            yield return(UnitySceneMgr.LoadSceneAsync(scenePath));

            SetRaycast(true);


            //场景handler
            curScene                 = GetMissingSceneObj <T>();
            curScene.Name            = scenePath;
            curScene.gameObject.name = curScene.GetType().Name;
            //配置场景相关内容
            curScene.name = "[scene] " + curScene.Name;
            // VRProfiler.StopWatch();
            //场景加载完成
            isLoading = false;
            //VRProfiler.StartWatch(string.Format("[LoadingScene] Scene: {0} Preload ", curScene.Name));
            curScene.Preload(bundle);
            //VRProfiler.StopWatch();



            //等待场景
            //VRProfiler.StartWatch(string.Format("[LoadingScene] Scene: {0} Wait ", curScene.Name));
            yield return(curScene.Wait());

            // VRProfiler.StopWatch();

            //VRProfiler.StartWatch(string.Format("[LoadingScene] Scene: {0} Loaded ", curScene.Name));
            curScene.Loaded();
            Events.DispathMsg(Event_OnLoaded, curScene.Name);
            //VRProfiler.StopWatch();

            //VRProfiler.StartWatch("[LoadingScene] Transition Out ");
            //黑幕打开
            if (null != mask)
            {
                yield return(mask.TransitOut(TransitionLength));

                mask.DestroySelf();
                mask = null;
            }
            //VRProfiler.StopWatch();

            yield return(1);

            //加载完成
            curScene.Opened();
        }
Exemple #3
0
        public void LoadScene(string sceneName)
        {
            Player       player       = GameSingleton.Instance.GetPlayer();
            SoundManager soundManager = GameSingleton.Instance.soundManager;

            PoolManager.PoolManager.Instance().ReleaseAll();

            switch (sceneName)
            {
            case "Menu":
                //soundManager.StopPlaying("Level theme");
                soundManager.StopPlayingAllMusics();
                soundManager.Play("Menu");

                if (player.gamemode != Player.Gamemode.LEVEL)
                {
                    player.arcadeModeInventory.Clear();
                    Shop.Instance.ClearShop();
                    player.arcadeGold         = 150;
                    player.currentLevelArcade = 0;
                }
                else
                {
                    player.storyModeInventory = player.inventoryBackup;
                    player.gold = player.goldStartLevel;
                    //player.storyModeInventory.Clear();
                }

                player.gamemode = Player.Gamemode.NONE;
                UnitySceneManager.LoadScene(_storedScenesIds[sceneName]);
                break;

            case "StoryMode":
                if (player.gamemode == Player.Gamemode.LEVEL)          // button restart
                {
                    player.storyModeInventory = player.inventoryBackup;
                    player.gold = player.goldStartLevel;
                }
                Shop.Instance.ClearShop();

                player.gamemode = Player.Gamemode.LEVEL;

                soundManager.StopPlayingAllMusics();

                //soundManager.StopPlaying("Menu");
                soundManager.Play("Level theme");
                UnitySceneManager.LoadScene(_storedScenesIds[sceneName]);
                break;

            case "freeMode":
                string token = player.token;

                if (string.IsNullOrEmpty(token) || token.Length < 8)
                {
                    Popups.instance.Popup(Traducer.Translate("Not connected!"), Color.red);
                }
                else
                {
                    GameSingleton.Instance.tokenManager.CheckToken(token, "scene.load.freeMode");
                    Shop.Instance.ClearShop();

                    player.currentLevelArcade = 0;
                    player.arcadeModeInventory.Clear();
                    player.arcadeGold = 150;

                    player.gamemode = Player.Gamemode.ARCADE;

                    soundManager.StopPlayingAllMusics();
                    soundManager.Play("Level theme");
                    UnitySceneManager.LoadScene(_storedScenesIds[sceneName]);
                }
                break;

            case "loadLvl":
                GameSingleton.Instance.GetPlayer().gamemode = Player.Gamemode.PERSONNALIZED;
                player.arcadeModeInventory.Clear();
                player.arcadeGold = 150;
                UnitySceneManager.LoadScene(_storedScenesIds[sceneName]);
                break;

            case "creator":
                UnitySceneManager.LoadScene(_storedScenesIds[sceneName]);
                break;
            }
        }
Exemple #4
0
 // private void Awake() => DontDestroyOnLoad(this);
 public void ChangeScene(int _sceneID) => SceneManager.LoadScene(_sceneID);
Exemple #5
0
 public void LoadGameLevel()
 {
     USceneManager.LoadScene(_levelScene.SceneName);
 }
Exemple #6
0
 private void LoginSuccess()
 {
     SceneManager.LoadScene("TokenRegistration");
 }
Exemple #7
0
 public static void LoadSceneInstant(string sceneName)
 {
     USM.LoadScene(sceneName);
 }
 public void LoadScene(int sceneIndex)
 {
     SceneLoader.LoadSceneAsync(sceneIndex);
 }
        public SceneManager()
        {
            var        subscriber       = new Subscriber();
            var        currentSceneName = "";
            GameObject loading          = null;

            // Scene Loaded
            subscriber.Subscribe(EventTopics.SceneAwake, () => currentSceneName = SceneManagement.GetActiveScene().name);

            // Scene Change
            subscriber.Subscribe <string>(EventTopics.SceneChange, (triggerName) =>
            {
                SceneConfig scene = config.Scenes.FirstOrDefault(x => String.Equals(x.Name, currentSceneName, StringComparison.InvariantCultureIgnoreCase));
                if (scene == null)
                {
                    throw new Exception($"{this} no configuration for the current scene: {currentSceneName}");
                }

                SceneNext next = scene.LinkTo.FirstOrDefault(x => String.Equals(x.TriggerName, triggerName, StringComparison.InvariantCultureIgnoreCase));
                if (next == null)
                {
                    throw new Exception($"{this} no configuration for this trigger scene: {currentSceneName}, trigger: {triggerName}");
                }

                SceneConfig nextConfig = config.Scenes.FirstOrDefault(x => String.Equals(x.Name, next.SceneName.Name, StringComparison.InvariantCultureIgnoreCase));
                if (nextConfig == null)
                {
                    throw new Exception($"{this} no configuration for this scene: {next.SceneName.Name}");
                }

                if (nextConfig.Async)
                {
                    SceneManagement.LoadSceneAsync(next.SceneName.Name, UnityEngine.SceneManagement.LoadSceneMode.Single);
                }
                else
                {
                    SceneManagement.LoadScene(next.SceneName.Name);
                }
            });

            // Scene Loading
            subscriber.Subscribe(EventTopics.SceneLoading, () =>
            {
                loading = Object.Instantiate(config.LoadingPrefab);
                loading.GetComponent <CanvasGroup>().alpha = 1;
            });

            subscriber.Subscribe(EventTopics.SceneLoaded, () =>
            {
                loading.GetComponent <CanvasGroup>().alpha = 0;
                Object.Destroy(loading);
                loading = null;
            });

            // Additive Scene
            subscriber.Subscribe <string>(EventTopics.SceneLoadAdditive, (name) =>
            {
                SceneConfig scene = config.Scenes.FirstOrDefault(x => x.Name.ToLowerInvariant() == currentSceneName.ToLowerInvariant());
                if (scene == null)
                {
                    throw new Exception($"{this} no configuration for the current scene: {currentSceneName}");
                }

                SceneAdditiveConfig additive = scene.Additives.FirstOrDefault(x => x.Name.ToLowerInvariant() == name.ToLowerInvariant());
                if (additive == null)
                {
                    throw new Exception($"{this} no configuration for this additive scene: {currentSceneName}, additive: {name}");
                }

                currentScene.StartCoroutine(LoadAdditiveScene(additive.Name));
            });

            subscriber.Subscribe <string>(EventTopics.SceneLoadAdditiveAwake, (name) =>
            {
                // if the additive scene is opened directly
                if (currentScene == null)
                {
                    return;
                }

                SceneConfig scene = config.Scenes.FirstOrDefault(x => x.Name.ToLowerInvariant() == currentSceneName.ToLowerInvariant());
                if (scene == null)
                {
                    throw new Exception($"{this} no configuration for the current scene: {currentSceneName}");
                }

                SceneAdditiveConfig additive = scene.Additives.FirstOrDefault(x => x.Name.ToLowerInvariant() == name.ToLowerInvariant());
                if (additive == null)
                {
                    throw new Exception($"{this} no configuration for this additive scene: {currentSceneName}, additive: {name}");
                }

                if (additive.ActiveOnLoad)
                {
                    SceneManagement.SetActiveScene(SceneManagement.GetSceneByName(additive.Name));
                }
            });
        }
Exemple #10
0
 IObservable <AsyncOperation> UnloadSceneInternal(Scene scene)
 {
     return(UnitySceneManager.UnloadSceneAsync(scene.sceneName).AsAsyncOperationObservable());
 }
        public IEnumerator UnloadCurrSceneAsync()
        {
            yield return(SceneManager.LoadSceneAsync(EMPTY_SCENE_NAME));

            UnloadCurrSceneModule();
        }
 public void UnloadCurrScene()
 {
     SceneManager.LoadScene(EMPTY_SCENE_NAME);
     UnloadCurrSceneModule();
 }
 public void SplashFinishedSceneChange()
 {
     SceneManager.LoadScene(nextScene);
 }
Exemple #14
0
 IEnumerator LoadChangeScene()
 {
     yield return(UnitySceneManager.LoadSceneAsync(_name));
 }
Exemple #15
0
        private static void EditRandomizedItems(string scene)
        {
            Dictionary <GameObject, List <string> > shopItems = new Dictionary <GameObject, List <string> >();

            foreach (KeyValuePair <string, string> pair in RandomizerMod.Instance.ItemPlacements)
            {
                string itemId = pair.Key.Substring(0, pair.Key.IndexOf('.'));
                string locId  = pair.Value;

                Item     item = RandoResources.Items.FirstOrDefault(i => i.Id == itemId);
                Location loc  = RandoResources.Locations.FirstOrDefault(l => l.Id == locId)
                                ?? RandoResources.Shops.FirstOrDefault(s => s.Id == locId);

                if (item == null)
                {
                    RandomizerMod.Instance.Log("Failed to find item " + itemId + " in resources, skipping");
                    continue;
                }

                if (loc == null)
                {
                    RandomizerMod.Instance.Log("Failed to find location " + locId + " in resources, skipping");
                    continue;
                }

                if (loc.Scene != scene)
                {
                    continue;
                }

                loc.SceneLoaded();

                PlayMakerFSM fsm;
                if (loc is ObjectLocation objLoc)
                {
                    GameObject obj = USceneManager.GetSceneByName(scene).FindGameObject(objLoc.MainObject);
                    if (obj.name == "Shop Menu")
                    {
                        if (!shopItems.TryGetValue(obj, out List <string> objShopItems))
                        {
                            objShopItems   = new List <string>();
                            shopItems[obj] = objShopItems;
                        }

                        objShopItems.Add(pair.Key);
                        continue;
                    }

                    fsm = ShinyUtil.GetShiny(obj);
                }
                else if (loc is NewLocation newLoc)
                {
                    fsm = ShinyUtil.CreateNewShiny(newLoc.X, newLoc.Y);
                }
                else
                {
                    continue;
                }

                // Begin patching shiny item fsm from vanilla -> rando
                ShinyUtil.CancelFling(fsm);
                ShinyUtil.SetLocationId(fsm, locId);
                fsm.ForceTransitions("Charm?", "Trink Flash", "Store Key");

                // Replace giving the store key with giving our new item
                FsmState giveTrinket = fsm.GetState("Store Key");
                giveTrinket.RemoveActionsOfType <SetPlayerDataBool>();
                giveTrinket.AddFirstAction(new CollectItem(loc, item));

                // Set the sprite/text on the popup to make it obvious if the above fails
                giveTrinket.GetActionOfType <GetLanguageString>().convName     = "IT BROKE";
                giveTrinket.GetActionOfType <SetSpriteRendererSprite>().sprite = Sprites.Get("NullTex");

                // Add dialogue box if necessary
                YNDialogue.AddToShiny(fsm, loc, item);
            }

            // Shop items
            foreach (KeyValuePair <GameObject, List <string> > pair in shopItems)
            {
                ShopModifier.SetShopItems(pair.Key, pair.Value.ToArray());
            }
        }
Exemple #16
0
        private static IEnumerator LoadStateCoro()
        {
            if (_savedPd == null || string.IsNullOrEmpty(_saveScene))
            {
                yield break;
            }

            GameManager.instance.entryGateName      = "dreamGate";
            GameManager.instance.startedOnThisScene = true;

            USceneManager.LoadScene("Room_Sly_Storeroom");

            yield return(new WaitUntil(() => USceneManager.GetActiveScene().name == "Room_Sly_Storeroom"));

            GameManager.instance.sceneData = SceneData.instance = JsonUtility.FromJson <SceneData>(JsonUtility.ToJson(_savedSd));
            GameManager.instance.ResetSemiPersistentItems();

            yield return(null);

            PlayerData.instance = GameManager.instance.playerData = HeroController.instance.playerData = JsonUtility.FromJson <PlayerData>(JsonUtility.ToJson(_savedPd));

            GameManager.instance.BeginSceneTransition
            (
                new GameManager.SceneLoadInfo
            {
                SceneName          = _saveScene,
                HeroLeaveDirection = GatePosition.unknown,
                EntryGateName      = "dreamGate",
                EntryDelay         = 0f,
                WaitForSceneTransitionCameraFade = false,
                Visualization            = 0,
                AlwaysUnloadUnusedAssets = true
            }
            );

            ReflectionHelper.SetAttr(GameManager.instance.cameraCtrl, "isGameplayScene", true);

            GameManager.instance.cameraCtrl.PositionToHero(false);

            if (_lockArea != null)
            {
                GameManager.instance.cameraCtrl.LockToArea(_lockArea as CameraLockArea);
            }

            yield return(new WaitUntil(() => USceneManager.GetActiveScene().name == _saveScene));

            GameManager.instance.cameraCtrl.FadeSceneIn();

            HeroController.instance.TakeMP(1);
            HeroController.instance.AddMPChargeSpa(1);
            HeroController.instance.TakeHealth(1);
            HeroController.instance.AddHealth(1);

            HeroController.instance.geoCounter.geoTextMesh.text = _savedPd.geo.ToString();

            GameCameras.instance.hudCanvas.gameObject.SetActive(true);

            cameraGameplayScene.SetValue(GameManager.instance.cameraCtrl, true);

            yield return(null);

            HeroController.instance.gameObject.transform.position = _savePos;
            HeroController.instance.transitionState = HeroTransitionState.WAITING_TO_TRANSITION;

            typeof(HeroController)
            .GetMethod("FinishedEnteringScene", BindingFlags.NonPublic | BindingFlags.Instance)?
            .Invoke(HeroController.instance, new object[] { true, false });
        }
Exemple #17
0
 public void OnSwitchScene()
 {
     SceneManager.LoadScene(sceneName);
 }