Skip to content

Instantly share code, notes, and snippets.

@edwardrowe
Created February 27, 2018 19:35
Show Gist options
  • Save edwardrowe/09574c6a88871ad7bbc9e97ef39e722b to your computer and use it in GitHub Desktop.
Save edwardrowe/09574c6a88871ad7bbc9e97ef39e722b to your computer and use it in GitHub Desktop.
Curve ScriptableObject for Unity
using UnityEngine;
/// <summary>
/// Stores a Unity AnimationCurve as an asset
/// </summary>
public class Curve : ScriptableObject
{
[SerializeField]
private AnimationCurve curve;
/// <summary>
/// Gets or sets the curve stored by this CurveObject
/// </summary>
public AnimationCurve Data
{
get
{
return this.curve;
}
private set
{
this.curve = value;
}
}
/// <summary>
/// Creates a curve with the specified Keyframes.
/// </summary>
/// <returns>The created curve.</returns>
/// <param name="keys">Keyframes for the curve.</param>
public static Curve CreateCurve(params Keyframe[] keys)
{
var createdCurve = ScriptableObject.CreateInstance<Curve>();
var animCurve = new AnimationCurve(keys);
createdCurve.curve = animCurve;
return createdCurve;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment