Preview
Asset is in development, documentation is a draft
5.Scripting
Whenever using the API, ensure you add using sc.splines.mesher.runtime; to include the namespace.
Callbacks
Both the Spline Curve Mesher and Spline Fill Mesher components and classes expose two triggers, designed to facilitate custom functionality. For instance, you may want to execute certain functionality whenever the spline mesh is rebuilt.
For example:
- Updating a navmesh after a fence has been altered.
- (Re)spawning objects along the same spline
- Updating game logic data that depends on the spline
- Adding components to the created mesh segments
All in all, this is an excellent way to integrate the tool with custom workflows.
Unlike the Events exposed in the inspector callbacks are entirely code-based, and can be subscribed to. A bare bones example looks like this:
using System;
using UnityEngine;
using sc.splines.mesher.runtime;
[ExecuteAlways] //Ensure the OnEnable and OnDisable functions fire outside of play mode
public class RebuildEventExample : MonoBehaviour
{
public SplineMesher splineMesher;
private void OnEnable()
{
//Subscribe
SplineMesher.onPostRebuildMesh += OnPostRebuild;
}
private void OnPostRebuild(SplineMesher instance)
{
//Is the instance being rebuild the one we want to work with
if (instance == splineMesher)
{
//Execute something
}
}
private void OnDisable()
{
//Unsubscribe
SplineMesher.onPostRebuildMesh -= OnPostRebuild;
}
}
There’s also the onPreRebuildMesh callback, that executes before the mesh is being rebuild.
Editor tools
The SplineMesherEditor class contains a few public static functions, for use in custom tooling and pipelines:
- GenerateLODS (with overloads for specific scenes and meshers)
- GenerateLightmapUVs (with an overload for a list of meshers)
