Пример #1
0
    public TileMapTextureGenerator GetTileMapTextureGenerator()
    {
        TileMapTextureGenerator tileMapTextureGenerator =
            new TileMapTextureGenerator(textureAtlas, tileResolution, _sizeX, _sizeY);

        return(tileMapTextureGenerator);
    }
Пример #2
0
    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);
    }
Пример #3
0
    private void BuildTexture()
    {
        TileMapTextureGenerator tileMapTextureGenerator = GetTileMapTextureGenerator();
        Texture2D texture = tileMapTextureGenerator.GenerateTexture(_tileMapData);

        _meshRenderer.sharedMaterial.mainTexture = texture;

        Debug.Log("Texture built!");
    }
Пример #4
0
    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);
    }
Пример #5
0
    public void UpdateTexture(TileData tileUnderMouse)
    {
        TileMapTextureGenerator tileMapTextureGenerator = GetTileMapTextureGenerator();

        tileMapTextureGenerator.UpdateTexture(_meshRenderer.sharedMaterial.mainTexture as Texture2D, tileUnderMouse);
    }