49 lines
1.6 KiB
C#
49 lines
1.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Splines;
|
|
namespace BITKit.Spline
|
|
{
|
|
public interface ISplineContainer
|
|
{
|
|
Transform Position { get; }
|
|
Transform TangentIn { get; }
|
|
Transform TangentOut { get; }
|
|
}
|
|
[System.Serializable]
|
|
public class BasicSplineContainer : ISplineContainer
|
|
{
|
|
public Transform m_transform;
|
|
public Transform m_tangentIn;
|
|
public Transform m_tangentOut;
|
|
public Transform Position => m_transform;
|
|
public Transform TangentIn => m_tangentIn;
|
|
public Transform TangentOut => m_tangentOut;
|
|
}
|
|
[ExecuteAlways]
|
|
public class UnitySplineCreator : MonoBehaviour
|
|
{
|
|
[SerializeReference, SubclassSelector] public List<ISplineContainer> splines = new();
|
|
public SplineContainer container;
|
|
public SplineExtrude extrude;
|
|
[Header(Constant.Header.Settings)]
|
|
public int updateTimes;
|
|
void Update()
|
|
{
|
|
UnityEngine.Splines.Spline spline = new();
|
|
foreach (var x in splines)
|
|
{
|
|
spline.Add(new BezierKnot()
|
|
{
|
|
Position = x.Position.position,
|
|
Rotation = x.Position.rotation,
|
|
TangentIn = x.TangentIn ? x.TangentIn.position : Vector3.zero,
|
|
TangentOut = x.TangentOut ? x.TangentOut.position : Vector3.zero,
|
|
});
|
|
}
|
|
container.Spline = spline;
|
|
extrude.Rebuild();
|
|
updateTimes++;
|
|
}
|
|
}
|
|
} |