{{description>Enhance your Unity spline with Curvy Splines Metadata! Attach custom data to control points, and access or interpolate seamlessly.}} {{indexmenu_n>4}} ====== Metadata ====== Sometimes you want to store additional information to your spline, e.g. a max speed or other track information for your racing track, additional [[..:generator:]] data etc.. This is done by creating your own Metadata classes and attaching them to Control Points. You then can use Curvy Splines' API to access that data. ===== Metadata interpolation ===== When assigning a Metadata to a Control Point, the Metadata's value is applied to the segment starting from said Control Point until the next one. When there is no Metadata interpolation, the value of the Metadata will suddenlty change one you reach the next Control Point. Sometimes, you want that value to be gradually interpolated between the two Control Points. That's when interpolatable Metadata comes into play. ===== Creating the Metadata class ===== Create a new MonoBehaviour that inherits from one of the following classes: * CurvyMetadataBase: Base class for all Metadata classes. * CurvyInterpolatableMetadataBase: Base class for Metadata classes that support interpolation. This class is abstract, which means that you will need to implement its abstract members, namely the MetaDataValue getter and the Interpolate method. Here is an example (used by the Metadata example scene) that provides a simple float value that can be interpolated: namespace FluffyUnderware.Curvy.Examples { public class HeightMetadata : CurvyInterpolatableMetadataBase { [SerializeField] [RangeEx(0, 1, Slider = true)] float m_Height; public override float MetaDataValue { get { return m_Height; } } public override float Interpolate(CurvyInterpolatableMetadataBase nextMetadata, float interpolationTime) { return (nextMetadata != null) ? Mathf.Lerp(MetaDataValue, nextMetadata.MetaDataValue, interpolationTime) : MetaDataValue; } } } ===== Assigning Metadata to Control Points ===== As Metadata classes are regular MonoBehaviours, simply add them to the desired Control Points using the Component menu. ===== Retrieving Metadata ===== You can access Metadata from Splines and from Control Points using the following API members: * GetMetadata: Method that gets the Metadata class itself, of type T * GetInterpolatedMetadata: Method that gets interpolated data of type U from Metadata class T * MetaDataSet: Property that gets a set of all attached Metadata ([[CurvySplineSegment]] only) For example, the MetadataController script from the example scene mentioned above uses the following code to access the height value: float height = Spline.GetInterpolatedMetadata(RelativePosition);