Controller Events

For now, Controller Events are limited to Spline Controllers

Reference

You can react to certain movement related events by adding a handler to the following UnityEvents:

OnControlPointReached

CurvySplineMoveEventArgs

Called when moving over a Control Point

OnEndReached

CurvySplineMoveEventArgs

Called when the end (or start) of the source spline is reached

OnSwitch

CurvySplineMoveEventArgs

Called during a spline switch

When you add an event handler by code, be sure to call BindEvents() afterwards! Please support our request to being able to check for event handlers without feeding the GC!

CurvySplineMoveEventArgs

Events using this EventArgs are called during a movement. This class offers several methods to influence the further movement (e.g. use a connection)

Properties/Fields

Name Description
Direction current movement direction (1 or -1)
Delta TF or world units distance left
TF current TF
WorldUnits whether Delta is TF or World Units
Control Point Current Control Point (from CurvyControlPointEventArgs)
Spline Current Spline (from CurvySplineEventArgs)

Methods

Name Description
SetPosition() Continue movement at another position (may be on another spline as well)
Follow() Continue movement at another spline (sets direction and delta to fit)
AngleTo() Gets the angle to another Control Point

Example

The following callback method (being part of the CurvyDefaultEventHandler component) can be bound to the OnEndCPReached (or OnCPReached) event of the SplineController and it's called each time the controller reaches the first or last Control Point of it's spline. If the event's Control Point has a FollowUp defined in a connection, it's used to continue movement on:

public void UseFollow (CurvySplineMoveEventArgs e)
{
            // we need a SplineController as well as a following spline to work with
            if (e.Sender is SplineController && e.ControlPoint.FollowUp)
            {
                // Follow the connected spline
                e.Follow(e.ControlPoint.FollowUp, e.ControlPoint.FollowUpHeading);
                // Set the controller to use the new spline
                SplineController controller = (SplineController)e.Sender;
                controller.Spline = e.Spline;
                controller.RelativePosition = e.TF;
                // Handle controller events for the new passed ControlPoint
                controller.OnControlPointReached.Invoke(e);
            }
}
Last modified: 2016/04/30 15:43 by Jake