Class ProceduralMeshBuilder
- Namespace
- S1MAPI.ProceduralMesh
- Assembly
- S1MAPI_Mono.dll
High-level fluent builder for creating procedural meshes. Provides a chainable API for constructing meshes from basic shapes.
public sealed class ProceduralMeshBuilder
- Inheritance
-
ProceduralMeshBuilder
- Inherited Members
Remarks
Use the builder pattern to add shapes, configure materials, then call Build() to create the final mesh. Unity automatically handles cleanup on scene unload and application quit.
Constructors
ProceduralMeshBuilder(string)
Create a new procedural mesh builder.
public ProceduralMeshBuilder(string name)
Parameters
namestringName for the generated mesh
Exceptions
- ArgumentNullException
Thrown when name is null or empty
Methods
AddBox(Vector3, Vector3)
Add a box (cube) to the mesh.
public ProceduralMeshBuilder AddBox(Vector3 center, Vector3 size)
Parameters
centerVector3Center position of the box
sizeVector3Size of the box
Returns
- ProceduralMeshBuilder
This builder for method chaining
AddCapsule(Vector3, Vector3, float)
Add a capsule to the mesh.
public ProceduralMeshBuilder AddCapsule(Vector3 start, Vector3 end, float radius)
Parameters
startVector3Start position (bottom)
endVector3End position (top)
radiusfloatRadius of the capsule
Returns
- ProceduralMeshBuilder
This builder for method chaining
AddCylinder(Vector3, Vector3, float, int)
Add a cylinder to the mesh.
public ProceduralMeshBuilder AddCylinder(Vector3 start, Vector3 end, float radius, int segments = 12)
Parameters
startVector3Start position (bottom center)
endVector3End position (top center)
radiusfloatRadius of the cylinder
segmentsintNumber of radial segments
Returns
- ProceduralMeshBuilder
This builder for method chaining
AddSphere(Vector3, float, int)
Add a sphere to the mesh.
public ProceduralMeshBuilder AddSphere(Vector3 center, float radius, int subdivisions = 8)
Parameters
centerVector3Center position of the sphere
radiusfloatRadius of the sphere
subdivisionsintNumber of subdivisions (higher = smoother)
Returns
- ProceduralMeshBuilder
This builder for method chaining
ApplyFlatShading()
Apply flat shading when building the mesh. Creates a low-poly aesthetic with hard edges.
public ProceduralMeshBuilder ApplyFlatShading()
Returns
- ProceduralMeshBuilder
This builder for method chaining
Build()
Build a GameObject with the mesh and material applied.
public GameObject Build()
Returns
- GameObject
The created GameObject with mesh components
BuildMesh()
Build the mesh and return it.
public Mesh BuildMesh()
Returns
- Mesh
The constructed mesh
SetColor(Color)
Set a solid color for the mesh (creates a material internally).
public ProceduralMeshBuilder SetColor(Color color)
Parameters
colorColorThe color to apply
Returns
- ProceduralMeshBuilder
This builder for method chaining
SetMaterial(Material)
Set the material for the generated mesh.
public ProceduralMeshBuilder SetMaterial(Material material)
Parameters
materialMaterialThe material to apply
Returns
- ProceduralMeshBuilder
This builder for method chaining