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); }
public Grid GetSubGrid(GridTile tileType) { foreach (Grid grid in subGrids) { if (grid.GetType() == tileType.GetType()) { return(grid); } } return(null); }
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>(); }