Beispiel #1
0
        public void CallBtn(int idBtn)
        {
            //GameSingleton.Instance.GetPlayer().Save();
            switch (idBtn)
            {
            case 0:
                GameSingleton.Instance.sceneManager.LoadScene("Menu");
                break;

            case 1:

                Player          player         = GameSingleton.Instance.GetPlayer();
                Player.Gamemode playerGamemode = player.gamemode;


                if (playerGamemode == Player.Gamemode.LEVEL)
                {
                    player.gold = player.goldStartLevel;
                    player.storyModeInventory = player.inventoryBackup;
                }


                Shop.Instance.ClearShop();
                GameSingleton.Instance.uiManager.inventoryUi.UpdateGold();
                SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
                break;
            }

            gameObject.SetActive(false);
        }
 public Lever()
 {
     BoolData = new PersistentBoolData {
         sceneName = USceneManager.GetActiveScene().name,
         id        = name
     };
 }
        private void UpdateSceneNameText()
        {
            if (!sceneNameText)
            {
                return;
            }

            sceneNameText.text = Manager.GetActiveScene().name;
        }
        /// <summary>
        /// Same as GameObject.FindObjectsOfType<T>, but also get inactive objects
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static T[] FindAllOfType <T>() where T : UnityEngine.Object
        {
            if (typeof(T) == typeof(GameObject))
            {
                throw new Exception("Use Transform instead of GameObject when calling GameObjectEx.FindAllOfType<>");
            }

            return(Resources.FindObjectsOfTypeAll <T>()
                   .Where(obj => obj.GameObject().scene == SceneManager.GetActiveScene())
                   .ToArray());
        }
        public void ChangeActiveScene(int buildIndexOffset)
        {
            if (Manager.sceneCountInBuildSettings < 1)
            {
                return;
            }

            int newSceneBuildIndex = Manager.GetActiveScene().buildIndex;

            newSceneBuildIndex += buildIndexOffset;
            newSceneBuildIndex += Manager.sceneCountInBuildSettings << 10;
            newSceneBuildIndex %= Manager.sceneCountInBuildSettings;
            newSceneBuildIndex  = Mathf.Clamp(newSceneBuildIndex, 0, Manager.sceneCountInBuildSettings - 1);

            Manager.LoadScene(newSceneBuildIndex);
            UpdateSceneNameText();
        }
Beispiel #6
0
        private void Setup()
        {
            scene = TCScenesManager.GetActiveScene();
            if (scene == null)
            {
                Logger.Error("The scene '{@Scene}' doesn't have a TCScene assigned to it!",
                             SceneManager.GetActiveScene().name);
                return;
            }

            sceneCamera = GameObject.FindWithTag(SceneCameraTag);
            if (sceneCamera == null)
            {
                Logger.Error(
                    "The scene {@Scene} doesn't have a Camera with the tag `{@SceneCameraTag}` assigned to it!",
                    scene.scene, SceneCameraTag);
            }
        }
        private static IEnumerator LoadStateCoro()
        {
            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);

            HeroController.instance.gameObject.transform.position = _savePos;

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

            On.HeroController.EnterScene += Ok;

            USceneManager.LoadScene(_saveScene);

            yield return(null);

            HeroController.instance.gameObject.transform.position = _savePos;

            yield return(null);

            yield return(null);

            cameraLockArea.SetValue(GameManager.instance.cameraCtrl, _lockArea);
            GameManager.instance.cameraCtrl.LockToArea(_lockArea as CameraLockArea);
            cameraGameplayScene.SetValue(GameManager.instance.cameraCtrl, true);

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

            HeroController.instance.gameObject.transform.position = _savePos;

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

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

            On.HeroController.EnterScene -= Ok;
        }
Beispiel #8
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();
     }
 }
Beispiel #9
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 });
        }
Beispiel #10
0
        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));
                }
            });
        }