Exemplo n.º 1
0
        protected override void OnTriggerActivate(Collider2D other)
        {
            if (!saved && other.CompareTag("Player"))
            {
                PlayerUpgrades upgrades = other.GetComponent <PlayerUpgrades>();

                if (upgrades)
                {
                    GameData gameData = upgrades.GetDataForSaving();
                    if (gameData != null)
                    {
                        DialogueHandler.instance.StartDialogue(saveDialogue);

                        saved = true;

                        gameData.spawnLocation = this.UniqueID;

                        SaveProfile saveProfile = new SaveProfile(gameData.ProfileName, true);
                        saveProfile.Save(gameData);
                    }
                    else
                    {
                        Debug.LogWarning("SaveStation: " + nameof(GameData) + " is null.");
                    }
                }
                else
                {
                    Debug.LogWarning("SaveStation: Player doesn't have " + nameof(PlayerUpgrades) + " component.");
                }

                Health health = other.GetComponent <Health>();

                if (health)
                {
                    health.Heal(health.MaxHP);
                }
                else
                {
                    Debug.LogWarning("SaveStation: Player doesn't have" + nameof(Health) + " component.");
                }
            }
        }
Exemplo n.º 2
0
        private void CreateGame()
        {
            if (!loadStarted)
            {
                if (string.IsNullOrWhiteSpace(textMesh.text))
                {
                    textMesh.text = "Invalid name";
                    return;
                }

                SaveProfile saveProfile = new SaveProfile(textMesh.text);
                defaultGameData.ProfileName = textMesh.text;
                saveProfile.Save(defaultGameData);

                loadStarted = true;
                SceneLoader loader = new SceneLoader(loadingScene);

                loader.ScenesToUnload.Add(gameObject.scene.name);

                if (isIntroEnabled)
                {
                    loader.ScenesToLoad.Add(introStartScene);
                }
                else
                {
                    loader.ScenesToLoad.Add(playerScene);
                    loader.Destination = defaultGameData.spawnLocation;
                }

                loader.GameData = defaultGameData;

                try
                {
                    loader.FadeScenes();
                }
                catch (InvalidOperationException e)
                {
                    loadStarted = false;
                }
            }
        }