Пример #1
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);
            }
        }
Пример #2
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);
            }
        }
Пример #3
0
        public IEnumerator Build(string name, GOFeature feature)
        {
            Profiler.BeginSample("[GOStreetName] text mesh settings");
            TextMesh textMesh = gameObject.GetComponent <TextMesh>();

            if (IsHebrew(name.ToCharArray()[0]))
            {
                textMesh.text = GOStreetName.Reverse(name);
            }
            else
            {
                textMesh.text = name;
            }

            GOStreetnamesSettings settings;

            switch (feature.goTile.mapType)
            {
            case GOMap.GOMapType.Nextzen:
            case GOMap.GOMapType.Mapbox:
                settings = feature.goTile.streetNames;
                break;

            default:
                settings = feature.labelsLayer.streetNames;
                break;
            }

            textMesh.color     = settings.streetnameColor; //new Color (settings.streetnameColor.r,color.g,color.b);
            textMesh.anchor    = TextAnchor.MiddleCenter;
            textMesh.alignment = TextAlignment.Center;

            textMesh.fontStyle = settings.fontStyle;
            textMesh.color     = settings.streetnameColor;
            float minimumFontSize = settings.minFontSize;

            textMesh.font          = settings.streetNameFont != null ? settings.streetNameFont : textMesh.font;
            textMesh.characterSize = settings.characterSize;
            textMesh.fontSize      = settings.fontSize;


            MeshRenderer renderer = GetComponent <MeshRenderer>();

            //			renderer.shadowCastingMode = feature.layer.castShadows;
            textLenght        = renderer.bounds.size.x;
            renderer.material = textMesh.font.material;
            Profiler.EndSample();

            if (feature.convertedGeometry.Count > 1)
            {
                Profiler.BeginSample("[GOStreetName] find middle point");
                GOSegment segment = feature.preloadedLabelData;           //GOSegment.FindTheLongestStreightSegment (feature.convertedGeometry, 0);
                transform.localPosition = segment.findMiddlePoint(0.04f); //LineCenter (road._verts);
                transform.localScale    = Vector3.one * 3;
                Profiler.EndSample();

                Profiler.BeginSample("[GOStreetName] find correct size");
                //Find correct size
                for (int i = textMesh.fontSize; i >= minimumFontSize - 1; i--)
                {
                    textMesh.fontSize = i;
                    float tl = renderer.bounds.size.x;
                    if (segment.distance >= tl)
                    {
                        break;
                    }
                    if (i == minimumFontSize - 1)
                    {
                        GameObject.DestroyImmediate(this.gameObject);
                        yield break;
                    }
                }
                Profiler.EndSample();

                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;
            }
            else if (feature.convertedGeometry.Count == 1)
            {
                transform.localPosition = feature.convertedGeometry[0];
                transform.localScale    = Vector3.one * 3;
                var rotation = transform.eulerAngles;
                rotation.x            = 90;
                transform.eulerAngles = rotation;
            }


            if (settings.textShader != null)
            {
                Material m = renderer.sharedMaterial;
                m.shader = settings.textShader;
                m.color  = textMesh.color;
            }


            yield return(null);
        }
Пример #4
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);
            }
        }