public void updateTexture(string texPath) { texturePath = texPath; barrierMaterial = InGameTextureHandler.createMaterial(texPath, "", ""); if (type == BarrierType.fence) { var parentTransform = BarrierContainer.transform; foreach (Transform child in parentTransform) { if (child.name != "FencePole") { MeshRenderer renderer = child.GetComponent <MeshRenderer>(); renderer.material = barrierMaterial; } } } else { var parentTransform = BarrierContainer.transform; foreach (Transform child in parentTransform) { MeshRenderer renderer = child.GetComponent <MeshRenderer>(); renderer.material = barrierMaterial; } } }
private void createFacade(int facadeID, Node node1, Node node2, GameObject building) { GameObject facade = new GameObject("facade" + facadeID, typeof(MeshRenderer), typeof(MeshFilter), typeof(MeshCollider)); facade.tag = "Building"; facade.transform.parent = building.transform; facade.AddComponent <BuildingMouseHandler>(); Vector3[] vertices = { node1.meterPosition, node2.meterPosition, new Vector3(node2.meterPosition.x,equalizedBuildingHeight, node2.meterPosition.z), new Vector3(node1.meterPosition.x,equalizedBuildingHeight, node1.meterPosition.z) }; int[] triangles; if (!isClockwise) { triangles = new int[] { 1, 2, 3, 3, 0, 1 } } ; else { triangles = new int[] { 0, 3, 2, 2, 1, 0 } }; //Texture Size Horizontal float aa; //Texture Size Vertical float bb; bb = equalizedBuildingHeight - buildingHeight; // Min Height try { aa = (vertices[1] - vertices[0]).magnitude / defaultTextureWidth; } catch (Exception) { aa = 1.0f; } Vector2[] UVcoords = new Vector2[4]; if (isClockwise) { UVcoords[0] = new Vector2(0, (vertices[0].y - bb) / buildingHeight); UVcoords[1] = new Vector2(aa, (vertices[1].y - bb) / buildingHeight); UVcoords[2] = new Vector2(aa, 1); UVcoords[3] = new Vector2(0, 1); } else { UVcoords[0] = new Vector2(aa, (vertices[0].y - bb) / buildingHeight); UVcoords[1] = new Vector2(0, (vertices[1].y - bb) / buildingHeight); UVcoords[2] = new Vector2(0, 1); UVcoords[3] = new Vector2(aa, 1); } Geometry geo = new Geometry(); Vector3 facadeNormal; if (isClockwise) { facadeNormal = -1 * geo.findNormal(vertices[0], vertices[1], vertices[2]); } else { facadeNormal = geo.findNormal(vertices[0], vertices[1], vertices[2]); } Vector3[] normals = { facadeNormal, facadeNormal, facadeNormal, facadeNormal }; Mesh mesh = new Mesh(); mesh.vertices = vertices; mesh.uv = UVcoords; mesh.triangles = triangles; mesh.normals = normals; MeshFilter meshFilter = facade.GetComponent <MeshFilter>(); meshFilter.mesh = mesh; MeshRenderer meshRenderer = facade.GetComponent <MeshRenderer>(); int skinIndex = facadeSkins.FindIndex(o => o.facadeID == facadeID); if (skinIndex == -1) { meshRenderer.material = defaultMaterial; } else { meshRenderer.material = InGameTextureHandler.createMaterial(facadeSkins[skinIndex]); } MeshCollider meshCollider = facade.GetComponent <MeshCollider>(); meshCollider.sharedMesh = mesh; facades.Add(facade); }