private void ResetBurningDistance(TileData tileData) { string tileKey = tileData.PositionX.ToString() + tileData.PositionY.ToString(); for (int x = tileData.PositionX - 1; x <= tileData.PositionX + 1; x++) { if (x < 0 || x >= _tileMapData.GetTileData().Length) { continue; } for (int y = tileData.PositionY - 1; y <= tileData.PositionY + 1; y++) { if (y < 0 || y >= _tileMapData.GetTileData()[x].Length) { continue; } if (x == tileData.PositionX && y == tileData.PositionY) { continue; } if (_tileMapData.GetTileData(x, y).FireSpreadingDistance.ContainsKey(tileKey)) { _tileMapData.GetTileData(x, y).FireSpreadingDistance[tileKey] = 0.0f; } } } }
private List <TileData> GetUnburningNeighbours(TileData selectedTile) { List <TileData> neighbours = new List <TileData>(); for (int x = selectedTile.PositionX - 1; x <= selectedTile.PositionX + 1; x++) { if (x < 0 || x >= _tileMap._tileMapData.GetTileData().Length) { continue; } for (int y = selectedTile.PositionY - 1; y <= selectedTile.PositionY + 1; y++) { if (y < 0 || y >= _tileMap._tileMapData.GetTileData()[x].Length) { continue; } if (x == selectedTile.PositionX && y == selectedTile.PositionY) { continue; } if (!_tileMapData.GetTileData(x, y).IsBurning) { neighbours.Add(_tileMapData.GetTileData(x, y)); } } } return(neighbours); }
private float GetMeanVertexHeight(int vertexX, int vertexY, TileMapData tileMapData) { List <TileData> tiles = new List <TileData>(); tiles.Add(tileMapData.GetTileData(vertexX - 1, vertexY - 1)); tiles.Add(tileMapData.GetTileData(vertexX - 1, vertexY)); tiles.Add(tileMapData.GetTileData(vertexX, vertexY)); tiles.Add(tileMapData.GetTileData(vertexX, vertexY - 1)); tiles.RemoveAll(item => item == null); float sum = tiles.Sum(data => data.TerrainData.Height); return(sum / tiles.Count); }
public void TestGetTileDataArray() { TileData[,] tileDataArray = _tileMapData.GetTileData(); Assert.AreEqual(MAP_SQUARE_SIZE, tileDataArray.GetLength(0)); Assert.AreEqual(MAP_SQUARE_SIZE, tileDataArray.GetLength(1)); }
public void Setup() { _tileMapData = new TileMapData(MAP_SQUARE_SIZE, MAP_SQUARE_SIZE); TileData[,] tileData = _tileMapData.GetTileData(); for (int x = 0; x < MAP_SQUARE_SIZE; x++) { for (int z = 0; z < MAP_SQUARE_SIZE; z++) { tileData [x, z] = GetGrassTileData(); } } // Add un-walkable tiles in middle of tilemap tileData [4, 4] = GetWaterTileData(); tileData [5, 4] = GetWaterTileData(); tileData [6, 4] = GetWaterTileData(); Graph graph = new Graph(MAP_SQUARE_SIZE, MAP_SQUARE_SIZE); graph.Generate4WayGraph(); _nodeGrapth = graph.GetGraph(); _validStraightPathfinder = new Pathfinder(_tileMapData, _nodeGrapth); _validStraightPathfinder.GeneratePath(0, 0, 5, 0); _invalidPathfinder = new Pathfinder(_tileMapData, _nodeGrapth); _invalidPathfinder.GeneratePath(0, 0, 0, 0); _validIgnoreUnWalkablePathfinder = new Pathfinder(_tileMapData, _nodeGrapth); _validIgnoreUnWalkablePathfinder.GeneratePath(new Vector3(3, 0, 4), new Vector3(7, 0, 4)); }
public void Setup() { _tileMapData = new TileMapData(MAP_SQUARE_SIZE, MAP_SQUARE_SIZE); TileData[,] tileData = _tileMapData.GetTileData(); for (int x = 0; x < MAP_SQUARE_SIZE; x++) { for (int z = 0; z < MAP_SQUARE_SIZE; z++) { tileData [x, z] = GetGrassTileData(); } } // Add un-walkable tiles in middle of tilemap tileData [4, 4] = GetWaterTileData(); }
private Texture2D GenerateTextureData(TileMapData tileMapData) { int textureWidth = _tileResolution * _tileSizeX; int textureHeight = _tileResolution * _tileSizeZ; Texture2D texture = new Texture2D(textureWidth, textureHeight); for (int y = 0; y < _tileSizeZ; y++) { for (int x = 0; x < _tileSizeX; x++) { TileData tileData = tileMapData.GetTileData(x, y); int textureIndex = MapTerrainToTexture(tileData.TerrainData.Type); Color[] extractedTexture = _extractedTextures[textureIndex]; texture.SetPixels(x * _tileResolution, y * _tileResolution, _tileResolution, _tileResolution, extractedTexture); } } texture.wrapMode = TextureWrapMode.Clamp; texture.filterMode = FilterMode.Point; texture.Apply(); return(texture); }
/// <summary> /// Builds the texture. /// </summary> private void BuildTexture() { int texWidth = Width * TileResolution; int texHeight = Height * TileResolution; Texture2D texture = new Texture2D(texWidth, texHeight); TileData[,] tileData = _tileMapData.GetTileData(); for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { TileData currentTileData = tileData [x, y]; string imagePath = currentTileData.ImagePath; // Grab texture from cache if available, if not, load from disk then put in cache //Texture2D loadedTexture; Color[] pixels; if (_pixelCache.ContainsKey(imagePath)) { pixels = _pixelCache [imagePath]; } else { Texture2D loadedTexture = new Texture2D(texWidth, texHeight); string path = Utility.CombinePaths(Application.streamingAssetsPath, TILE_SET_ROOT_DIRECTORY, TileSet, "Tiles", imagePath); byte[] bytes = File.ReadAllBytes(path); loadedTexture.LoadImage(bytes); pixels = loadedTexture.GetPixels(0, 0, TileResolution, TileResolution); _pixelCache.Add(imagePath, pixels); } // Set pixels texture.SetPixels(x * TileResolution, y * TileResolution, TileResolution, TileResolution, pixels); // If a unit is on the tile, instantiate them and move them to that tile if (currentTileData.UnitResRef != null) { Unit unit = Unit.InstantiateUnit(currentTileData.UnitResRef); unit.gameObject.name = unit.GetFullName(); currentTileData.Unit = unit; unit.Tile = currentTileData.Position; unit.transform.position = TileMapUtil.TileMapToWorldCentered(currentTileData.Position, TileSize); GameManager.Instance.GetTurnOrderController().AddUnsortedUnit(unit); if (unit.UnitData.Type == UnitData.UnitType.PLAYER) { _allies.Add(unit); } else if (unit.UnitData.Type == UnitData.UnitType.ENEMY) { _enemies.Add(unit); } } } } texture.filterMode = FilterMode.Point; texture.wrapMode = TextureWrapMode.Clamp; texture.Apply(); MeshRenderer mesh_renderer = GetComponent <MeshRenderer>(); mesh_renderer.sharedMaterials [0].mainTexture = texture; //Debug.Log ("Done Texture!"); }