Exemplo n.º 1
0
 protected override void _StartState(IState oldstate)
 {
     this.gameObject.SetActive(true);
     firstSelected = returnButton;
     for (int i = 2; i >= 0; i--)             // for each potential save:
     {
         if (SaveObj.SaveExists(i + 1))       // if exists, set name and number-unlocked to match info in save, and make button non-interactible
         {
             SaveObj save = SaveObj.LoadGame(i + 1);
             slotNameText[i].text = save.slotName;
             int count = 0;
             for (int j = 0; j < GameManager.numLevels; j++)
             {
                 if (save.canAccess(j))
                 {
                     count++;
                 }
             }
             numUnlockedText[i].text    = count + "/" + GameManager.numLevels;
             slotButton[i].interactable = false;
         }
         else                    // else set text to defualt and set interactible
         {
             slotNameText[i].text       = "-";
             numUnlockedText[i].text    = "~/" + GameManager.numLevels;
             slotButton[i].interactable = true;
             firstSelected = slotButton[i];
         }
     }
     //resetSelected();
 }
Exemplo n.º 2
0
 /// <summary>
 /// update which slots are selectible and the info displayed on them
 /// </summary>
 public void refresh()
 {
     for (int i = 2; i >= 0; i--)             // for each save: (reverse order, so first valid slot is set at selected)
     {
         if (SaveObj.SaveExists(i + 1))       // if exists, set name and number-unlocked to match info in save, and make button interactible
         {
             SaveObj save = SaveObj.LoadGame(i + 1);
             slotNameText[i].text = save.slotName;
             int count = 0;
             for (int j = 0; j < GameManager.numLevels; j++)
             {
                 if (save.canAccess(j))
                 {
                     count++;
                 }
             }
             numUnlockedText[i].text    = count + "/" + GameManager.numLevels;
             slotButton[i].interactable = true;
             firstSelected = slotButton[i]; // set valid slot as selected
         }
         else                               // else set text to defualt and set non-interactible
         {
             slotNameText[i].text       = "-";
             numUnlockedText[i].text    = "~/" + GameManager.numLevels;
             slotButton[i].interactable = false;
         }
     }
 }
Exemplo n.º 3
0
    /// <summary>
    /// set up the dialog and return value on the ConfirmMenu
    /// </summary>
    /// <param name="num"></param>
    public void deleteSlot(int num)
    {
        // ask to confirm delete?
        number = num;
        SaveObj save = SaveObj.LoadGame(num);

        GameManager.confirmMenu.setupDialog(0, "Are you sure you want to delete the save file \"" + save.slotName + "\"", false, true);
    }
Exemplo n.º 4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="num"></param>
 public void loadSlot(int num)
 {
     GameManager.saveGame = SaveObj.LoadGame(num);
     if (GameManager.saveGame == null)               // complain if save file doesn't exist/error
     // give file-doesn't exist notification here
     {
         Debug.Log("Error: Can't find save file \"" + num + "\"");
         return;
     }
     GameManager.settings.saveNum = num;                                                                                // set the last-save-used to this num, and save that change
     SettingsObj.saveSettings(GameManager.settings);
     if (GameManager.saveGame.levelNumber >= 0 && GameManager.saveGame.levelNumber < levelSelector.levelButtons.Length) // load straight to the last visited level if it exists
     {
         LevelSelector.changeLevelHelper(GameManager.saveGame.levelNumber);
         GameManager.changeState(GameManager.gameplay, this);
     }
     else
     {
         onClick(levelSelector);             // else, go to level selector
     }
 }
Exemplo n.º 5
0
    public void Awake()
    {
        #region finding objects/setting refferences
        if ((instance == null) || (instance == this))           // singleton pattern
        {
            instance = this;
        }
        else
        {
            Debug.Log("Duplicate GameManager destroyed");
            DestroyImmediate(this.gameObject);
        }

        IState[] objList = (IState[])Resources.FindObjectsOfTypeAll(typeof(IState));            // find all IState objects
        // should be easily tweakable to work when switching between scenes
        foreach (IState state in objList)
        {
            if (istates[(int)state._stateType] == null)                 // add one of each type to list of istates, delete any duplicates
            {
                istates[(int)state._stateType] = state;                 // the type enum is used to put each istate in a unique nd predictable slot
                state.gameObject.SetActive(false);
            }
            else
            {
                Debug.Log("Destroyed duplicate of IState " + state._stateType);
                DestroyImmediate(state.gameObject);
            }
        }
        for (int i = 0; i < istates.Length; i++)                // check that one of each type exists
        {
            if (istates[i] == null)
            {
                Debug.Log("Error: IState object of type \"" + (IStateType)i + "\" not found");
            }
            else
            {
                istates[i].initialize();                        // initialize each that exists
            }
        }

        ConfirmMenu[] conList = (ConfirmMenu[])Resources.FindObjectsOfTypeAll(typeof(ConfirmMenu));
        if (conList.Length > 0)
        {
            confirmMenu = conList[0];               // only use one copy of the ConfirmMenu object
            confirmMenu.gameObject.SetActive(false);
        }
        else
        {
            Debug.Log("Error: No ConfirmMenu object is exists");
        }
        for (int i = 1; i < conList.Length; i++)
        {
            DestroyImmediate(conList[i].gameObject);                                                // destroy extras
        }
        #endregion

        //settup spritebook & index
        spriteBook  = _spriteBook;                  // move info from non-static variables to static variables
        errorSprite = _errorSprite;
        for (int s = 0; s < spriteBook.Length; s++) // get the index and name of every sprite, so you can look them up by name
        {
            if (spriteBook[s] != null)
            {
                string lowercase = spriteBook[s].name.ToLowerInvariant();
                //Debug.Log(string.Format("Trying to add sprite {0} to sprite index", lowercase));
                if (!spriteIndex.ContainsKey(lowercase))                        // don't add any duplicate names
                {
                    spriteIndex.Add(lowercase, s);
                }
                else
                {
                    throw new System.Exception("Error: sprite with name" + spriteBook[s].name + " present in spritebook more than once");
                }
            }
        }

        // load settings stuff, and apply them.
        if (SettingsObj.settingsExists())               //load the settings if the file exists
        {
            settings = SettingsObj.loadSettings();
        }
        else                    // else create new file
        {
            Debug.Log("Creating new settings file");
            settings = new SettingsObj();
            SettingsObj.saveSettings(settings);
        }
        applySettings(settings);            // apply the saved settings
        // consider changing so that it keeps resolution settings from start-up menu

        // load from save if possible, or load default save.
        if (settings.saveNum >= 1 && settings.saveNum <= 3)             // if saveNum = 1, 2, or 3, savefile should exist, else one won't
        {
            saveGame = SaveObj.LoadGame(settings.saveNum);
            if (saveGame == null)
            {
                Debug.Log("Indicated save does not exist, load an existing save or create a new one.");
                settings.saveNum = 0;
                SettingsObj.saveSettings(settings);
            }
        }


        gameplay = (Gameplay)istates[(int)GameManager.IStateType.gameplay];     // get gameplay IState from istate[Enum.gameplay] slot of array

        if (istates[(int)GameManager.IStateType.gameMenu] != null)              // set current state to gamemenu, or complain if gameMenu istate doesn't exist
        {
            currentstate = istates[(int)GameManager.IStateType.gameMenu];
            currentstate.StartState(null);
            istates[(int)GameManager.IStateType.gameMenu].gameObject.SetActive(true);
        }

        //InputManager.instance.LoadKeybinds();   // load keybindings

        eventSystem = (EventSystem)FindObjectOfType(typeof(EventSystem));
    }