Spline Mesher
5.Scripting
Whenever using the API, ensure you add using sc.modeling.splines.runtime; to include the namespace.
The Spline Mesher
component and class exposes 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
- Post-processing the created mesh (adding a gradient to the vertex colors?)
All in all, this is an excellent way to integrate the tool with custom workflows.
Callbacks vs Events?
- A callback is strictly something you use in a C# script.
- An event is exposed in the inspector, so allows for drag & drop operations.
As you may imagine, can use both, but depending on the context one may be easier to work with than the other!
Callbacks
Callbacks are entirely code-based, and can be subscribed to. A bare bones example looks like this:
using System;
using UnityEngine;
using sc.modeling.splines.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.
Events
Events are exposed in the inspector on a Spline Mesher
component and allow easy (often code-less) functionality to be executed.
This sort of functionality is native to Unity, please see the Unity Manual section for more information. Or search for “Unity Events”.