예제 #1
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);
    }
예제 #2
0
 private void InitTerrainTypeMaterialProperties(TerrainType[] terrainTypesValues)
 {
     foreach (TerrainType terrainType in terrainTypesValues)
     {
         MaterialProperties materialProperties = MaterialPropertiesFactory.GetProperties(terrainType);
         _materialProperties.Add(terrainType, materialProperties);
     }
 }
        private void InitTiles(TileMapData tileMapData)
        {
            TerrainType[] terrainTypes = MaterialPropertiesFactory.GetAllowedInitialTerrainTypes();

            float terrainSeed = Random.Range(0.0f, 200.0f);
            float heightSeed  = Random.Range(0.0f, 200.0f);

            for (int x = 0; x < _sizeX; x++)
            {
                for (int y = 0; y < _sizeY; y++)
                {
                    int   generatedType   = GenerateTerrainType(x, y, terrainSeed, terrainTypes.Length);
                    float generatedHeight = GenerateTerrainHeight(x, y, heightSeed);

                    TerrainType        terrainType        = terrainTypes[generatedType];
                    MaterialProperties materialProperties = MaterialPropertiesFactory.GetProperties(terrainType);

                    TerrainData terrainData = new TerrainData(terrainType, generatedHeight, materialProperties);
                    tileMapData.SetTileData(x, y, new TileData(x, y, terrainData));
                }
            }
        }