示例#1
0
 public void InitializeMap()
 {
     gridMapSize = GridPoints.UnityToGridCoord(unityMapSize);
     tilesInMap  = new GameObject[unityMapSize.x, unityMapSize.y];
     mapTiles    = new GameObject[unityMapSize.x, unityMapSize.y, 16]; //array with all tiles
     GetSeed();
 }
示例#2
0
 public void CombineTilesInMap()
 {
     for (int x = 1; x < unityMapSize.x; x++)
     {
         for (int y = 1; y < unityMapSize.y; y++)
         {
             if (tilesInMap[x, y] != null)
             {
                 CombineTiles(tilesInMap[x, y], GridPoints.UnityToGridCoord(new Vector2(x, y)));
             }
         }
     }
 }
示例#3
0
    public void CreateTile(Tile tile, int xCoord, int yCoord)
    {
        Vector2    coords     = new Vector2(xCoord, yCoord);
        GridPoints gridCoords = GridPoints.UnityToGridCoord(coords);

        if (IsInsideBoundaries(coords) && !TileAlreadyThere(gridCoords, tile.isGroundTile))
        {
            GameObject tileToAdd = new GameObject("Tile", typeof(SpriteRenderer), typeof(TileObject));
            tileToAdd.transform.position = new Vector3(gridCoords.x, gridCoords.y, 0f);

            // to render the sprites correctly
            SpriteRenderer spriteRenderer = tileToAdd.GetComponent <SpriteRenderer>();
            spriteRenderer.material = pixelMaterial;

            TileObject tileData = tileToAdd.GetComponent <TileObject>();
            tileData.tile = tile;
            tileToAdd.transform.parent = mapHolder.transform;
            tilesInMap[xCoord, yCoord] = tileToAdd;
            lastCreatedTile            = tileToAdd;
        }
    }