Ejemplo n.º 1
0
    public void LoadGame()
    {
        GameData    gameData    = GameData.Load();
        GameDataMap gameDataMap = GameDataMap.Load("map");

        this.baseMaterials.Clear();
        this.tiles.Clear();
        this.mapComponents.Clear();
        this.buildings.Clear();
        this.units.Clear();

        // Tiles
        this.tiles = Json.Deserialize <Dictionary <int, TileDao> >(gameData.tiles);

        // Base Materials
        this.baseMaterials = Json.Deserialize <Dictionary <int, BaseMaterialDao> >(gameData.baseMaterials);

        foreach (BaseMaterialDao baseMaterial in baseMaterials.Values)
        {
            baseMaterial.Instantiate();
        }

        // Material Sources
        this.mapComponents = Json.Deserialize <Dictionary <int, MapComponentDao> >(gameData.mapComponents);

        // Units
        this.units = Json.Deserialize <Dictionary <int, UnitDao> >(gameData.units);

        foreach (UnitDao unit in this.units.Values)
        {
            Debug.Log(unit.name + " => " + unit.id);
        }

        // Buildings
        this.buildings = Json.Deserialize <Dictionary <int, BuildingDao> >(gameData.buildings);

        // Map
        //map = Json.Deserialize<Map>(gameData.map);
        this.map = JsonUtility.FromJson <Map>(gameDataMap.map);

        this.mapTile      = new int[map.height, map.width];
        this.mapComponent = new int[map.height, map.width];

        // Map Tiles
        //mapTile = Json.Deserialize<int[,]>(gameData.mapTile);
        int[] tilesList = Json.Deserialize <int[]>(gameDataMap.mapTile);

        //Map Components
        //mapComponent = Json.Deserialize<int[,]>(gameData.mapComponent);
        int[] componentsList = Json.Deserialize <int[]>(gameDataMap.mapComponent);

        int height = (this.map.isReflected && (this.map.directionReflected == 'N' || this.map.directionReflected == 'S')) ? this.map.height / 2 : this.map.height;
        int width  = (this.map.isReflected && (this.map.directionReflected == 'E' || this.map.directionReflected == 'W')) ? this.map.width / 2 : this.map.width;

        int i, j;

        for (i = 0; i < height; i++)
        {
            for (j = 0; j < width; j++)
            {
                this.mapTile[i, j]      = tilesList[i * width + j];
                this.mapComponent[i, j] = componentsList[i * width + j];
            }
        }
    }
Ejemplo n.º 2
0
    public void LoadMap(string map = "")
    {
        Debug.Log("LoadMap()");

        string path = "";

        this.mapName = map;

        while (true && map == "")
        {
            path = EditorUtility.OpenFilePanel("Selecione um mapa", Application.dataPath + "/StreamingAssets/", "map");

            if (path.Equals(""))
            {
                return;
            }

            string[] extension = path.Split('.');

            string[] mapName = path.Split(new string[] { "/StreamingAssets/" }, StringSplitOptions.None);

            this.mapName = mapName[1];

            if (extension[extension.Length - 1].ToLower().Equals("map"))
            {
                break;
            }
            else
            {
                bool option = EditorUtility.DisplayDialog("Arquivo inválido!", "Selecione um arquivo que possua a extenção .map", "Tentar novamente", "Cancelar");

                if (!option)
                {
                    return;
                }
            }
        }

        this.CleanEditor();

        GameDataMap gdm = GameDataMap.Load(this.mapName);

        // Map
        this.map = JsonUtility.FromJson <Map>(gdm.map);

        // Map Tiles
        this.mapTileData = Json.Deserialize <int[]>(gdm.mapTile);

        //Map Components
        this.mapComponentsData = Json.Deserialize <int[]>(gdm.mapComponent);

        this.map.height = (this.map.directionReflected.Equals('N') || this.map.directionReflected.Equals('S') ? this.map.height / 2 : this.map.height);
        this.map.width  = (this.map.directionReflected.Equals('E') || this.map.directionReflected.Equals('W') ? this.map.width / 2 : this.map.width);

        this.height = this.map.height;
        this.width  = this.map.width;

        this.gameComponents.mapTile      = new int[this.map.height, this.map.width];
        this.gameComponents.mapComponent = new int[this.map.height, this.map.width];

        for (int i = 0; i < this.map.height; i++)
        {
            for (int j = 0; j < this.map.width; j++)
            {
                this.gameComponents.mapTile[i, j]      = this.mapTileData[i * this.map.width + j];
                this.gameComponents.mapComponent[i, j] = this.mapComponentsData[i * this.map.width + j];
            }
        }

        bool isReflected = this.map.isReflected;

        this.map.isReflected = false;

        this.map.Build(gameComponents);

        this.DrawMap();

        if (isReflected)
        {
            this.map.isReflected = true;
            this.map.height      = (this.map.directionReflected.Equals('N') || this.map.directionReflected.Equals('S') ? this.map.height * 2 : this.map.height);
            this.map.width       = (this.map.directionReflected.Equals('E') || this.map.directionReflected.Equals('W') ? this.map.width * 2 : this.map.width);;
        }

        this.buttonSave.SetActive(true);
    }