Spline Mesher Documentation

Spline Mesher

Spline Mesher
Version: 1.2.0
Review

5.Scripting #

Familiarity with C# and OOP programming is assumed. Support cannot be extended to coding help. Some specific functionality and use cases really need to be handled on a project-specific basis with some creative thinking.

If you are using an assembly definition, ensure you add a reference to the sc.modeling.splines.runtime assembly, otherwise you won’t be able to access the namespace and classes.

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.

Example scripts

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!

Never ever call the “Rebuild()” function on a Spline Mesher instance from a callback or event. This creates an infinite loop and crashed the editor/application.

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”.

Yes No Suggest edit
Last updated on April 18, 2024
0 of 0 users found this section helpful
Suggest Edit