public TileMapTextureGenerator GetTileMapTextureGenerator() { TileMapTextureGenerator tileMapTextureGenerator = new TileMapTextureGenerator(textureAtlas, tileResolution, _sizeX, _sizeY); return(tileMapTextureGenerator); }
private void GenerateButtonsForTileTypes() { TerrainType[] terrainTypesValues = MaterialPropertiesFactory.GetAllowedInitialTerrainTypes(); InitTerrainTypeMaterialProperties(terrainTypesValues); TileMapTextureGenerator tileMapTextureGenerator = TileMap.GetTileMapTextureGenerator(); List <Color[]> texturesFromAtlas = tileMapTextureGenerator.ExtractTexturesFromAtlas(); RectTransform parentRectTransform = TerrainTypesPanel.transform.GetComponent <RectTransform>(); foreach (TerrainType terrainTypesValue in terrainTypesValues) { Texture2D texture2D = GetTextureForTerrainType(tileMapTextureGenerator, terrainTypesValue, texturesFromAtlas); GameObject button = CreateButton(terrainTypesValue, texture2D); _terrainButtons.Add(button); RectTransform buttonRectTransform = button.transform.GetComponent <RectTransform>(); float rectWidth = buttonRectTransform.rect.width / terrainTypesValues.Length; int buttonOffset = Array.IndexOf(terrainTypesValues, terrainTypesValue); button.transform.localPosition = new Vector3(rectWidth * 2 + (rectWidth * 8 * buttonOffset), (-parentRectTransform.rect.height / 2), 0); } SetPanelWidth(terrainTypesValues, parentRectTransform); }
private void BuildTexture() { TileMapTextureGenerator tileMapTextureGenerator = GetTileMapTextureGenerator(); Texture2D texture = tileMapTextureGenerator.GenerateTexture(_tileMapData); _meshRenderer.sharedMaterial.mainTexture = texture; Debug.Log("Texture built!"); }
private Texture2D GetTextureForTerrainType(TileMapTextureGenerator tileMapTextureGenerator, TerrainType terrainTypesValue, List <Color[]> texturesFromAtlas) { int terrainIndex = tileMapTextureGenerator.MapTerrainToTexture(terrainTypesValue); Color[] texturePixels = texturesFromAtlas[terrainIndex]; Texture2D texture2D = new Texture2D(TileMap.tileResolution, TileMap.tileResolution); texture2D.SetPixels(texturePixels); texture2D.Apply(); return(texture2D); }
public void UpdateTexture(TileData tileUnderMouse) { TileMapTextureGenerator tileMapTextureGenerator = GetTileMapTextureGenerator(); tileMapTextureGenerator.UpdateTexture(_meshRenderer.sharedMaterial.mainTexture as Texture2D, tileUnderMouse); }