Exemple #1
0
    public void Load(GameManagerInfo _gMI)
    {
        TownHallHP    = _gMI.townHallHP;
        woodAcquired  = _gMI.wood;
        stoneAcquired = _gMI.stone;
        oreAcquired   = _gMI.ore;
        steelAcquired = _gMI.steel;

        gameObject.GetComponent <SpawnerControl>().waveCount = _gMI.waveCount;
    }
Exemple #2
0
    public GameManagerInfo SaveGameManager()
    {
        GameManagerInfo gMI = new GameManagerInfo();

        gMI.townHallHP = TownHallHP;
        gMI.wood       = woodAcquired;
        gMI.stone      = stoneAcquired;
        gMI.ore        = oreAcquired;
        gMI.steel      = steelAcquired;

        gMI.waveCount = gameObject.GetComponent <SpawnerControl>().waveCount;

        return(gMI);
    }
Exemple #3
0
    void Start()
    {
        if (instance == null)
        {
            instance = this;
        }
        else if (instance != this)
        {
            Destroy(gameObject);
        }

        DontDestroyOnLoad(gameObject);

        gameManagerInfo = new GameManagerInfo();
    }
Exemple #4
0
    private void SaveGameManager()
    {
        BinaryFormatter bf   = new BinaryFormatter();
        FileStream      file = File.Open(Application.persistentDataPath + gameSavesDirectoryPath + "/GameManager.cas", FileMode.OpenOrCreate);

        GameManagerInfo myInfo = new GameManagerInfo();

        //put what ever you're saving as myInfo.whatever
        myInfo.townHallHP = gameManagerInfo.townHallHP;
        myInfo.wood       = gameManagerInfo.wood;
        myInfo.stone      = gameManagerInfo.stone;
        myInfo.ore        = gameManagerInfo.ore;
        myInfo.steel      = gameManagerInfo.steel;
        myInfo.waveCount  = gameManagerInfo.waveCount;

        bf.Serialize(file, myInfo);
        file.Close();
    }
Exemple #5
0
    //called from GameManagerScript
    public void SaveGame()
    {
        GameObject townHall_GO = GameObject.Find("TownHallTile(Clone)");

        if (townHall_GO.GetComponent <TownHallScript>().Enemiesleft > 0)
        {
            Debug.Log("SaveLoadGame -- SaveGame: The wave is still in progress!");
            return;
        }
        //If the Directory doesn't exist, then create the folder
        if (!Directory.Exists(Application.persistentDataPath + gameSavesDirectoryPath))
        {
            Directory.CreateDirectory(Application.persistentDataPath + gameSavesDirectoryPath);
        }

        //Ga through and save tiles
        gameTilesInfoList = new List <GameTilesInfo>();

        for (int i = -15; i < 15; i++)
        {
            for (int j = -25; j < 25; j++)
            {
                if (GameObject.Find("Tile(" + j + ", " + i + ")").GetComponent <Tile_Scripts>().baseTile)
                {
                    //add to the list
                    GameObject tile_GO = GameObject.Find("Tile(" + j + ", " + i + ")");
                    if (tile_GO.GetComponent <Tile_Scripts>().buildingID != -1)
                    {
                        Debug.Log(tile_GO);
                        GameTilesInfo gTI = tile_GO.GetComponent <Tile_Scripts>().Save();
                        gameTilesInfoList.Add(gTI);
                    }
                }
            }
        }

        SaveTiles();

        //Save the Game Manager
        gameManagerInfo = GameObject.Find("GameManager").GetComponent <GameManagerScript>().SaveGameManager();

        SaveGameManager();
    }
Exemple #6
0
    //called from GameManagerScript
    public void LoadGameState()
    {
        if (File.Exists(Application.persistentDataPath + gameSavesDirectoryPath + "/GameTiles.cas"))
        {
            BinaryFormatter   bf               = new BinaryFormatter();
            FileStream        file             = File.Open(Application.persistentDataPath + gameSavesDirectoryPath + "/GameTiles.cas", FileMode.Open);
            GameTilesInfoList myLoadedTileInfo = (GameTilesInfoList)bf.Deserialize(file);
            gameTilesInfoList = myLoadedTileInfo.gameTileInfoList;
            file.Close();

            if (File.Exists(Application.persistentDataPath + gameSavesDirectoryPath + "/GameManager.cas"))
            {
                bf   = new BinaryFormatter();
                file = File.Open(Application.persistentDataPath + gameSavesDirectoryPath + "/GameManager.cas", FileMode.Open);
                GameManagerInfo myLoadedGameManagerInfo = (GameManagerInfo)bf.Deserialize(file);

                gameManagerInfo.townHallHP = myLoadedGameManagerInfo.townHallHP;
                gameManagerInfo.wood       = myLoadedGameManagerInfo.wood;
                gameManagerInfo.stone      = myLoadedGameManagerInfo.stone;
                gameManagerInfo.ore        = myLoadedGameManagerInfo.ore;
                gameManagerInfo.steel      = myLoadedGameManagerInfo.steel;

                SetLoadedTiles();

                GameObject.Find("GameManager").GetComponent <GameManagerScript>().Load(gameManagerInfo);
                file.Close();
            }
            else
            {
                Debug.LogError("SaveLoadGame -- LoadGame: Tile were saved but the GameManager file cannot be found!");
            }
        }
        else
        {
            Debug.Log("No saved tiles found");
        }
    }