In Unities Shruiken particle system (say if your editing the size by speed value) there is a very nice feature where you can set the ratio between the two values using a curve with multiple points. You can also choose multiple types of curves or graphs and so on.
Im wondering if theres a way of adding this feature to my own components. It would be so handy!
Yes! Simply add an animation curve object to your component. Then, from code, you can just do
AnimationCurve someCurve = new AnimationCurve();
// elsewhere...
var number = someCurve.Evaluate(someValue);
Obviously that is ridiculously pseudo-code, but it should give you what you need. Just make a new animation curve object and call evaluate to get the ‘y’ value at the passed in ‘x’ value.
Sure, just use the AnimationCurve class. If you add such a field to your class you will have a curve field which will open the default curve editor:
// C#
public AnimationCurve curve;
In your code you can evaluate the curve with the Evaluate method:
void Update()
{
float t = 0.5f; // the position on the x-axis
float val = curve.Evaluate(t); // gets the position on the y-axis
}
The shuriken particle engine uses their own curve editor but it is very similar.