Exemplo n.º 1
0
    // Start is called before the first frame update
    void Start()
    {
        SaveData saveData = GameSaver.LoadGame();

        if (saveData != null)
        {
            LoadData(saveData);
        }
        Vector2Int[] resolutions = { new Vector2Int(3840, 2160), new Vector2Int(2560, 1440), new Vector2Int(1920, 1080), new Vector2Int(1280, 720), new Vector2Int(854, 480) };
        resolution = new Vector2Int(Display.main.systemWidth, Display.main.systemHeight);
        Animation.Play("Show");
        int height = Display.main.systemHeight;
        int width  = Display.main.systemWidth;

        foreach (Vector2 res in resolutions)
        {
            if (res.x <= width && res.y <= height)
            {
                dropdown.options.Add(new Dropdown.OptionData(res.x + "×" + res.y));
            }
        }
    }
Exemplo n.º 2
0
 public void LoadGame()
 {
     GameSaver.LoadGame();          //reads save from file into live save
     SceneManager.LoadScene(GameSaver.liveSave.sceneName);
 }
 public void LoadGame()
 {
     gameSaver.LoadGame(this.fileNum);
 }
Exemplo n.º 4
0
    private void CreateWorld()
    {
        //spawn tiles
        Debug.Log(((Screen.height / 32f) - height) / 2f);
        grid   = new GameObject[width, height];
        tile   = Resources.Load("Prefabs/Tile") as GameObject;
        city   = Resources.Load("Prefabs/City") as GameObject;
        forest = Resources.Load("Prefabs/Forest") as GameObject;

        for (int ix = 0; ix < width; ix++)
        {
            for (int iy = 0; iy < height; iy++)
            {
                freeCoordinates.Add(new Vector3(ix, iy, -1));
                float      xLoc        = ix - (width / 2);
                float      yLoc        = iy - (height / 2);
                GameObject spawnedTile = Instantiate(tile, new Vector3(xLoc, yLoc, 100), Quaternion.identity) as GameObject;
                grid[ix, iy] = spawnedTile;

                //give tile coordinate information
                spawnedTile.GetComponent <Tile> ().posX = ix;
                spawnedTile.GetComponent <Tile> ().posY = iy;
            }
        }

        //shuffle coordinates
        for (int i = 0; i < freeCoordinates.Count; i++)
        {
            Vector3 temp        = freeCoordinates[i];
            int     randomIndex = UnityEngine.Random.Range(0, freeCoordinates.Count);
            freeCoordinates[i]           = freeCoordinates[randomIndex];
            freeCoordinates[randomIndex] = temp;
        }

        if (gameSaver.ProfileExists())
        {
            gameSaver.LoadGame();
            //playerCity.GetComponent<City>().FillArmySelectCB();
            playerCity.GetComponent <City> ().FillArmySelectDropdown();
        }
        else //create a whoooooole new woooooorld
        {
            //spawn player city
            int px = (int)grid[(int)freeCoordinates[0].x, (int)freeCoordinates[0].y].transform.position.x;
            int py = (int)grid[(int)freeCoordinates[0].x, (int)freeCoordinates[0].y].transform.position.y;
            playerCity = Instantiate(city, new Vector3(px, py, 99), Quaternion.identity) as GameObject;
            playerCity.GetComponent <City>().position.x = (int)freeCoordinates[0].x;
            playerCity.GetComponent <City>().position.y = (int)freeCoordinates[0].y;
            grid[(int)freeCoordinates[0].x, (int)freeCoordinates[0].y].GetComponent <Tile>().environment = playerCity;
            freeCoordinates.RemoveAt(0);
            playerCity.GetComponent <City>().type = "your home";
            allCities.Add(playerCity.GetComponent <City>());

            //set new profile
            PlayerPrefs.SetString("profile", playerCity.GetComponent <City>().name);
            for (int i = 0; i < 2; ++i)
            {
                playerCity.GetComponent <City>().CreateArmy();
            }
            playerCity.GetComponent <City> ().FillArmySelectDropdown();


            //spawn other cities
            for (int i = 1; i < cityNumber; ++i)
            {
                SpawnCity();
            }

            //spawn villages
            for (int i = 0; i < cityNumber * 3; ++i)
            {
                SpawnEnvironment((int)freeCoordinates[0].x, (int)freeCoordinates[0].y, village);
                freeCoordinates.RemoveAt(0);
            }
            //Spawn Forests -- Randomize Tree Layout Later
            for (int i = 0; i < (width * height) * .25f; ++i)
            {
                SpawnEnvironment((int)freeCoordinates[0].x, (int)freeCoordinates[0].y, forest);
                freeCoordinates.RemoveAt(0);
            }
            //fill empty space with salt
            while (freeCoordinates.Count > 0)
            {
                SpawnEnvironment((int)freeCoordinates[0].x, (int)freeCoordinates[0].y, saltFlats);
                freeCoordinates.RemoveAt(0);
            }
        }
        LoadCityTable();

        Debug.Log("table size " + cityTable.Count);

        foreach (string key in cityTable.Keys)
        {
            Debug.Log(key);
        }

        for (int i = 0; i < basicEnvironmentsList.Count; ++i)
        {
            basicEnvironmentsList[i].ConnectToOwner();
        }
        for (int i = 0; i < villageList.Count; ++i)
        {
            villageList[i].ConnectToOwner();
        }
    }