Created
February 27, 2018 19:35
-
-
Save edwardrowe/09574c6a88871ad7bbc9e97ef39e722b to your computer and use it in GitHub Desktop.
Curve ScriptableObject for Unity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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