public void BuildLine(GameObject line, GOLayer layer, GORenderingOptions renderingOptions, GOMap map) { if (feature.convertedGeometry.Count == 2 && feature.convertedGeometry[0].Equals(feature.convertedGeometry[1])) { return; } if (renderingOptions.tag.Length > 0) { line.tag = renderingOptions.tag; } if (renderingOptions.material) { renderingOptions.material.renderQueue = -(int)feature.sort; } if (renderingOptions.outlineMaterial) { renderingOptions.outlineMaterial.renderQueue = -(int)feature.sort; } GOLineMesh lineMesh = new GOLineMesh(feature.convertedGeometry); lineMesh.width = renderingOptions.lineWidth * Global.tilesizeRank; lineMesh.load(line); mesh = lineMesh.mesh; mesh = SimpleExtruder.Extrude(mesh, line, 0.05f); line.GetComponent <MeshFilter>().sharedMesh = mesh; line.GetComponent <Renderer>().material = renderingOptions.material; Vector3 position = line.transform.position; position.y = feature.y * Global.tilesizeRank; line.transform.position = position; if (renderingOptions.outlineMaterial != null) { GameObject outline = CreateRoadOutline(line, renderingOptions.outlineMaterial, Global.tilesizeRank * (renderingOptions.lineWidth + layer.defaultRendering.outlineWidth)); if (layer.useColliders) { outline.AddComponent <MeshCollider>().sharedMesh = outline.GetComponent <MeshFilter>().sharedMesh; } outline.layer = line.layer; outline.tag = line.tag; } else if (layer.useColliders) { // Mesh m = gameObject.GetComponent<MeshFilter> ().sharedMesh; line.AddComponent <MeshCollider>(); } }
public GORenderingOptions GetRenderingOptions() { GORenderingOptions renderingOptions = layer.defaultRendering; foreach (GORenderingOptions r in layer.renderingOptions) { if (r.kind == kind) { defaultRendering = false; renderingOptions = r; break; } } return(renderingOptions); }
public Material GetMaterial(GORenderingOptions rendering, Vector3 center) { if (rendering.materials.Length > 0) { seed = (center.x + "/" + center.z).GetHashCode(); UnityEngine.Random.InitState(seed); int pick = UnityEngine.Random.Range(0, rendering.materials.Length); Material material = rendering.materials [pick]; return(material); } else { return(rendering.material); } }
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 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); } }