コード例 #1
0
        private void CreateTileBackground(GOTile tile)
        {
            MeshFilter   filter   = tile.gameObject.AddComponent <MeshFilter>();
            MeshRenderer renderer = tile.gameObject.AddComponent <MeshRenderer>();

            tile.vertices = new List <Vector3> ();
            IList verts = tile.tileCenter.tileVertices(zoomLevel);

            foreach (Vector3 v in verts)
            {
                tile.vertices.Add(tile.transform.InverseTransformPoint(v));
            }

            Poly2Mesh.Polygon poly = new Poly2Mesh.Polygon();
            poly.outside = tile.vertices;
            Mesh mesh = Poly2Mesh.CreateMesh(poly);

            Vector2[] uvs = new Vector2[mesh.vertices.Length];
            for (int i = 0; i < uvs.Length; i++)
            {
                uvs[i] = new Vector2(mesh.vertices[i].x, mesh.vertices[i].z);
            }
            mesh.uv = uvs;

            filter.sharedMesh = mesh;
            tile.gameObject.AddComponent <MeshCollider> ();

            renderer.material = tileBackground;
        }
コード例 #2
0
        GOTile createSmartTileObject(Vector2 tileCoords, int Zoom)
        {
            GameObject tileObj = new GameObject((int)tileCoords.x + "-" + (int)tileCoords.y + "-" + zoomLevel);

            tileObj.transform.parent = gameObject.transform;
            GOTile tile = tileObj.AddComponent <GOMapzenProtoTile> ();

            tiles.Add(tileObj.name, tile);
            return(tile);
        }
コード例 #3
0
        public virtual IEnumerator BuildFeature(GOTile tile, bool delayedLoad)
        {
            if (type == null)
            {
                Debug.Log("type is null");
                return(null);
            }
            try
            {
                if (goFeatureType == GOFeatureType.Line || goFeatureType == GOFeatureType.MultiLine)
                {
                    if (properties.Contains("min_zoom"))
                    {
                        if (float.Parse(properties["min_zoom"].ToString()) < 14f)
                        {
                            return(CreateLine(tile, delayedLoad));
                        }
                        else
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    // return null;
                    return(CreatePolygon(tile, delayedLoad));

                    /* if (properties.Contains("min_zoom"))
                     * {
                     *   if (float.Parse(properties["min_zoom"].ToString()) < 15f)
                     *   {
                     *       return CreatePolygon(tile, delayedLoad);
                     *   }
                     *   else
                     *   {
                     *       return null;
                     *   }
                     * }
                     * else
                     * {
                     *   return null;
                     * }*/
                }
            }
            catch (Exception ex)
            {
                Debug.Log("[GOFeature] Catched exception: " + ex);
                return(null);
            }
        }
コード例 #4
0
        public void SpawnBallons(GOTile tile)
        {
            //int spawn = Random.Range (0, 5);
            //if (spawn == 0) {
            //float y = Random.Range (90, 250);
            Vector3 pos = tile.tileCenter.convertCoordinateToVector();
            //pos.y = y;
            int        n   = Random.Range(0, baloonPrefab.Length);
            GameObject obj = (GameObject)Instantiate(baloonPrefab[n]);

            obj.transform.position = pos;
            obj.transform.parent   = transform;
            //}
        }
コード例 #5
0
        public virtual IEnumerator CreateLine(GOTile tile, bool delayedLoad)
        {
            GORenderingOptions renderingOptions = GetRenderingOptions();

            if (renderingOptions.lineWidth == 0)
            {
                yield break;
            }

            GameObject line = new GameObject(name != null ? name : kind.ToString());

            line.transform.parent = parent.transform;

            //Layer mask
            if (layer.useLayerMask == true)
            {
                tile.AddObjectToLayerMask(layer, line);
            }

            GOFeatureMeshBuilder builder = new GOFeatureMeshBuilder(this);

            builder.BuildLine(line, layer, renderingOptions, tile.map);

            GOFeatureBehaviour fb = line.AddComponent <GOFeatureBehaviour>();

            fb.goFeature = this;

            if (layer.layerType == GOLayer.GOLayerType.Roads && name != null && name.Length > 0 && renderingOptions.useStreetNames)
            {
                GOStreetName streetName = new GameObject().AddComponent <GOStreetName>();
                streetName.gameObject.name = name + "_streetname";
                streetName.transform.SetParent(line.transform);
                yield return(tile.StartCoroutine(streetName.Build(name)));
            }

            if (layer.OnFeatureLoad != null)
            {
                layer.OnFeatureLoad.Invoke(builder.mesh, layer, kind, builder.center);
            }

            if (delayedLoad)
            {
                yield return(null);
            }
        }
コード例 #6
0
        public IEnumerator ReloadMap(Vector2 location, bool delayed)
        {
            //Get SmartTiles
            List <Vector2> tileList = veclist(location, tileBuffer);
            List <GOTile>  newTiles = new List <GOTile> ();

            // Create new tiles
            foreach (Vector2 tileCoords in tileList)
            {
                string name = tileCoords.x + "-" + tileCoords.y + "-" + zoomLevel;
                if (!tiles.ContainsKey(name))
                {
                    GOTile adiacentSmartTile = createSmartTileObject(tileCoords, zoomLevel);
                    adiacentSmartTile.tileCenter = new Coordinates(tileCoords, zoomLevel);
                    adiacentSmartTile.gameObject.transform.position = adiacentSmartTile.tileCenter.convertCoordinateToVector();
                    newTiles.Add(adiacentSmartTile);

                    if (tileBackground != null)
                    {
                        CreateTileBackground(adiacentSmartTile);
                    }
                }
            }
            foreach (GOTile tile in newTiles)
            {
                                #if !UNITY_WEBPLAYER
                if (tile != null && FileHandler.Exist(tile.gameObject.name) && useCache)
                {
                    yield return(tile.StartCoroutine(tile.LoadTileData(this, tile.tileCenter, zoomLevel, layers, delayed)));
                }
                else
                {
                    tile.StartCoroutine(tile.LoadTileData(this, tile.tileCenter, zoomLevel, layers, delayed));
                }
                                #endif
            }
            yield return(null);
        }
コード例 #7
0
        public virtual IEnumerator CreatePolygon(GOTile tile, bool delayedLoad)
        {
            GameObject           polygon          = null;
            GORenderingOptions   renderingOptions = GetRenderingOptions();
            GOFeatureMeshBuilder builder          = new GOFeatureMeshBuilder(this);

            //Materials
            Material material = tile.GetMaterial(renderingOptions, builder.center);
            Material roofMat  = renderingOptions.roofMaterial == null ? renderingOptions.material : renderingOptions.roofMaterial;

            if (sort != 0)
            {
                if (material)
                {
                    material.renderQueue = -(int)sort;
                }
                if (roofMat)
                {
                    roofMat.renderQueue = -(int)sort;
                }
            }

            //Group buildings by center coordinates
            if (layer.layerType == GOLayer.GOLayerType.Buildings && defaultRendering)
            {
                GameObject centerContainer = tile.findNearestCenter(builder.center, parent, material);
                parent   = centerContainer;
                material = centerContainer.GetComponent <GOMatHolder>().material;
            }

            int offset = 0;

            if (!layer.useRealHeight)
            {
                height = renderingOptions.polygonHeight;
            }


            if (height == 0f)
            {
                height = 0.05f;
            }
            polygon = builder.BuildPolygon(name, layer, height + offset);
            polygon.GetComponent <Renderer>().material = material;

            //}
            if (polygon == null)
            {
                yield break;
            }
            if (name == "")
            {
                name = "某大楼";
            }
            polygon.name = name;

            polygon.transform.parent = parent.transform;

            //Layer mask
            if (layer.useLayerMask == true)
            {
                tile.AddObjectToLayerMask(layer, polygon);
            }

            if (renderingOptions.tag.Length > 0)
            {
                polygon.tag = renderingOptions.tag;
            }
            Vector3 pos = polygon.transform.localPosition;

            if (layer.useRealHeight && roofMat != null)
            {
                roof                  = builder.CreateRoof();
                roof.name             = "roof";
                roof.transform.parent = polygon.transform;
                roof.GetComponent <MeshRenderer>().material = roofMat;
                roof.transform.position = new Vector3(roof.transform.position.x, height + 0.01f, roof.transform.position.z);
                roof.tag   = polygon.tag;
                roof.layer = polygon.layer;
                if (y < 1f)
                {
                    y = 0.02f;
                }
            }

            if (height > 1f)
            {
                polygon.AddComponent <BuildingCollider>().InitRoot(roof);
            }

            /* if (y > 0.45f)
             * {
             *   y = 0.01f;
             * }
             * else*/
            if (y == 0.2f || y == 0.096f || this.kind == GOFeatureKind.commercial || this.kind == GOFeatureKind.recreation_ground || this.kind == GOFeatureKind.attraction)
            {
                y = 0.02f;
            }
            else if (y == 0.098f)
            {
                y = 0.03f;
            }
            // y = y * Global.tilesizeRank;
            pos.y = y;
            //polygon.transform.position = pos;
            polygon.transform.localPosition = pos;

            GOFeatureBehaviour fb = polygon.AddComponent <GOFeatureBehaviour>();

            fb.goFeature = this;
            if (layer.OnFeatureLoad != null)
            {
                layer.OnFeatureLoad.Invoke(builder.mesh, layer, kind, builder.center);
            }

            if (delayedLoad)
            {
                yield return(null);
            }
        }