Example #1
0
    public static Mesh Stairwell(float stepWidth, float length, float floorHeight, float slabDepth, float separation, float slabThickness = 0.3f)
    {
        List <Mesh> meshes = new List <Mesh>();

        float hH = floorHeight / 2;
        float y  = 0;

        float stairLength = length - 2 * slabDepth;

        // STAIRS

        Mesh leftFlight  = MeshX.StairsBounds(stepWidth, hH, stairLength, true, 0.18f);
        Mesh rightFlight = MeshX.StairsBounds(stepWidth, hH, stairLength, true, 0.18f);

        leftFlight.Translate(new Vector3(0, y, slabDepth));

        rightFlight.Rotate(180, Vector3.up);
        rightFlight.Translate(new Vector3(stepWidth + separation, y + hH, length - slabDepth));

        // SLABS

        Mesh backSlab = MeshX.Cube(new Vector3(stepWidth * 2 + separation, slabThickness, slabDepth));

        backSlab.Translate(new Vector3((stepWidth + separation) / 2, y + hH - slabThickness / 2, length - (slabDepth / 2)));

        Mesh frontSlab = MeshX.Cube(new Vector3(stepWidth * 2 + separation, slabThickness, slabDepth));

        frontSlab.Translate(new Vector3((stepWidth + separation) / 2, y - slabThickness / 2, slabDepth / 2));

        meshes.Add(leftFlight);
        meshes.Add(rightFlight);
        meshes.Add(backSlab);
        meshes.Add(frontSlab);

        Mesh combined = MeshX.Combine(meshes.ToArray());

        return(combined);
    }
Example #2
0
    void OnValidate()
    {
        if (!Application.isPlaying)
        {
            return;
        }

        if (!stairWell)
        {
            if (!total)
            {
                gameObject.SetMesh(MeshX.Stairs(stairsNum, stepWidth, stepHeight, stepDepth));
            }
            else
            {
                gameObject.SetMesh(MeshX.StairsBounds(stepWidth, totalHeight, totalDepth));
            }
        }

        if (!stairWell)
        {
            return;
        }

        //floors = 1;

        if (floors < 1)
        {
            return;
        }

        Mesh combined = null;

        List <Mesh> meshes = new List <Mesh>();

        float hH = floorHeight / 2;

        for (int f = 0; f < floors; f++)
        {
            float y = f * floorHeight;


            Mesh leftFlight  = MeshX.StairsBounds(stepWidth, hH, totalDepth);
            Mesh rightFlight = MeshX.StairsBounds(stepWidth, hH, totalDepth);

            leftFlight.Translate(new Vector3(0, y));

            rightFlight.Rotate(180, Vector3.up);
            rightFlight.Translate(new Vector3(stepWidth + separation, y + hH, totalDepth));

            float slabThickness = 0.3f;

            Mesh slab = MeshX.Cube(new Vector3(stepWidth * 2 + separation, slabThickness, slabDepth));
            slab.Translate(new Vector3((stepWidth + separation) / 2, y + hH - slabThickness / 2, totalDepth + (slabDepth / 2)));


            meshes.Add(leftFlight);
            meshes.Add(rightFlight);
            meshes.Add(slab);
        }

        combined = MeshX.Combine(meshes.ToArray());
        gameObject.SetMesh(combined);
    }