/// <summary> /// Assigns an animation curve to a given track. /// </summary> /// <param name="track">The name of the track.</param> /// <param name="curve"> /// A <see cref="ICurveSampler{T}"/> instance which also /// implements <see cref="IConvertibleCurve{T}"/>, /// or null to remove a track. /// </param> public void SetTrack(string track, ICurveSampler <T> curve) { Guard.NotNullOrEmpty(track, nameof(track)); // remove track if (curve == null) { if (_Tracks == null) { return; } _Tracks.Remove(track); if (_Tracks.Count == 0) { _Tracks = null; } return; } curve.GetPoint(0); // make a single evaluation to ensure it's an evaluable curve. Guard.IsTrue(curve is IConvertibleCurve <T>, nameof(curve), $"Provided {nameof(ICurveSampler<T>)} {nameof(curve)} must implement {nameof(IConvertibleCurve<T>)} interface."); // insert track if (_Tracks == null) { _Tracks = new Dictionary <string, ICurveSampler <T> >(); } _Tracks[track] = curve; }
/// <summary> /// Assigns an animation curve to a given track. /// </summary> /// <param name="track">The name of the track.</param> /// <param name="curve"> /// A <see cref="ICurveSampler{T}"/> instance which also /// implements <see cref="IConvertibleCurve{T}"/>, /// or null to remove a track. /// </param> public void SetTrack(string track, ICurveSampler <T> curve) { Guard.NotNullOrEmpty(track, nameof(track)); // remove track if (curve == null) { if (_Tracks == null) { return; } _Tracks.Remove(track); if (_Tracks.Count == 0) { _Tracks = null; } return; } Guard.IsFalse(curve is CurveBuilder <T>, "Use UseTrackBuilder() instead"); // clone curve var convertible = curve as IConvertibleCurve <T>; curve = convertible.Clone() as ICurveSampler <T>; // validate curve.GetPoint(0); // make a single evaluation to ensure it's an evaluable curve. Guard.NotNull(curve, $"Provided {nameof(ICurveSampler<T>)} {nameof(curve)} must implement {nameof(IConvertibleCurve<T>)} interface."); // insert track if (_Tracks == null) { _Tracks = new Dictionary <string, ICurveSampler <T> >(); } _Tracks[track] = curve; }