BITKit/Packages/Runtime~/Unity/Extensions/Dreamteck/SplinePathProvider.cs

38 lines
1.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Dreamteck.Splines;
namespace BITKit
{
public class SplinePathProvider : LineObstacleProvider
{
public SplineComputer computer;
public SplinePositioner positioner;
public override bool IsValid(ref Vector3 startPos)
{
var isValid = base.IsValid(ref startPos);
if (isValid)
{
computer.SetPoint(0, new SplinePoint()
{
position = startPos,
tangent = startPos,
tangent2 = startPos,
});
computer.SetPoint(1, new SplinePoint()
{
position = endPos,
tangent = endPos + transform.rotation * new Vector3(0, 1, -1),
tangent2 = endPos + transform.rotation * new Vector3(0, 1, 1),
normal = new(0, 1, 0),
});
computer.RebuildImmediate();
}
return isValid;
}
public override Vector3 Evaluate(float time)
{
return positioner.EvaluatePosition(time);
}
}
}