Пример #1
0
    // Create map Tiles
    private void drawMap()
    {
        this.tileGameObjects = new Dictionary <KeyValuePair <int, int>, GameObject>();

        if (this.mapModel != null)
        {
            for (int y = 0; y < this.mapModel.Height; y++)
            {
                for (int x = 0; x < this.mapModel.Width; x++)
                {
                    MapGenetic.MapTileType type = this.mapModel.getTileType(x, y);
                    this.tileGameObjects.Add(new KeyValuePair <int, int>(y, x), this.createMapTile(type, x, y));
                }
            }
            foreach (GeneticTarget t in this.mapModel.Targets)
            {
                this.createTarget(t.getPosX(), t.getPosY());
            }
            // Adjust the camera
            Camera mapCamera = GameObject.FindObjectOfType <Camera>();
            if (mapCamera != null)
            {
                mapCamera.transform.position = new Vector3(this.mapModel.Width / 2f - 0.5f, this.mapModel.Height / 2f - 0.5f, -1);              // 0.5 is the size of a half of the tile
                mapCamera.orthographicSize   = Mathf.Max(this.mapModel.Width / 2f, this.mapModel.Height / 2f);
            }
        }
    }
 public void setType(MapGenetic.MapTileType type)
 {
     this.type = type;
     if (this.type != MapGenetic.MapTileType.NotDefined)
     {
         tileImage.sprite = tileSprites[MapGenetic.typeToTypeIndex(this.type)];
     }
 }
Пример #3
0
    private GameObject createMapTile(MapGenetic.MapTileType type, int x, int y)
    {
        GameObject result = null;

        if (type != MapGenetic.MapTileType.NotDefined)
        {
            result = GameObject.Instantiate(mapTilePrefab, mapContainer.transform);
            result.GetComponent <MapGeneticTileView>().setPosition(x, y);
            result.GetComponent <MapGeneticTileView>().setType(type);
        }
        return(result);
    }