Пример #1
0
        /// <summary>
        /// Occurs when the new game menu option is clicked.
        /// </summary>
        public void NewGame()
        {
            if (CharacterNameTextBox.text.Length > 2)
            {
                ValidationLabel.text = "";
                if (FirstSceneName.Length > 0)
                {
                    // find the leveling system
                    if (!LevelingSystem)
                    {
                        GameObject player = GlobalFuncs.FindPlayerInstance();
                        if (player)
                        {
                            LevelingSystem = player.GetComponent <CharacterBase>();
                        }
                        else
                        {
                            if (GlobalFuncs.DEBUGGING_MESSAGES)
                            {
                                Debug.Log("Unable to find player");
                            }
                        }
                    }
                    if (!LevelingSystem)
                    {  // not found?
                        if (GlobalFuncs.DEBUGGING_MESSAGES)
                        {
                            Debug.Log("Leveling system not found on player");
                        }
                    }
                    else
                    {  // all good
                        // set the leveling system initial values
                        LevelingSystem.CurrentLevel     = 1;
                        LevelingSystem.Name             = CharacterNameTextBox.text;
                        LevelingSystem.CurrentAxis      = (BaseAxis)AxisDropDown.value;
                        LevelingSystem.CurrentAlignment = (BaseAlignment)AlignDropDown.value;
                        LevelingSystem.CurrentRace      = (BaseRace)RaceDropDown.value;
                        LevelingSystem.CurrentClass     = (BaseClass)ClassDropDown.value;
                        LevelingSystem.ResetToDefaults(); // reset character to the selection
                        LevelingSystem.reCalcCore(true);  // recalc the core stats, max out health etc
                        CharacterNameTextBox.text = "";   // clear for mid game create new character

                        // create a new slot and first save game in the data layer
                        LevelingSystem.SaveSlotID     = 0;
                        LevelingSystem.LastSaveGameID = GlobalFuncs.TheDatabase().SavePlayerState(ref LevelingSystem, FirstSceneName, -1);
                        GlobalFuncs.TheDatabase().ClearInventoryAndHUD();

                        // close the menu and load the scene
#if !VANILLA
                        Inventory.gameObject.SetActive(true);
#endif
                        NewCharacterWindow.SetActive(false);
                        Fader.BeginFade(1);
                        isOpen    = false;
                        lockInput = false;
                        Fader.LoadSceneAsync(FirstSceneName);  // start the load with progress bar
                    }
                }
                else
                {
                    if (GlobalFuncs.DEBUGGING_MESSAGES)
                    {
                        Debug.Log("First scene name is not specified");
                    }
                }
            }
            else
            {
                ValidationLabel.text = "Missing Character Name..";
            }
        }
Пример #2
0
        /// <summary>
        /// Save the game and load the next scene when collider trigger entered by the player.
        /// </summary>
        /// <param name="other">Collider that has entered the trigger.</param>
        void OnTriggerEnter(Collider other)
        {
            if (other.gameObject.tag.Equals("Player"))
            {     // only player can trigger
                if (SceneToLoad != "")
                { // fail safe
                    // spawn all
                    if (SpawnOnEnter.Count > 0)
                    {
                        StartCoroutine(GlobalFuncs.SpawnAllDelayed(SpawnOnEnter, SpawnDelay, NoneSequentialSpawns, transform, null, 0, false, SpawnTarget.Any));  // trigger all spawns the the array
                    }

                    // save to data layer
                    LevelingSystem = other.gameObject.GetComponent <CharacterBase>();
                    if (!LevelingSystem)
                    {  // not found?
                        if (GlobalFuncs.DEBUGGING_MESSAGES)
                        {
                            Debug.Log("Leveling system not found on player");
                        }
                    }
                    else
                    {  // all good
                       // save the game
                        LevelingSystem.LastSaveGameID = GlobalFuncs.TheDatabase().SavePlayerState(ref LevelingSystem, SceneToLoad, -1);
                        MainMenu MainMenuSystem = GlobalFuncs.TheMainMenu();
                        if (MainMenuSystem)
                        {
                            MainMenuSystem.LatestSaveGameID = LevelingSystem.LastSaveGameID;

                            // confirm save to user
                            MainMenuSystem.SaveGameMessage.CrossFadeAlpha(1f, 0.01f, true);
                            MainMenuSystem.SaveGameMessage.text = "Save Complete..";
                            MainMenuSystem.SaveGameMessage.CrossFadeAlpha(0f, 3f, true);

                            // load the next scene
                            MainMenu_FadingLoad Fader = MainMenuSystem.gameObject.GetComponent <MainMenu_FadingLoad>();
                            if (Fader)
                            {
                                Fader.BeginFade(1);
                                Fader.LoadSceneAsync(SceneToLoad, LoadDelay);  // start the load with progress bar
                            }
                            else
                            {
                                if (GlobalFuncs.DEBUGGING_MESSAGES)
                                {
                                    Debug.Log("Main menu system NOT found in scene");
                                }
                            }
                        }
                        else
                        {
                            if (GlobalFuncs.DEBUGGING_MESSAGES)
                            {
                                Debug.Log("Main menu system NOT found in scene");
                            }
                        }
                    }
                }
                else
                {
                    if (GlobalFuncs.DEBUGGING_MESSAGES)
                    {
                        Debug.Log("Scene to load is NOT set");
                    }
                }
            }
        }