Example #1
0
    // Start is called before the first frame update
    void Start()
    {
        foreach (Button b in gameButtons)
        {
            PlayerSave ps = SaveLoadHandler.LoadGame(gameButtons.IndexOf(b));
            if (ps != null)
            {
                b.interactable = true;
                b.GetComponentInChildren <Text>().text = "Start Game " + ps.saveIndex;

                playerSaves.Add(ps);
                //get button from serialized list
                //hide button
                //Add to list
                //Set text to be save data ex: % time and last save local
            }
            else
            {
                b.GetComponentInChildren <Text>().text = "New Game";
            }
            b.gameObject.SetActive(false);
        }

        if (playerSaves.Count <= 0)
        {
            system.firstSelectedGameObject = newGameButton.gameObject;
            continueButton.gameObject.SetActive(false);
            newGameButton.gameObject.SetActive(true);
        }
        else
        {
            system.firstSelectedGameObject = continueButton.gameObject;
            continueButton.gameObject.SetActive(true);
            newGameButton.gameObject.SetActive(false);
        }
        backButton.gameObject.SetActive(false);

        //if() button list isbigger than max save dont show new game button
        //also for continue, dont show for continue if more than one game
        popUp.SetActive(false);
    }
Example #2
0
    public void Load(int index)
    {
        gameIndex = index;
        if (SceneManager.GetSceneByName(mainMenu).isLoaded)
        {
            SceneManager.UnloadSceneAsync(mainMenu);
        }
        SceneManager.LoadScene(testPauseUI, LoadSceneMode.Additive);
        SceneManager.LoadScene(playerScene, LoadSceneMode.Additive);
        PlayerSave thisSave = SaveLoadHandler.LoadGame(gameIndex);

        if (thisSave == null)
        {
            Debug.Log("Room Not or First Save");
            SceneManager.LoadScene(testLoadScene, LoadSceneMode.Additive);
            occuredEvents    = new List <string>();
            playerStartPos   = Vector2.zero;
            currentMaxHealth = 6;
            keyItemStates    = new List <KeyItemState>();
            foreach (string s in keyItems)
            {
                keyItemStates.Add(new KeyItemState(s, false));
            }
        }
        else
        {
            Debug.Log("Loading at room " + thisSave.lastSavePoint.roomName);

            SceneManager.LoadScene(thisSave.lastSavePoint.roomName, LoadSceneMode.Additive);
            playerStartPos   = thisSave.lastSavePoint.location;
            occuredEvents    = thisSave.eventsTriggered;
            currentMaxHealth = thisSave.currentMaxHealth;
            keyItemStates    = new List <KeyItemState>();
            foreach (KeyItemState s in thisSave.keyItems)
            {
                keyItemStates.Add(s);
            }
        }
    }