Exemplo n.º 1
0
        public void CreateBoundary()
        {
            var boundaryPoints = Config.BoundaryGeoData.GetPathInStreamingAssets().GetBoundaryPoints().AddTileIntersectionPoints();

            // Create vertices
            var wallVertices = new List <Vector3>();

            for (int p = 0; p < boundaryPoints.Length - 1; p++)
            {
                var point0 = boundaryPoints[p];
                var point1 = boundaryPoints[p + 1];

                wallVertices.Add(point0);
                wallVertices.Add(point1);
                wallVertices.Add(new Vector3(point0.x, point0.y + Config.BoundaryHeight, point0.z));
                wallVertices.Add(new Vector3(point1.x, point1.y + Config.BoundaryHeight, point1.z));
            }

            // Create faces
            var faces = new List <Face>();

            for (int f = 0; f < wallVertices.Count - 3; f += 4)
            {
                var faceVertices = new int[] { f, f + 1, f + 2, f + 1, f + 3, f + 2 };
                faces.Add(new Face(faceVertices));
            }

            var wall = ProBuilderMesh.Create(wallVertices, faces);

            Normals.CalculateNormals(wall);
            Normals.CalculateTangents(wall);
            Smoothing.ApplySmoothingGroups(wall, faces, 30);
            wall.ToMesh();
            wall.Refresh();
            EditorMeshUtility.Optimize(wall);

            var meshRenderer = wall.GetComponent <MeshRenderer>();

            meshRenderer.material          = Config.BoundaryMaterial;
            meshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
            meshRenderer.lightProbeUsage   = UnityEngine.Rendering.LightProbeUsage.Off;

            wall.gameObject.name = wall.name = Path.GetFileNameWithoutExtension(Config.BoundaryGeoData).Replace('_', ' ');
            wall.transform.SetParent(null, true);
        }