private GameObject GenerateFragment(PSPolygon polygon) { TerrainPiece piece = Instantiate(terrainPieceTemplate, gameObject.transform.position, gameObject.transform.rotation); var poly = new Polygon(); poly.Add(TerrainMesh.createContour(polygon.points)); var quality = new QualityOptions(); quality.MinimumAngle = 36; quality.MaximumAngle = 91; var imesh = poly.Triangulate(quality); List <Vector2> vertices = new List <Vector2>(); List <int> triangles = new List <int>(); getTriangles(imesh, ref vertices, ref triangles); var polygonBoundsCenter = polygon.Bounds.center; var doNotWrapUV = polygonBoundsCenter.x < 0 && polygonBoundsCenter.y < 0; var floorEdges = getFloorEdges(polygon); var uvs = vertices.Select(v => getUV(v, doNotWrapUV)).ToArray(); var uv2s = vertices.Select(v => getUV2(v, doNotWrapUV, floorEdges)).ToArray(); UpdateMesh( piece.GetComponent <MeshFilter>(), vertices.Select(v => (Vector3)v), uvs, uv2s, vertices.Select(p => (Color32)terrainTintColor(p, doNotWrapUV)), triangles); UpdateMesh( piece.background, vertices.Select(v => (Vector3)v), uvs, uv2s, vertices.Select(p => (Color32)backgroundTintColor(p, doNotWrapUV)), triangles); PolygonCollider2D collider = piece.gameObject.AddComponent <PolygonCollider2D>(); collider.SetPath(0, polygon.points); piece.terrainMesh = this; piece.doNotWrapUV = doNotWrapUV; piece.floorEdges = floorEdges; piece.gameObject.SetActive(true); return(piece.gameObject); }
private void Update() { if (sisterTeleport == null) { foreach (GameObject possibleSisterTeleporter in GameObject.FindGameObjectsWithTag("Environment")) { TerrainPiece sisterBeingChecked = possibleSisterTeleporter.GetComponent <TerrainPiece>(); if (sisterBeingChecked != null && sisterBeingChecked.teleporterGroup == teleporterGroup && sisterBeingChecked.gameObject != this.gameObject && (sisterBeingChecked.sender || sisterBeingChecked.receiver)) { sisterTeleport = sisterBeingChecked.GetComponent <TerrainPiece>(); } } } }
private void InitMaterial() { if (material == null) { var terrainMaterial = terrainMaterials[Random.Range(0, terrainMaterials.Count)]; terrainPieceTemplate.GetComponent <MeshRenderer>().sharedMaterial = terrainMaterial.piece; terrainPieceTemplate.background.GetComponent <MeshRenderer>().sharedMaterial = terrainMaterial.pieceBackground; caveBackground.GetComponent <MeshRenderer>().sharedMaterial = terrainMaterial.background; tintColorU = terrainMaterial.tintColorU; tintColorV = terrainMaterial.tintColorV; material = terrainMaterial.piece; mainTex = material.GetTexture("_MainTex") as Texture2D; mainTexOffset = material.GetTextureOffset("_MainTex"); mainTexScale = material.GetTextureScale("_MainTex"); overlayTex = material.GetTexture("_OverlayTex") as Texture2D; overlayTexOffset = material.GetTextureOffset("_OverlayTex"); overlayTexScale = material.GetTextureScale("_OverlayTex"); //tintColor = material.GetColor("_Color"); brightness = material.GetFloat("_Brightness"); } }