Beispiel #1
0
		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;

		}
Beispiel #2
0
        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);
            }
        }
        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);
            }
        }
Beispiel #4
0
        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);
            }
        }
Beispiel #5
0
        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);
            }
        }
Beispiel #6
0
        public IEnumerator Build(string name, Shader shader, Color color)
        {
            GOFeatureBehaviour road = transform.parent.GetComponent <GOFeatureBehaviour> ();

            GORoadSegment segment = GORoadSegment.FindTheLongestStreightSegment(road.goFeature.convertedGeometry, 0);

//			segment.DebugSegment ();

            transform.localPosition = segment.findMiddlePoint(0.01f);             //LineCenter (road._verts);
            transform.localScale    = Vector3.one * 3;

            TextMesh textMesh = gameObject.AddComponent <TextMesh> ();

            textMesh.text      = name;
            textMesh.color     = new Color(color.r, color.g, color.b);
            textMesh.anchor    = TextAnchor.MiddleCenter;
            textMesh.alignment = TextAlignment.Center;
            textMesh.fontStyle = FontStyle.Bold;
            textMesh.fontSize  = 15;

            float minimumFontSize = 12;

            textLenght = textMesh.GetComponent <Renderer>().bounds.size.x;

            //Find correct size
            for (int i = textMesh.fontSize; i >= minimumFontSize - 1; i--)
            {
                textMesh.fontSize = i;
                float tl = textMesh.GetComponent <Renderer>().bounds.size.x;
                if (segment.distance >= tl)
                {
                    break;
                }
                if (i == minimumFontSize - 1)
                {
                    GameObject.DestroyImmediate(this.gameObject);
                    yield break;
                }
            }

            var rotation = transform.eulerAngles;

            rotation.x = 90;

            Vector3 targetDir = segment.direction();

            if (targetDir.Equals(Vector3.zero))
            {
                rotation.y = 90;
            }
            else
            {
                Quaternion finalRotation = Quaternion.LookRotation(targetDir);
                rotation.y = finalRotation.eulerAngles.y + 90;

                rotation.y = (rotation.y % 360 + 360) % 360;

                if (rotation.y > 90 && rotation.y < 180)
                {
                    rotation.y -= 180;
                }
                else if (rotation.y > 0 && rotation.y < 90)
                {
                    rotation.y += 180;
                }
            }

            rot = rotation;
            transform.eulerAngles = rotation;

            if (shader != null)
            {
                MeshRenderer textMeshRenderer = GetComponent <MeshRenderer> ();
                Material     m = textMeshRenderer.sharedMaterial;
                m.shader = shader;
                m.color  = textMesh.color;
            }

            yield return(null);
        }
Beispiel #7
0
		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;

		}
Beispiel #8
0
        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);
            }
        }
Beispiel #9
0
        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);
            }
        }
Beispiel #10
0
        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);
            }
        }