54 lines
1.3 KiB
C#
54 lines
1.3 KiB
C#
|
using Dreamteck.Splines;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
public class ExampleJunctionHandler : MonoBehaviour
|
||
|
{
|
||
|
SplineTracer tracer;
|
||
|
|
||
|
private void Awake()
|
||
|
{
|
||
|
tracer = GetComponent<SplineTracer>();
|
||
|
}
|
||
|
|
||
|
private void OnEnable()
|
||
|
{
|
||
|
tracer.onNode += OnNode; //onNode is called every time the tracer passes by a Node
|
||
|
}
|
||
|
|
||
|
private void OnDisable()
|
||
|
{
|
||
|
tracer.onNode -= OnNode;
|
||
|
}
|
||
|
|
||
|
private void OnNode(List<SplineTracer.NodeConnection> passed)
|
||
|
{
|
||
|
Node.Connection[] connections = passed[0].node.GetConnections();
|
||
|
|
||
|
if (connections.Length == 1) return;
|
||
|
|
||
|
int newConnection = 1;
|
||
|
|
||
|
//if (connections[newConnection].spline == tracer.spline && connections[newConnection].pointIndex == passed[0].point)
|
||
|
//{
|
||
|
// newConnection++;
|
||
|
|
||
|
// if (newConnection >= connections.Length) newConnection = 0;
|
||
|
//}
|
||
|
|
||
|
if (connections[newConnection].spline != tracer.spline)
|
||
|
{
|
||
|
SwitchSpline(connections[newConnection]);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void SwitchSpline(Node.Connection to)
|
||
|
{
|
||
|
tracer.spline = to.spline;
|
||
|
tracer.RebuildImmediate();
|
||
|
double startpercent = tracer.ClipPercent(to.spline.GetPointPercent(to.pointIndex));
|
||
|
tracer.SetPercent(startpercent);
|
||
|
}
|
||
|
}
|