Exemplo n.º 1
0
    public void Save()
    {
        SaveGeneralInfo();
        BinaryFormatter bf = new BinaryFormatter();
        FileStream      file;

        if (SceneManager.GetActiveScene().name == "CoalIsland")
        {
            file          = File.Create(Application.persistentDataPath + "/coalIslandInfo.dat");
            firstTimeCoal = false;
        }
        else if (SceneManager.GetActiveScene().name == "GasIsland")
        {
            file = File.Create(Application.persistentDataPath + "/gasIslandInfo.dat");
        }
        else if (SceneManager.GetActiveScene().name == "SolarIsland")
        {
            file = File.Create(Application.persistentDataPath + "/solarIslandInfo.dat");
        }
        else if (SceneManager.GetActiveScene().name == "WindIsland")
        {
            file = File.Create(Application.persistentDataPath + "/windIslandInfo.dat");
        }
        else if (SceneManager.GetActiveScene().buildIndex == 1)
        {
            file = File.Create(Application.persistentDataPath + "/mainIslandInfo.dat");
        }

        else
        {
            Debug.Log("Ni uno ni otro");
            return;
        }

        LevelData data = new LevelData();


        CreateEnvironment ce      = GameObject.Find("GameManager").GetComponent <CreateEnvironment>();
        WeatherController weather = GameObject.Find("GameManager").GetComponent <WeatherController>();
        Player            player  = GameObject.Find("Player").GetComponent <Player>();

        stageSizeX      = ce.GetStageX();
        stageSizeY      = ce.GetStageY();
        data.stageSizeX = stageSizeX;
        data.stageSizeY = stageSizeY;
        gridSizeX       = ce.GetRows();
        gridSizeY       = ce.GetColumns();
        data.gridSizeX  = gridSizeX;
        data.gridSizeY  = gridSizeY;

        data.levelCity = player.levelCity;

        data.sizeXPlane = ce.planeLimit.transform.localScale.x;
        data.sizeYPlane = ce.planeLimit.transform.localScale.z;

        data.energy    = player.totalEnergy;
        data.maxEnergy = (int)player.levelObject.maxValue;

        data.pollution          = player.totalPollution;
        data.maxPollution       = (int)player.pollutionSlider.maxValue;
        data.happiness          = player.totalHappiness;
        data.cantCompletedQuest = player.cantCompletedQuest;
        // data.money = player.totalCurrency;


        //  data.days = weather.fakeDays;
        //  data.hour = weather.fakeHour;
        //  data.minute = weather.fakeMinutes;
        //  data.month = weather.actualMonthNumber;
        //  data.night = weather.isNight;

        Node[,] aux = ce.GetMatrixNode();

        information = new NodeInformation[gridSizeX, gridSizeY];

        for (int f = 1; f < gridSizeX; f++)
        {
            for (int c = 1; c < gridSizeY; c++)
            {
                if (aux[f, c].idBuilding == 0)
                {
                    information[f, c].isUnlock   = false;
                    information[f, c].haveWater  = false;
                    information[f, c].idBuilding = 0;
                    //continue;
                }
                else
                {
                    information[f, c].idBuilding = aux[f, c].idBuilding;
                    information[f, c].isUnlock   = true;
                    information[f, c].haveWater  = false;
                }
            }
        }

        data.information = information;
        // data.money = GameObject.Find("Player").GetComponent<Player>().totalCurrency;

        if (information.Length != 0)
        {
            Debug.Log("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
        }

        bf.Serialize(file, data);
        file.Close();

        Debug.Log("Se ha creado archivo de guardado");
    }
Exemplo n.º 2
0
    public void SaveGasIsland()
    {
        BinaryFormatter bf = new BinaryFormatter();
        FileStream      file;

        file = File.Create(Application.persistentDataPath + "/gasIslandInfo.dat");

        LevelData data = new LevelData();


        CreateEnvironment ce      = GameObject.Find("GameManager").GetComponent <CreateEnvironment>();
        WeatherController weather = GameObject.Find("GameManager").GetComponent <WeatherController>();
        Player            player  = GameObject.Find("Player").GetComponent <Player>();

        stageSizeX      = ce.GetStageX();
        stageSizeY      = ce.GetStageY();
        data.stageSizeX = stageSizeX;
        data.stageSizeY = stageSizeY;
        gridSizeX       = ce.GetRows();
        gridSizeY       = ce.GetColumns();
        data.gridSizeX  = gridSizeX;
        data.gridSizeY  = gridSizeY;

        data.levelCity = player.levelCity;

        data.sizeXPlane = ce.planeLimit.transform.localScale.x;
        data.sizeYPlane = ce.planeLimit.transform.localScale.z;

        data.energy    = player.totalEnergy;
        data.maxEnergy = (int)player.levelObject.maxValue;

        data.pollution    = player.totalPollution;
        data.maxPollution = (int)player.pollutionSlider.maxValue;
        data.happiness    = player.totalHappiness;

        data.cantCompletedQuest = player.cantCompletedQuest;


        Node[,] aux = ce.GetMatrixNode();

        information = new NodeInformation[gridSizeX, gridSizeY];

        for (int f = 1; f < gridSizeX; f++)
        {
            for (int c = 1; c < gridSizeY; c++)
            {
                if (aux[f, c].idBuilding == 0)
                {
                    information[f, c].isUnlock   = false;
                    information[f, c].haveWater  = false;
                    information[f, c].idBuilding = 0;
                    //continue;
                }
                else
                {
                    information[f, c].idBuilding = aux[f, c].idBuilding;
                    information[f, c].isUnlock   = true;
                    information[f, c].haveWater  = false;
                }
            }
        }

        data.information = information;
        // data.money = GameObject.Find("Player").GetComponent<Player>().totalCurrency;

        if (information.Length != 0)
        {
            Debug.Log("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
        }

        bf.Serialize(file, data);
        file.Close();

        Debug.Log("Se ha creado archivo de guardado");
    }