public virtual IEnumerator BuildFeature(GOTile tile, bool delayedLoad) { if (goFeatureType == GOFeatureType.Undefined) { Debug.Log("type is null"); return(null); } try { if (goFeatureType == GOFeatureType.Line || goFeatureType == GOFeatureType.MultiLine || (goFeatureType != GOFeatureType.Point && goFeatureType != GOFeatureType.Label && !layer.isPolygon)) { return(CreateLine(tile, delayedLoad)); } else if (goFeatureType == GOFeatureType.Polygon || goFeatureType == GOFeatureType.MultiPolygon) { return(CreatePolygon(tile, delayedLoad)); } else if (goFeatureType == GOFeatureType.Point) { return(CreatePoi(tile, delayedLoad)); } else if (goFeatureType == GOFeatureType.Label) { return(CreateLabel(tile, delayedLoad)); } else { return(null); } } catch (Exception ex) { Debug.Log("[GOFeature] Catched exception: " + ex); return(null); } }
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); Vector3[] meshverts = mesh.vertices; Vector2[] uvs = new Vector2[meshverts.Length]; for (int i = 0; i < uvs.Length; i++) { uvs [i] = new Vector2(meshverts [i].x, meshverts [i].z); } mesh.uv = uvs; filter.sharedMesh = mesh; tile.gameObject.AddComponent <MeshCollider> (); renderer.material = tileBackground; }
IEnumerator downloadMapData(Coordinates worldOrigin) { //Get the list of tile coordinates to download. List <Vector2> adiacentTiles = worldOrigin.adiacentNTiles(locationManager.zoomLevel, tileBuffer); //Update the max slider value slider.maxValue = adiacentTiles.Count; sliderLabel.text = "Downloading map data..."; //Create a GOTile obejct for each tile coordinates pair foreach (Vector2 tileCoords in adiacentTiles) { GOTile tile = createSmartTileObject(tileCoords, locationManager.zoomLevel); tile.PrepareGoTile(); //Download tile data yield return(StartCoroutine(tile.goTile.downloadData(this))); slider.value++; Debug.Log(string.Format("[GOMap Loading Scene] Tiles Downloaded {0}/{1}", slider.value, slider.maxValue)); Object.Destroy(tile.gameObject); } Debug.Log(string.Format("[GOMap Loading Scene] All tiles Downloaded, load scene: {0}", nextSceneName)); //Load new scene, the data is now stored in the GOMap cache folder and will be automatically reused by the next scene. //That means no API waiting time in the game scene. if (!string.IsNullOrEmpty(nextSceneName)) { SceneManager.LoadScene(nextSceneName); } yield return(null); }
public IEnumerator DestroyTiles(List <Vector2> list) { try { List <string> tileListNames = new List <string> (); foreach (Vector2 v in list) { string s = tilenameFormat(v); tileListNames.Add(s); // Debug.Log ("Tile list name: "+s); } List <GOTile> toDestroy = new List <GOTile> (); foreach (GOTile tile in tiles) { if (!tileListNames.Contains(tile.name)) { toDestroy.Add(tile); } } for (int i = 0; i < toDestroy.Count; i++) { GOTile tile = toDestroy [i]; tiles.Remove(tile); GameObject.Destroy(tile.gameObject, i); } } catch { } yield return(null); }
IEnumerator CreatePoi(GOTile tile, bool delayedLoad) { if (poiRendering == null) { yield break; } GameObject poi = GameObject.Instantiate (poiRendering.prefab); #if GOLINK poiGeometry.y = GoTerrain.GOTerrain.RaycastAltitudeForVector(poiGeometry); #endif poi.transform.localPosition = poiGeometry; poi.transform.parent = parent.transform; poi.name = name; //Layer mask if (poiLayer.useLayerMask == true) { tile.AddObjectToLayerMask (layer, poi); } GOFeatureBehaviour fb = poi.AddComponent<GOFeatureBehaviour> (); fb.goFeature = this; if (poiRendering.OnPoiLoad != null) { poiRendering.OnPoiLoad.Invoke(this); } if (delayedLoad) yield return null; }
IEnumerator DestroyTiles(List <Vector2> list) { try { List <string> tileListNames = new List <string> (); foreach (Vector2 v in list) { tileListNames.Add(v.x + "-" + v.y + "-" + zoomLevel); } List <GOTile> toDestroy = new List <GOTile> (); foreach (GOTile tile in tiles) { if (!tileListNames.Contains(tile.name)) { toDestroy.Add(tile); } } for (int i = 0; i < toDestroy.Count; i++) { GOTile tile = toDestroy [i]; tiles.Remove(tile); GameObject.Destroy(tile.gameObject, i); } } catch { } yield return(null); }
public IEnumerator DestroyTiles(List <Vector2> list) { try { List <string> tileListNames = new List <string> (); foreach (Vector2 v in list) { string s = GOTileObj.TileNamePrototype(v, zoomLevel); tileListNames.Add(s); } List <GOTile> toDestroy = new List <GOTile> (); foreach (GOTile tile in tiles) { if (tile != null && !tileListNames.Contains(tile.name) && tile.goTile.status == GOTileObj.GOTileStatus.Done) { Debug.Log(tile.goTile.status.ToString()); toDestroy.Add(tile); } } for (int i = 0; i < toDestroy.Count; i++) { GOTile tile = toDestroy [i]; tiles.Remove(tile); GameObject.Destroy(tile.gameObject, i); } } catch (Exception ex) { Debug.LogWarning(ex); } yield return(null); }
public IEnumerator ReloadMap(Coordinates location, bool delayed) { if (!dynamicLoad) { yield break; } //Get SmartTiles List <Vector2> tileList = location.adiacentNTiles(zoomLevel, tileBuffer); List <GOTile> newTiles = new List <GOTile> (); // Create new tiles foreach (Vector2 tileCoords in tileList) { if (!isSmartTileAlreadyCreated(tileCoords, zoomLevel)) { GOTile adiacentSmartTile = createSmartTileObject(tileCoords, zoomLevel); adiacentSmartTile.tileCenter = new Coordinates(tileCoords, zoomLevel); adiacentSmartTile.diagonalLenght = adiacentSmartTile.tileCenter.diagonalLenght(zoomLevel); adiacentSmartTile.gameObject.transform.position = adiacentSmartTile.tileCenter.convertCoordinateToVector(); newTiles.Add(adiacentSmartTile); if (tileBackground != null) { CreateTileBackground(adiacentSmartTile); } } } foreach (GOTile tile in newTiles) { if (OnTileLoad != null) { OnTileLoad.Invoke(tile); } #if !UNITY_WEBPLAYER // if (tile != null && FileHandler.Exist (tile.gameObject.name) && useCache) { if (Application.isPlaying) { yield return(tile.StartCoroutine(tile.LoadTileData(this, tile.tileCenter, zoomLevel, layers, delayed))); } else { GORoutine.start(tile.LoadTileData(this, tile.tileCenter, zoomLevel, layers, delayed), tile); } // } else { // tile.StartCoroutine(tile.LoadTileData(this, tile.tileCenter, zoomLevel,layers,delayed)); // } #endif } //Destroy far tiles List <Vector2> tileListForDestroy = location.adiacentNTiles(zoomLevel, tileBuffer + 1); yield return(StartCoroutine(DestroyTiles(tileListForDestroy))); }
public IEnumerator ReloadMap(Coordinates location, bool delayed) { if (!dynamicLoad) { yield break; } GOFeature.BuildingElevationOffset *= locationManager.worldScale; GOFeature.RoadsHeightForElevation *= locationManager.worldScale; //Get SmartTiles List <Vector2> tileList = location.adiacentNTiles(zoomLevel, tileBuffer); List <GOTile> newTiles = new List <GOTile> (); // Create new tiles foreach (Vector2 tileCoords in tileList) { if (!isSmartTileAlreadyCreated(tileCoords, zoomLevel)) { GOTile adiacentSmartTile = createSmartTileObject(tileCoords, zoomLevel); adiacentSmartTile.gameObject.transform.position = adiacentSmartTile.goTile.tileCenter.convertCoordinateToVector(); adiacentSmartTile.map = this; newTiles.Add(adiacentSmartTile); if (tileBackground != null) { adiacentSmartTile.createTileBackground(); } } } foreach (GOTile tile in newTiles) { if (Application.isPlaying) { yield return(tile.StartCoroutine(tile.LoadTileData(layers, delayed))); } else { GORoutine routine = GORoutine.start(tile.LoadTileData(layers, delayed), tile); while (!routine.finished) { yield return(null); } } } //Destroy far tiles List <Vector2> tileListForDestroy = location.adiacentNTiles(zoomLevel, tileBuffer + 1); if (destroyTilesRoutine != null) { yield return(destroyTilesRoutine); } destroyTilesRoutine = DestroyTiles(tileListForDestroy); yield return(StartCoroutine(destroyTilesRoutine)); }
public virtual IEnumerator CreateLine(GOTile tile, bool delayedLoad) { GORenderingOptions renderingOptions = GetRenderingOptions(); if (renderingOptions.lineWidth == 0) { yield break; } GOFeatureMeshBuilder builder = new GOFeatureMeshBuilder(this); featureCenter = builder.center; GameObject line = null; if (preloadedMeshData != null) { line = builder.BuildLineFromPreloaded(this, tile.map, parent); } if (line == null) { yield break; } line.name = name != null? name:kind.ToString(); //Layer mask if (layer.useLayerMask == true) { tile.AddObjectToLayerMask(layer, line); } if (goTile.addGoFeatureComponents) { GOFeatureBehaviour fb = line.AddComponent <GOFeatureBehaviour> (); fb.goFeature = this; } //Mapzen Streetnames if (goTile.mapType == GOMap.GOMapType.Mapzen_Legacy && layer.layerType == GOLayer.GOLayerType.Roads && name != null && name.Length > 0 && goTile.useStreetnames && !isLoop && !goTile.useElevation) { GOStreetName streetName = GameObject.Instantiate(goTile.streetnamePrototype, line.transform).GetComponent <GOStreetName>(); streetName.gameObject.name = name + "_streetname"; yield return(tile.StartCoroutine(streetName.Build(name, this))); } if (layer.OnFeatureLoad != null) { layer.OnFeatureLoad.Invoke(this, line); } if (delayedLoad) { yield return(null); } }
GOTile createSmartTileObject(Vector2 tileCoords, int Zoom) { GameObject tileObj = new GameObject(tileCoords.x + "-" + tileCoords.y + "-" + zoomLevel); tileObj.transform.parent = gameObject.transform; GOTile tile = tileObj.AddComponent <GOTile> (); tiles.Add(tile); return(tile); }
void OnTileLoad(GOTile goTile) { slider.value++; Debug.Log(string.Format("[GOMap Loading Screen] Tiles Loaded {0}/{1}", slider.value, slider.maxValue)); if (slider.value.Equals(slider.maxValue)) { StartCoroutine(slideOutLoadingScreen()); Object.Destroy(gameObject, 1); } }
bool TileFilter(GOTile tile, Coordinates coordinates) { Vector2 tileCoordinates = coordinates.tileCoordinates(goMap.zoomLevel); if (tile.goTile.tileCoordinates.Equals(tileCoordinates)) { return(true); } // Debug.LogWarning ("Coordinates outside the tile"); return(false); }
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); if (preloadedMeshData != null) { builder.BuildLineFromPreloaded(line, this, tile.map); } else if (tile.map.mapType == GOMap.GOMapType.MapzenJson) { 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 = ""; streetName.transform.SetParent(line.transform); yield return(tile.StartCoroutine(streetName.Build(name, tile.map.textShader, tile.map.streetnameColor))); } if (layer.OnFeatureLoad != null) { layer.OnFeatureLoad.Invoke(builder.mesh, layer, kind, builder.center); } if (delayedLoad) { yield return(null); } }
public void OnTileLoad(GOTile tile) { foreach (GOEnvironmentKind kind in floatingEnvironment) { if (Application.isPlaying) { StartCoroutine(SpawnPrefabsInTile(tile, tile.gameObject, kind)); } else { GORoutine.start(SpawnPrefabsInTile(tile, tile.gameObject, kind), this); } } }
public void SpawnBallons(GOTile tile) { int spawn = Random.Range(0, 2); if (spawn == 0) { // if (true) { 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; } }
IEnumerator CreateLabel(GOTile tile, bool delayedLoad) { GameObject label = GameObject.Instantiate(goTile.streetnamePrototype); //Mapzen Streetnames if (name != null && name.Length > 0 && !goTile.useElevation) { GOStreetName streetName = label.GetComponent <GOStreetName>(); streetName.gameObject.name = name + "_streetname"; yield return(tile.StartCoroutine(streetName.Build(name, this))); } if (label == null) { yield break; } Vector3 pos = label.transform.position; pos.y = y; label.transform.position = pos; label.transform.SetParent(parent.transform); //Layer mask if (labelsLayer.useLayerMask == true) { tile.AddObjectToLayerMask(layer, label); } if (goTile.addGoFeatureComponents) { GOFeatureBehaviour fb = label.AddComponent <GOFeatureBehaviour> (); fb.goFeature = this; } if (labelsLayer.OnLabelLoad != null) { labelsLayer.OnLabelLoad.Invoke(this, label); } if (delayedLoad) { yield return(null); } }
IEnumerator CreatePoi(GOTile tile, bool delayedLoad) { if (poiRendering == null) { yield break; } GameObject poi = GameObject.Instantiate(poiRendering.prefab); #if GOLINK poiGeometry.y = GoTerrain.GOTerrain.RaycastAltitudeForVector(poiGeometry); #endif poiGeometry.y += poi.transform.position.y; poiGeometry.y *= goTile.worldScale; poi.transform.position = poiGeometry; poi.transform.SetParent(parent.transform); poi.name = name; // Debug.Log ("Load POI: "+ name); //Layer mask if (poiLayer.useLayerMask == true) { tile.AddObjectToLayerMask(layer, poi); } if (goTile.addGoFeatureComponents) { GOFeatureBehaviour fb = poi.AddComponent <GOFeatureBehaviour> (); fb.goFeature = this; } if (poiRendering.OnPoiLoad != null) { poiRendering.OnPoiLoad.Invoke(this, poi); } if (delayedLoad) { yield return(null); } }
public IEnumerator createTileWithPreloadedData(Vector2 tileCoords, int Zoom, bool delayedLoad, object mapData) { #if GOLINK switch (goTerrain.goTerrainOptions.vectorAPI) { case GOTerrainOptions.VectorAPI.MapzenJSON: mapType = GOMapType.MapzenJson; break; case GOTerrainOptions.VectorAPI.Mapzen: mapType = GOMapType.Mapzen; break; case GOTerrainOptions.VectorAPI.Mapbox: mapType = GOMapType.Mapbox; break; } #endif if (!isSmartTileAlreadyCreated(tileCoords, zoomLevel)) { GOTile goTile = createSmartTileObject(tileCoords, zoomLevel); goTile.tileCoordinates = tileCoords; goTile.tileCenter = new Coordinates(tileCoords, zoomLevel); goTile.diagonalLenght = goTile.tileCenter.diagonalLenght(zoomLevel); goTile.gameObject.transform.position = goTile.tileCenter.convertCoordinateToVector(); goTile.mapData = mapData; goTile.map = this; if (tileBackground != null) { CreateTileBackground(goTile); } if (OnTileLoad != null) { OnTileLoad.Invoke(goTile); } yield return(goTile.StartCoroutine(goTile.ParseTileData(this, goTile.tileCenter, Zoom, layers, delayedLoad, layerNames()))); } yield return(null); }
private void CreateTileBackground(GOTile tile) { MeshFilter filter = tile.gameObject.AddComponent <MeshFilter>(); MeshRenderer renderer = tile.gameObject.AddComponent <MeshRenderer>(); tile.vertices = tile.tileCenter.tileVertices(zoomLevel); 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.mesh = mesh; renderer.material = tileBackground; }
public IEnumerator SpawnPrefabsInTile(GOTile tile, GameObject parent, GOEnvironmentKind kind) { if (tile == null) { yield break; } float rate = Mathf.FloorToInt(tile.goTile.diagonalLenght * (kind.density / 100)); for (int i = 0; i <= rate; i++) { float randomX = UnityEngine.Random.Range(tile.goTile.getXRange().x, tile.goTile.getXRange().y); float randomZ = UnityEngine.Random.Range(tile.goTile.getZRange().x, tile.goTile.getZRange().y); float randomY = UnityEngine.Random.Range(200, 320); int n = UnityEngine.Random.Range(0, kind.prefabs.Length); Vector3 pos = new Vector3(randomX, randomY, randomZ); pos.y += kind.prefabs [n].transform.position.y; pos.y += GOMap.AltitudeForPoint(pos); var rotation = kind.prefabs [n].transform.eulerAngles; var randomRotation = new Vector3(0, UnityEngine.Random.Range(0, 360), 0); GameObject obj = (GameObject)GameObject.Instantiate(kind.prefabs[n], pos, Quaternion.Euler(rotation + randomRotation)); obj.transform.parent = parent.transform; obj.transform.position = pos; if (Application.isPlaying) { yield return(null); } } yield return(null); }
public virtual IEnumerator BuildFeature (GOTile tile, bool delayedLoad) { if (goFeatureType == GOFeatureType.Undefined) { Debug.Log ("type is null"); return null; } try { if (goFeatureType == GOFeatureType.Line || goFeatureType == GOFeatureType.MultiLine) { return CreateLine (tile,delayedLoad); } else if (goFeatureType == GOFeatureType.Polygon || goFeatureType == GOFeatureType.MultiPolygon){ return CreatePolygon (tile,delayedLoad); } else if (goFeatureType == GOFeatureType.Point){ return CreatePoi (tile,delayedLoad); } else return null; } catch (Exception ex) { Debug.Log ("[GOFeature] Catched exception: " + ex); return null; } }
void OnLoadTile(GOTile tile) { StartCoroutine(NearbySearch(tile)); }
void OnLoadTile(GOTile tile) { string url = baseUrl + "&ll=" + tile.goTile.tileCenter.latitude + "," + tile.goTile.tileCenter.longitude + "&radius=" + tile.goTile.diagonalLenght / 2 + "&categoryId=" + categoryID + "&oauth_token=" + oauth_token; StartCoroutine(LoadPlaces(url)); }
IEnumerator CreatePoi(GOTile tile, bool delayedLoad) { if (poiRendering == null && tileSetPoiRendering == null) { yield break; } int unityLayer; GOFeatureEvent featureEvent; GameObject prefab; string tag; if (poiRendering != null) { prefab = poiRendering.prefab; unityLayer = (int)poiLayer.unityLayer; featureEvent = poiRendering.OnPoiLoad; tag = poiRendering.tag; } else { prefab = tileSetPoiRendering.prefab; unityLayer = (int)tilesetLayer.unityLayer; featureEvent = tileSetPoiRendering.OnPoiLoad; tag = tileSetPoiRendering.tag; } GameObject poi = GameObject.Instantiate(prefab); #if GOLINK poiGeometry.y = GoTerrain.GOTerrain.RaycastAltitudeForVector(poiGeometry); #endif poiGeometry.y += poi.transform.position.y; poiGeometry.y *= goTile.worldScale; poi.transform.position = poiGeometry; poi.transform.SetParent(parent.transform); poi.name = name; if (!string.IsNullOrEmpty(tag)) { poi.transform.tag = tag; } // Debug.Log ("Load POI: "+ name); //Layer mask poi.layer = unityLayer; if (goTile.addGoFeatureComponents) { GOFeatureBehaviour fb = poi.AddComponent <GOFeatureBehaviour>(); fb.goFeature = this; } if (featureEvent != null) { featureEvent.Invoke(this, poi); } if (delayedLoad) { yield return(null); } }
public virtual IEnumerator CreateLine(GOTile tile, bool delayedLoad) { //if () //GORenderingOptions renderingOptions = GetRenderingOptions(); float lineWidth; int unityLayer; GOFeatureEvent goFeatureEvent; if (layer != null) { lineWidth = renderingOptions.lineWidth; unityLayer = layer.unityLayer; goFeatureEvent = layer.OnFeatureLoad; } else { lineWidth = tileSetLineRendering.witdh; unityLayer = tilesetLayer.unityLayer; goFeatureEvent = tilesetLayer.OnFeatureLoad; } if (lineWidth == 0) { yield break; } GOFeatureMeshBuilder builder = new GOFeatureMeshBuilder(this); featureCenter = builder.center; GameObject line = null; if (preloadedMeshData != null) { line = builder.BuildLineFromPreloaded(this, tile.map, parent); } if (line == null) { yield break; } line.name = name != null ? name : kind.ToString(); //Layer mask line.layer = unityLayer; if (goTile.addGoFeatureComponents) { GOFeatureBehaviour fb = line.AddComponent <GOFeatureBehaviour>(); fb.goFeature = this; } //Mapzen Streetnames if ((goTile.mapType == GOMap.GOMapType.Nextzen || goTile.mapType == GOMap.GOMapType.Mapbox) && layer != null && layer.layerType == GOLayer.GOLayerType.Roads && name != null && name.Length > 0 && goTile.useStreetnames && !isLoop && !goTile.useElevation) { GOStreetName streetName = GameObject.Instantiate(goTile.streetnamePrototype, line.transform).GetComponent <GOStreetName>(); streetName.gameObject.name = name + "_streetname"; yield return(tile.StartCoroutine(streetName.Build(name, this))); } if (goFeatureEvent != null) { goFeatureEvent.Invoke(this, line); } if (delayedLoad) { yield return(null); } }
IEnumerator NearbySearch(GOTile tile) { //Center of the map tile Coordinates tileCenter = tile.goTile.tileCenter; //radius of the request, equals the tile diagonal /2 float radius = tile.goTile.diagonalLenght / 2; //The complete nearby search url, api key is added at the end string url = nearbySearchUrl + "location=" + tile.goTile.tileCenter.latitude + "," + tile.goTile.tileCenter.longitude + "&radius=" + radius + "&type=" + type + "&key=" + googleAPIkey; //Perform the request var www = UnityWebRequest.Get(url); yield return(www.SendWebRequest()); //Check for errors if (string.IsNullOrEmpty(www.error)) { string response = www.downloadHandler.text; //Deserialize the json response IDictionary deserializedResponse = (IDictionary)Json.Deserialize(response); Debug.Log(string.Format("[GO Places] Tile center: {0} - Request Url {1} - response {2}", tileCenter.toLatLongString(), url, response)); //That's our list of Places IList results = (IList)deserializedResponse ["results"]; //Create a container for the places and set it as a tile child. In this way when the tile is destroyed it will take also the places with it. GameObject placesContainer = new GameObject("Places"); placesContainer.transform.SetParent(tile.transform); foreach (IDictionary result in results) { string placeID = (string)result["place_id"]; string name = (string)result["name"]; IDictionary location = (IDictionary)((IDictionary)result ["geometry"])["location"]; double lat = (double)location ["lat"]; double lng = (double)location ["lng"]; //Create a new coordinate object, with the desired lat lon Coordinates coordinates = new Coordinates(lat, lng, 0); if (!TileFilter(tile, coordinates)) { continue; } //Instantiate your game object GameObject place = GameObject.Instantiate(prefab); place.SetActive(true); //Convert coordinates to position Vector3 position = coordinates.convertCoordinateToVector(place.transform.position.y); if (goMap.useElevation) { position = GOMap.AltitudeToPoint(position); } //Set the position to object place.transform.localPosition = position; //the parent place.transform.SetParent(placesContainer.transform); //and the name place.name = (name != null && name.Length > 0)? name:placeID; if (addGOPlaceComponent) { GOPlacesPrefab component = place.AddComponent <GOPlacesPrefab> (); component.placeInfo = result; component.goPlaces = this; } } } }
public virtual IEnumerator CreatePolygon(GOTile tile, bool delayedLoad) { // // if (layer.layerType == GOLayer.GOLayerType.Buildings && name != "Whitehall Building Annex") // yield break; Profiler.BeginSample("[GOFeature] CreatePolygon ALLOC"); GOFeatureMeshBuilder builder = new GOFeatureMeshBuilder(this); this.featureCenter = new Vector3(2, builder.center.y, 8); //new Vector3 (builder.center.x, builder.center.y, builder.center.z); Profiler.EndSample(); Material material = null; Material roofMat = null; if (layer.layerType == GOLayer.GOLayerType.Buildings && defaultRendering && renderingOptions.materials.Length != 0) { Profiler.BeginSample("[GOFeature] CreatePolygon Center"); GOCenterContainer centerContainer = tile.findNearestCenter(builder.center, parent); Profiler.EndSample(); if (centerContainer.material == null) { Profiler.BeginSample("[GOFeature] CreatePolygon Material"); centerContainer.material = tile.GetMaterial(renderingOptions, builder.center); centerContainer.secondaryMaterial = renderingOptions.roofMaterial; Profiler.EndSample(); } material = centerContainer.material; roofMat = centerContainer.secondaryMaterial; } else { Profiler.BeginSample("[GOFeature] CreatePolygon Material"); //Materials material = tile.GetMaterial(renderingOptions, builder.center); roofMat = renderingOptions.roofMaterial; Profiler.EndSample(); } if (sort != 0) { if (material) { material.renderQueue = -(int)sort; } if (roofMat) { roofMat.renderQueue = -(int)sort; } } if (!layer.useRealHeight) { height = renderingOptions.polygonHeight; } float offset = 0; float trueHeight = height; if (goTile.useElevation && layer.layerType == GOLayer.GOLayerType.Buildings) { trueHeight += BuildingElevationOffset; offset = BuildingElevationOffset; if (y < offset) { y = highestAltitudeVertex - offset + 0.5f; } // y = goTile.altitudeForPoint(builder.center)-offset+0.5f; } Profiler.BeginSample("[GOFeature] CreatePolygon MESH"); GameObject polygon = null; if (preloadedMeshData != null) { polygon = builder.BuildPolygonFromPreloaded(this, parent); } Profiler.EndSample(); if (polygon == null) { yield break; } polygon.name = name; //Layer mask if (layer.useLayerMask == true) { tile.AddObjectToLayerMask(layer, polygon); } if (renderingOptions.tag.Length > 0) { polygon.tag = renderingOptions.tag; } if (renderingOptions.hasRoof) { Material[] mats = new Material[2]; mats [0] = material; mats [1] = roofMat; MeshRenderer mr = polygon.GetComponent <MeshRenderer> (); mr.shadowCastingMode = layer.castShadows; mr.materials = mats; } else { builder.meshRenderer.material = material; builder.meshRenderer.shadowCastingMode = layer.castShadows; } Profiler.BeginSample("[GOFeature] TRANSFORM"); Vector3 pos = polygon.transform.position; pos.y = y; if (layer.layerType == GOLayer.GOLayerType.Buildings) { y += GOFeatureMeshBuilder.Noise(); } polygon.transform.position = pos; polygon.transform.localPosition = pos; if (goTile.addGoFeatureComponents) { GOFeatureBehaviour fb = polygon.AddComponent <GOFeatureBehaviour> (); fb.goFeature = this; } if (layer.OnFeatureLoad != null) { layer.OnFeatureLoad.Invoke(this, polygon); } Profiler.EndSample(); preloadedMeshData = null; if (delayedLoad) { yield return(null); } }
void OnLoadTile(GOTile tile) { string url = baseUrl + "location=" + tile.tileCenter.latitude + "," + tile.tileCenter.longitude + "&radius=" + tile.diagonalLenght / 2 + "&type=" + type + "&key=" + googleAPIkey; StartCoroutine(LoadPlaces(url)); }
public virtual IEnumerator CreatePolygon (GOTile tile, bool delayedLoad) { Profiler.BeginSample ("[GOFeature] CreatePolygon ALLOC"); GOFeatureMeshBuilder builder = new GOFeatureMeshBuilder(this); Profiler.EndSample (); Profiler.BeginSample ("[GOFeature] CreatePolygon Material"); //Materials Material material = tile.GetMaterial(renderingOptions,builder.center); Material roofMat = renderingOptions.roofMaterial; if (sort != 0) { if (material) material.renderQueue = -(int)sort; if (roofMat) roofMat.renderQueue = -(int)sort; } Profiler.EndSample (); Profiler.BeginSample ("[GOFeature] CreatePolygon Center"); //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; } Profiler.EndSample(); if (!layer.useRealHeight) { height = renderingOptions.polygonHeight; } int offset = 0; float trueHeight = height; #if GOLINK if (GOMap.GOLink) { trueHeight += BuildingElevationOffset; //[GOLINK] GOTerrain link (This requires GOTerrain! https://www.assetstore.unity3d.com/#!/content/84198) if (tile.map.goTerrain != null) { offset = BuildingElevationOffset; if (y < offset) y = tile.map.goTerrain.FindAltitudeForVector(builder.center)-offset; } } #endif Profiler.BeginSample ("[GOFeature] CreatePolygon MESH"); GameObject polygon = null; if (preloadedMeshData != null) polygon = builder.BuildPolygonFromPreloaded(this); else if (tile.map.mapType == GOMap.GOMapType.MapzenJson) //ONLY FOR JSON polygon = builder.BuildPolygon(layer,trueHeight+offset); Profiler.EndSample (); if (polygon == null) yield break; 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; } if (layer.useRealHeight && roofMat != null) { Profiler.BeginSample ("[GOFeature] CreatePolygon ROOF"); GameObject roof; if (preloadedMeshData != null && preloadedMeshData.secondaryMesh != null) roof = builder.CreateRoofFromPreloaded (preloadedMeshData.secondaryMesh); else 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,trueHeight+0.11f,roof.transform.position.z); roof.tag = polygon.tag; roof.layer = polygon.layer; Profiler.EndSample (); } Profiler.BeginSample ("[GOFeature] TRANSFORM"); Vector3 pos = polygon.transform.position; pos.y = y; if (layer.layerType == GOLayer.GOLayerType.Buildings) y += GOFeatureMeshBuilder.Noise (); polygon.transform.position = pos; polygon.transform.localPosition = pos; GOFeatureBehaviour fb = polygon.AddComponent<GOFeatureBehaviour> (); fb.goFeature = this; builder.meshRenderer.material = material; if (layer.OnFeatureLoad != null) { layer.OnFeatureLoad.Invoke(builder.mesh,layer,kind, builder.center); } Profiler.EndSample (); preloadedMeshData = null; if (delayedLoad) yield return null; }