GameObject CreateRoadOutline(GameObject line, Material material, float width) { GameObject outline = new GameObject(line.name + "outline"); outline.transform.parent = line.transform; material.renderQueue = -((int)feature.sort - 1); GOLineMesh lineMesh = new GOLineMesh(feature.convertedGeometry); lineMesh.width = width; lineMesh.load(outline); mesh = lineMesh.mesh; mesh = SimpleExtruder.Extrude(mesh, outline, 0.05f); Vector2[] uvs2 = new Vector2[mesh.vertices.Length]; for (int i = 0; i < uvs2.Length; i++) { uvs2[i] = new Vector2(mesh.vertices[i].x, mesh.vertices[i].z); } mesh.uv = uvs2; mesh.RecalculateBounds(); outline.GetComponent <MeshFilter>().sharedMesh = mesh; Vector3 position = outline.transform.position; position.y = -0.01f; outline.transform.localPosition = position; outline.GetComponent <Renderer>().material = material; return(outline); }
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>(); } }
private void RenderRegion(string landId, Vector3 pos, Vector3 borderOffset, bool isSelected) { GameObject line = null; if (!regions.ContainsKey(landId)) { List <Vector3> figure = new List <Vector3> (); figure.Add(new Vector3(pos.x + borderOffset.x, 1f, pos.z - borderOffset.z)); figure.Add(new Vector3(pos.x - borderOffset.x, 1f, pos.z - borderOffset.z)); figure.Add(new Vector3(pos.x - borderOffset.x, 1f, pos.z + borderOffset.z)); figure.Add(new Vector3(pos.x + borderOffset.x, 1f, pos.z + borderOffset.z)); figure.Add(new Vector3(pos.x + borderOffset.x, 1f, pos.z - borderOffset.z)); line = new GameObject("Line " + pos); GOLineMesh lineMesh = new GOLineMesh(figure); lineMesh.width = 0.6f; lineMesh.load(line); GameObject textObj = Instantiate(landIdTextPrefab, new Vector3(pos.x, 1f, pos.z + borderOffset.z - 3f), Quaternion.Euler(90f, 0f, 0f), line.transform) as GameObject; textObj.GetComponent <TextMeshPro>().text = landId; regions.Add(landId, line); } else { line = regions[landId]; } if (isSelected) { line.GetComponent <MeshRenderer> ().material = regionBorderHighLight; } else { line.GetComponent <MeshRenderer> ().material = regionBorder; } if (isSelected && line.transform.position.y < 0.1f) { line.transform.Translate(new Vector3(0, 0.1f, 0)); } else if (!isSelected && line.transform.position.y >= 0.1f) { line.transform.Translate(new Vector3(0, -0.1f, 0)); } }