using System;
using UnityEngine;
using UnityEngine.Splines;
namespace Unity.Cinemachine
{
///
/// This structure holds the spline reference and the position and position units.
///
[Serializable]
public struct SplineSettings
{
/// The Spline container to which the the position will apply.
[Tooltip("The Spline container to which the position will apply.")]
public SplineContainer Spline;
/// The position along the spline. The actual value corresponding to a given point
/// on the spline will depend on the unity type.
[Tooltip("The position along the spline. The actual value corresponding to a given point "
+ "on the spline will depend on the unity type.")]
public float Position;
/// How to interpret the Spline Position:
/// - Distance: Values range from 0 (start of Spline) to Length of the Spline (end of Spline).
/// - Normalized: Values range from 0 (start of Spline) to 1 (end of Spline).
/// - Knot: Values are defined by knot indices and a fractional value representing the normalized
/// interpolation between the specific knot index and the next knot."
[Tooltip("How to interpret the Spline Position:\n"
+ "- Distance: Values range from 0 (start of Spline) to Length of the Spline (end of Spline).\n"
+ "- Normalized: Values range from 0 (start of Spline) to 1 (end of Spline).\n"
+ "- Knot: Values are defined by knot indices and a fractional value representing the normalized "
+ "interpolation between the specific knot index and the next knot.\n")]
public PathIndexUnit Units;
///
/// Change the units of the position, preserving the position on the spline.
/// The value of Position may change in order to preserve the position on the spline.
///
/// The new units to use
public void ChangeUnitPreservePosition(PathIndexUnit newUnits)
{
if (Spline.IsValid() && newUnits != Units)
Position = Spline.Spline.ConvertIndexUnit(Position, Units, newUnits);
Units = newUnits;
}
}
}