Exemple #1
0
    /**
     * SaveLastSave()
     *  --> overwrite the last GameSave allocated
     * */
    public static void SaveLastSave()
    {
        if(m_MustLoad)
            return;
        Debug.Log("SAVE");
        GameSave gamesave = new GameSave();

        WorldControllerScript worldController = null;
        GameObject worldControllerGo = GameObject.Find("GameWorld");
        if(worldControllerGo != null)
        {
            if((worldController = worldControllerGo.GetComponent<WorldControllerScript>()) != null)
                gamesave.world = worldController.GetCurrentWorldNumber();
        }

        GameObject[] gameObject = (GameObject[])GameObject.FindObjectsOfType(typeof(GameObject));
        int id = 1;
        foreach(GameObject go in gameObject)
        {
            Saveable savecomponent = null;
            if((savecomponent = go.GetComponent<Saveable>()) != null)
            {
                Save save = savecomponent.SaveTo();
                save.m_Id = id;
                gamesave.AddSave(save);
                id++;
            }
        }

        gamesave.level = Application.loadedLevel;
        if(last_save != null)
        {
            gamesave.time = last_save.time;
            gamesave.deathCount = last_save.deathCount;
            gamesave.score = last_save.score;
        }
        if(gamesave == null)
        {
            Debug.Log ("Warning : save fail");
            return;
        }
        last_save = gamesave;
    }