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); } }
public IEnumerator Build(string name) { 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(61 / 255.0f, 61 / 255.0f, 83 / 255f); 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.Destroy(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; yield return(null); }
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); } }