예제 #1
0
    public void Generate()
    {
        if (lWallPoints.Count == 0 || rWallPoints.Count == 0)
        {
            GenerateWallPoints();
        }


        int startGen = GameManager.segmentPos - 2;
        int endGen   = GameManager.segmentPos + 8;

        if (startGen < 0)
        {
            startGen = 0;
        }
        if (endGen > Points.Count)
        {
            endGen = Points.Count;
        }
        if (endGen < 0)
        {
            endGen = 0;
        }

        List <Vector3> pointsforLeftMesh  = lWallPoints.GetRange(startGen, endGen - startGen);
        List <Vector3> pointsforRightMesh = rWallPoints.GetRange(startGen, endGen - startGen);

        MeshFilter   meshFilter   = walls[0].GetComponent <MeshFilter>();
        MeshCollider meshCollider = walls[0].GetComponent <MeshCollider>();

        if (meshFilter.sharedMesh == null)
        {
            meshFilter.sharedMesh = new Mesh();
        }
        Mesh mesh = new Mesh();

        CatmullRom.Extrude(mesh, shape, GetWallPath(pointsforLeftMesh));
        meshFilter.sharedMesh   = mesh;
        meshCollider.sharedMesh = mesh;

        meshFilter   = walls[1].GetComponent <MeshFilter>();
        meshCollider = walls[1].GetComponent <MeshCollider>();
        if (meshFilter.sharedMesh == null)
        {
            meshFilter.sharedMesh = new Mesh();
        }
        mesh = new Mesh();

        CatmullRom.Extrude(mesh, shape, GetWallPath(pointsforRightMesh));
        meshFilter.sharedMesh   = mesh;
        meshCollider.sharedMesh = mesh;
    }