Exemple #1
0
    public virtual void SetTile(Vector3Int location, GridTile tile)
    {
        if (tile == null)
        {
            return;
        }
        if (tilemap == null)
        {
            tilemap = GetComponent <Tilemap>();
        }
        tile.transform.position = tilemap.CellToWorld(location) + new Vector3(0, .25f, 0);
        tile.transform.SetParent(tilemap.transform);
        tile.spriteRenderer.sortingOrder = layer;
        tile.location   = location;
        tiles[location] = tile;

        foreach (Grid newGrid in subGrids)
        {
            if (tile.GetType() == newGrid.type)
            {
                newGrid.SetTile(location, tile);
            }
        }

        // UpdateNeighbors(location);
    }
Exemple #2
0
 public Grid GetSubGrid(GridTile tileType)
 {
     foreach (Grid grid in subGrids)
     {
         if (grid.GetType() == tileType.GetType())
         {
             return(grid);
         }
     }
     return(null);
 }
Exemple #3
0
 protected virtual void Init()
 {
     type = prefab.GetType();
     foreach (Grid grid in GetComponentsInChildren <Grid>())
     {
         if (grid.Equals(this))
         {
             continue;
         }
         grid.Init();
         subGrids.Add(grid);
     }
     tilemap = GetComponent <Tilemap>();
 }