Beispiel #1
0
    public void ChangeTerrainTileInTilemap(Vector3Int position, TerrainType type, bool predict = false)
    {
        TerrainBinding binding  = GetTerrainBindingFromType(type);
        TileBase       tilebase = binding?.terrainTile;

        GetTerrainTilemap(predict).SetTile(position, tilebase);
    }
Beispiel #2
0
    public TerrainType GetTerrainTypeFromTile(TileBase tile)
    {
        TerrainType    returnType = TerrainType.Default;
        TerrainBinding binding    = GetTerrainBindingFromTile(tile);

        if (binding != null)
        {
            returnType = binding.type;
        }
        return(returnType);
    }
Beispiel #3
0
    public TerrainTile CreateTerrainFromType(TerrainType type, BaseTileData baseTileData)
    {
        TerrainTile newTile = null;

        TerrainBinding terrainBinding = GetTerrainBindingFromType(type);

        if (terrainBinding != null)
        {
            switch (type)
            {
            case TerrainType.Plains:
                newTile = new PlainsTile();
                break;

            case TerrainType.Water:
                newTile = new WaterTile();
                break;

            case TerrainType.Wood:
                newTile = new WoodsTile();
                break;

            case TerrainType.Stone:
                newTile = new StoneTile();
                break;

            case TerrainType.Sand:
                newTile = new SandTile();
                break;

            default:
                throw new MissingTerrainTypeDefinitionException();
            }
        }
        baseTileData.terrainTile = newTile;

        TerrainInfo terrainInfo = Instantiate(terrainBinding.terrainVisualInfo, baseTileData.worldPosition, Quaternion.identity, _terrainTilemap.transform);

        terrainInfo.dataTile = newTile;
        newTile.terrainInfo  = terrainInfo;
        newTile.GridPosition = baseTileData.GridPosition;
        return(newTile);
    }
Beispiel #4
0
    internal TerrainData GetDataForTerrain(TerrainType terrainType)
    {
        TerrainBinding element = _terrainTemplates.First(x => x.type == terrainType);

        return(element?.terrainData);
    }
Beispiel #5
0
    public void CreateBaseTileData(TileBase tile, BaseTileData data)
    {
        TerrainBinding binding = GetTerrainBindingFromTile(tile);

        CreateTerrainFromType(binding.type, data);
    }