Beispiel #1
0
        /// <summary>
        /// Creates the non-flat terrain using a height multiplier
        /// </summary>
        /// <param name="tile"></param>
        // <param name="heightMultiplier">Multiplier for queried height value</param>
        private void CreateTerrainHeight(UnityTile tile)
        {
            tile.HeightDataState = TilePropertyState.Loading;
            var pngRasterTile = new RawPngRasterTile();

            tile.AddTile(pngRasterTile);
            Progress++;

            pngRasterTile.Initialize(_fileSource, tile.CanonicalTileId, MapId, () =>
            {
                if (tile == null)
                {
                    return;
                }

                if (pngRasterTile.HasError)
                {
                    OnErrorOccurred(new TileErrorEventArgs(tile.CanonicalTileId, pngRasterTile.GetType(), tile, pngRasterTile.Exceptions));
                    tile.HeightDataState = TilePropertyState.Error;

                    // Handle missing elevation from server (404)!
                    // TODO: optimize this search!
                    if (pngRasterTile.ExceptionsAsString.Contains("404"))
                    {
                        ResetToFlatMesh(tile);
                    }
                    Progress--;
                    return;
                }

                tile.SetHeightData(pngRasterTile.Data, _elevationOptions.requiredOptions.exaggerationFactor);
                GenerateTerrainMesh(tile);
                Progress--;
            });
        }
Beispiel #2
0
    //tile here should be totally optional and used only not to have keep a dictionary in terrain factory base
    public void FetchTerrain(CanonicalTileId canonicalTileId, string mapid, UnityTile tile = null)
    {
        var pngRasterTile = new RawPngRasterTile();

        pngRasterTile.Initialize(_fileSource, canonicalTileId, mapid, () =>
        {
            if (pngRasterTile.HasError)
            {
                FetchingError(tile, new TileErrorEventArgs(canonicalTileId, pngRasterTile.GetType(), null, pngRasterTile.Exceptions));
            }

            DataRecieved(tile, pngRasterTile);
        });
    }
Beispiel #3
0
        /// <summary>
        /// Creates the non-flat terrain using a height multiplier
        /// </summary>
        /// <param name="tile"></param>
        /// <param name="heightMultiplier">Multiplier for queried height value</param>
        private void CreateTerrainHeight(UnityTile tile)
        {
            tile.HeightDataState = TilePropertyState.Loading;
            var pngRasterTile = new RawPngRasterTile();

            tile.AddTile(pngRasterTile);
            Progress++;

            pngRasterTile.Initialize(_fileSource, tile.CanonicalTileId, _mapId, () =>
            {
                if (tile == null)
                {
                    return;
                }

                if (pngRasterTile.HasError)
                {
                    OnErrorOccurred(new TileErrorEventArgs(tile.CanonicalTileId, pngRasterTile.GetType(), tile, pngRasterTile.Exceptions));
                    tile.HeightDataState = TilePropertyState.Error;

                    // Handle missing elevation from server (404)!
                    // TODO: optimize this search!
                    if (pngRasterTile.ExceptionsAsString.Contains("404"))
                    {
                        ResetToFlatMesh(tile);
                    }
                    Progress--;
                    return;
                }

                tile.SetHeightData(pngRasterTile.Data, _heightModifier, _useRelativeHeight);
                GenerateTerrainMesh(tile);
                // Add a collider this may or may not be worse than the mesh collider that the terrain factory
                // can generate
                // tile.gameObject.AddComponent<BoxCollider>();
                // tile.gameObject.GetComponent<BoxCollider>().size = new Vector3( 99, .1f, 99 );
                // tile.gameObject.GetComponent<BoxCollider>().center = new Vector3( 0 , 0, 0 );
                // Add a tag for generating navmesh
                // tile.gameObject.AddComponent<NavMeshSourceTag>();
                Progress--;
            });
        }
    //tile here should be totally optional and used only not to have keep a dictionary in terrain factory base
    public override void FetchData(DataFetcherParameters parameters)
    {
        var terrainDataParameters = parameters as TerrainDataFetcherParameters;

        if (terrainDataParameters == null)
        {
            return;
        }
        var pngRasterTile = new RawPngRasterTile();

        pngRasterTile.Initialize(_fileSource, terrainDataParameters.canonicalTileId, terrainDataParameters.mapid, () =>
        {
            if (terrainDataParameters.tile.CanonicalTileId != pngRasterTile.Id)
            {
                //this means tile object is recycled and reused. Returned data doesn't belong to this tile but probably the previous one. So we're trashing it.
                return;
            }

            if (pngRasterTile.HasError)
            {
                FetchingError(terrainDataParameters.tile, pngRasterTile, new TileErrorEventArgs(terrainDataParameters.canonicalTileId, pngRasterTile.GetType(), null, pngRasterTile.Exceptions));
            }
            else
            {
                DataRecieved(terrainDataParameters.tile, pngRasterTile);
            }
        });
    }
    //tile here should be totally optional and used only not to have keep a dictionary in terrain factory base
    public void FetchTerrain(CanonicalTileId canonicalTileId, string mapid, UnityTile tile = null)
    {
        var pngRasterTile = new RawPngRasterTile();

        pngRasterTile.Initialize(_fileSource, canonicalTileId, mapid, () =>
        {
            if (tile.CanonicalTileId != pngRasterTile.Id)
            {
                //this means tile object is recycled and reused. Returned data doesn't belong to this tile but probably the previous one. So we're trashing it.
                return;
            }

            if (pngRasterTile.HasError)
            {
                FetchingError(tile, pngRasterTile, new TileErrorEventArgs(canonicalTileId, pngRasterTile.GetType(), null, pngRasterTile.Exceptions));
            }
            else
            {
                DataRecieved(tile, pngRasterTile);
            }
        });
    }