public bool HasTileAtCellPoint(Vector3Int cellPosToCheckFor, EnumData.TileType tileTypeTocheck) { Vector3 objectPosition = cellToworld(cellPosToCheckFor); RaycastHit2D[] hit2DArr = Physics2D.BoxCastAll(objectPosition, grid.cellSize * GameConfig.boxCastCellSizePercent, 0, objectPosition, 0); for (int i = 0; i < hit2DArr.Length; i++) { TileData td = hit2DArr[i].collider.gameObject.GetComponent <TileData>(); if (td != null && td.tileType == tileTypeTocheck) { return(true); } } return(false); }
public void SetTile(Vector3Int cellPos, EnumData.TileType tType, bool HasTile) { Vector3 worldPos = Vector3.zero; Vector3Int fireCellPos = Vector3Int.zero; GameObject fire = null; if (((int)tType - 1) > gameStateDependentTileArray.Length - 1) { Debug.LogError("index more thean range: " + tType); return; } if (((int)tType - 1) < 0) { Debug.LogError("index less thean zero: " + tType); return; } if (gameStateDependentTileArray[(int)tType - 1].tileMap == null) { Debug.LogError("tilemap is null"); return; } if (!HasTile) { gameStateDependentTileArray[(int)tType - 1].tileMap.SetTile(cellPos, null); if (gameStateDependentTileArray[(int)tType - 1].cereberustileToggle) { //switch (tType) //{ // case EnumData.TileType.LeftCereberusHead: // worldPos = cellToworld(cellPos) + GetFacingDirectionOffsetVector3(FaceDirection.Left); // fireCellPos = grid.WorldToCell(worldPos); // fire = GetFireObject(fireCellPos, FaceDirection.Left); // if (fire != null) // { // Destroy(fire); // } // break; // case EnumData.TileType.RightCereberusHead: // worldPos = cellToworld(cellPos) + GetFacingDirectionOffsetVector3(FaceDirection.Right); // fireCellPos = grid.WorldToCell(worldPos); // fire = GetFireObject(fireCellPos, FaceDirection.Right); // if (fire != null) // { // Destroy(fire); // } // break; // case EnumData.TileType.UpCereberusHead: // worldPos = cellToworld(cellPos) + GetFacingDirectionOffsetVector3(FaceDirection.Up); // fireCellPos = grid.WorldToCell(worldPos); // fire = GetFireObject(fireCellPos, FaceDirection.Up); // if (fire != null) // { // Destroy(fire); // } // break; // case EnumData.TileType.DownCereberusHead: // worldPos = cellToworld(cellPos) + GetFacingDirectionOffsetVector3(FaceDirection.Down); // fireCellPos = grid.WorldToCell(worldPos); // fire = GetFireObject(fireCellPos, FaceDirection.Down); // if (fire != null) // { // Destroy(fire); // } // break; //} } } else { int xAbs = Mathf.Abs(cellPos.x); int yAbs = Mathf.Abs(cellPos.y); if (gameStateDependentTileArray[(int)tType - 1].cereberustileToggle) { switch (tType) { //case EnumData.TileType.RightCereberusHead: // worldPos = cellToworld(cellPos) + GetFacingDirectionOffsetVector3(FaceDirection.Right); // if (!IsCellBlockedForPetrifiedUnitMotionAtPos(grid.WorldToCell(worldPos)) || IsCellContainingMirrorAtPos(grid.WorldToCell(worldPos))) // { // Instantiate(rightFire, worldPos, Quaternion.identity); // } // break; //case EnumData.TileType.LeftCereberusHead: // worldPos = cellToworld(cellPos) + GetFacingDirectionOffsetVector3(FaceDirection.Left); // if (!IsCellBlockedForPetrifiedUnitMotionAtPos(grid.WorldToCell(worldPos)) || IsCellContainingMirrorAtPos(grid.WorldToCell(worldPos))) // { // Instantiate(leftFire, worldPos, Quaternion.identity); // } // break; //case EnumData.TileType.DownCereberusHead: // worldPos = cellToworld(cellPos) + GetFacingDirectionOffsetVector3(FaceDirection.Down); // if (!IsCellBlockedForPetrifiedUnitMotionAtPos(grid.WorldToCell(worldPos)) || IsCellContainingMirrorAtPos(grid.WorldToCell(worldPos))) // { // Instantiate(downFire, worldPos, Quaternion.identity); // } // break; //case EnumData.TileType.UpCereberusHead: // worldPos = cellToworld(cellPos) + GetFacingDirectionOffsetVector3(FaceDirection.Up); // if (!IsCellBlockedForPetrifiedUnitMotionAtPos(grid.WorldToCell(worldPos)) || IsCellContainingMirrorAtPos(grid.WorldToCell(worldPos))) // { // Instantiate(upFire, worldPos, Quaternion.identity); // } // break; } } if (gameStateDependentTileArray[(int)tType - 1].multipleTileGraphic) { if (gameStateDependentTileArray[(int)tType - 1].isDarkOnOdd) { if ((xAbs + yAbs) % 2 == 1) { gameStateDependentTileArray[(int)tType - 1].tileMap.SetTile(cellPos, gameStateDependentTileArray[(int)tType - 1].darkTile); } if ((xAbs + yAbs) % 2 == 0) { gameStateDependentTileArray[(int)tType - 1].tileMap.SetTile(cellPos, gameStateDependentTileArray[(int)tType - 1].tile); } } else { if ((xAbs + yAbs) % 2 == 1) { gameStateDependentTileArray[(int)tType - 1].tileMap.SetTile(cellPos, gameStateDependentTileArray[(int)tType - 1].tile); } if ((xAbs + yAbs) % 2 == 0) { gameStateDependentTileArray[(int)tType - 1].tileMap.SetTile(cellPos, gameStateDependentTileArray[(int)tType - 1].darkTile); } } } else { //if (gameStateDependentTileArray[(int)tType - 1].cereberustileToggle) //{ // if (!IsCellBlockedForPetrifiedUnitMotionAtPos(grid.WorldToCell(worldPos)) || IsCellContainingMirrorAtPos(grid.WorldToCell(worldPos))) // { // gameStateDependentTileArray[(int)tType - 1].tileMap.SetTile(cellPos, gameStateDependentTileArray[(int)tType - 1].tile); // } // else // { // gameStateDependentTileArray[(int)tType - 1].tileMap.SetTile(cellPos, gameStateDependentTileArray[(int)tType - 1].tileOff); // } //} //else //{ gameStateDependentTileArray[(int)tType - 1].tileMap.SetTile(cellPos, gameStateDependentTileArray[(int)tType - 1].tile); //} } if (gameStateDependentTileArray[(int)tType - 1].tileMap.GetComponent <TilemapCollider2D>() != null) { gameStateDependentTileArray[(int)tType - 1].tileMap.GetComponent <TilemapCollider2D>().enabled = false; gameStateDependentTileArray[(int)tType - 1].tileMap.GetComponent <TilemapCollider2D>().enabled = true; } } }