Example #1
0
        // check if a tile is fully visible
        private bool CheckTileExistence(int tileRoundedZoom, int tileX, int tileY)
        {
            string key = Tile.GetTileKey(tileRoundedZoom, tileX, tileY);

            if (!tiles.ContainsKey(key))
            {
                return(true);        // the tile is out of the frustum
            }
            Tile     tile = tiles[key];
            Renderer r    = tile.GetComponent <Renderer>();

            return(r.enabled && r.material.mainTexture != null && !tile.Showing);
        }
Example #2
0
        // <summary>
        // A recursive method that grows tiles starting from the map's center in all four directions.
        // </summary>
        void GrowTiles(Plane[] frustum, int tileX, int tileY, int tileCountOnX, int tileCountOnY, float offsetX, float offsetZ)
        {
            tileTemplate.transform.position = new Vector3(offsetX, tileTemplate.transform.position.y, offsetZ);
            if (GeometryUtility.TestPlanesAABB(frustum, tileTemplate.GetComponent <Collider>().bounds) == true)
            {
                if (tileX < 0)
                {
                    tileX += tileCountOnX;
                }
                else if (tileX >= tileCountOnX)
                {
                    tileX -= tileCountOnX;
                }

                string tileAddress = Tile.GetTileKey(Map.RoundedZoom, tileX, tileY);
                //Debug.Log("DEBUG: tile address: " + tileAddress);
                if (tiles.ContainsKey(tileAddress) == false)
                {
                    Tile tile = null;
                    if (tileCache.Count > 0)
                    {
                        tile = tileCache[0];
                        tileCache.Remove(tile);
                        tile.transform.position   = tileTemplate.transform.position;
                        tile.transform.localScale = new Vector3(Map.RoundedHalfMapScale, 1.0f, Map.RoundedHalfMapScale);
                        //tile.gameObject.active = this.gameObject.active;
                    }
                    else
                    {
                        tile = (GameObject.Instantiate(tileTemplate.gameObject) as GameObject).GetComponent <Tile>();
                        tile.transform.parent = this.gameObject.transform;
                    }

                    tile.name = "tile_" + tileAddress;
                    tiles.Add(tileAddress, tile);
                    //MeshRenderer tileMeshRenderer = tile.GetComponent<MeshRenderer>();
                    //tileMeshRenderer.enabled = true;

                    RequestTile(tileX, tileY, Map.RoundedZoom, tile);
                }

                tileAddressLookedFor = tileAddress;
                if (visitedTiles.Exists(visitedTilesMatchPredicate) == false)
                {
                    visitedTiles.Add(tileAddress);

                    // grow tiles in the four directions without getting outside of the coordinate range of the zoom level
                    int   nTileX, nTileY;
                    float nOffsetX, nOffsetZ;

                    if (GetNeighbourTile(tileX, tileY, offsetX, offsetZ, tileCountOnX, tileCountOnY, NeighbourTileDirection.South, out nTileX, out nTileY, out nOffsetX, out nOffsetZ))
                    {
                        GrowTiles(frustum, nTileX, nTileY, tileCountOnX, tileCountOnY, nOffsetX, nOffsetZ);
                    }

                    if (GetNeighbourTile(tileX, tileY, offsetX, offsetZ, tileCountOnX, tileCountOnY, NeighbourTileDirection.North, out nTileX, out nTileY, out nOffsetX, out nOffsetZ))
                    {
                        GrowTiles(frustum, nTileX, nTileY, tileCountOnX, tileCountOnY, nOffsetX, nOffsetZ);
                    }

                    if (GetNeighbourTile(tileX, tileY, offsetX, offsetZ, tileCountOnX, tileCountOnY, NeighbourTileDirection.East, out nTileX, out nTileY, out nOffsetX, out nOffsetZ))
                    {
                        GrowTiles(frustum, nTileX, nTileY, tileCountOnX, tileCountOnY, nOffsetX, nOffsetZ);
                    }

                    if (GetNeighbourTile(tileX, tileY, offsetX, offsetZ, tileCountOnX, tileCountOnY, NeighbourTileDirection.West, out nTileX, out nTileY, out nOffsetX, out nOffsetZ))
                    {
                        GrowTiles(frustum, nTileX, nTileY, tileCountOnX, tileCountOnY, nOffsetX, nOffsetZ);
                    }
                }
            }
        }