public void SwapTilesInContainer(TileContainer tileFrom, TileContainer tileTo) { if (AreTilesAdjacent(tileFrom, tileTo)) { Vector2 fromCoord = GetTileContainerCoordinates(tileFrom); Vector2 toCoord = GetTileContainerCoordinates(tileTo); SwapTiles(fromCoord, toCoord); tileTo.AttachNewTile(TileMap[(int)toCoord.y][(int)toCoord.x].Tile); tileFrom.AttachNewTile(TileMap[(int)fromCoord.y][(int)fromCoord.x].Tile); } }
public void InitTiles() { RemoveCurrentTiles(); for (int y = 0; y < Rows; y++) { TileMap.Add(new List <TileContainer>()); for (int x = 0; x < Columns; x++) { Tile t = CreateNewRandomTile(); //add tile container TileContainer container = Instantiate(TileContainerPrefab); //t.transform.position = container.transform.position; container.AttachNewTile(t); container.transform.SetParent(UiTilesTransformBase, false); container.transform.SetSiblingIndex(0); //add reference TileMap[y].Add(container); } } FreezeUpdateLoop = false; }