- Home /
Does Unity provide a Vector3 Curve similar to AnimationCurve?
Hey guys
So far my usage of AnimationCurves has been limited to animating single float values (for example, controlling the alpha of a color over time).
Now I'm in a situation where I want to use animation curves to animate things like the scale of an object:
As you can see I'm using 1 AnimationCurve for each axis. My question is: am I reinventing the wheel? Does Unity already provide a Vector3 AnimationCurve set?
If Unity does not provide this I would like to move towards making my own Editor classes to present these curves in a nicer way. I have noticed that Shuriken has it's own curve fields:
Somehow Shuriken is drawing a custom field for the curves, and is also drawing a custom curve editor.
How would I go about drawing curves like this to the inspector? How does shuriken make the extra editor window appear at the bottom of the inspector? How could I write a custom curve editor to show my 3 curves at the same time?
Any solutions for this? Some kind of way to use Shuriken's built-in-graph-system could really change a ton for data driven aspects of my game.
Curve editor support multiple curves at a time, but there's no easy way to get it to work from code. You'd need reflection to get and open CurveEditorWindow
, get its internal CurveEditor
, then set its m_AnimationCurves
and probably a dozen other values that Unity normally automates.
I ended up writing my own PropertyAttribute and PropertyDrawer to display the curves in the inspector, and then exactly as $$anonymous$$TheDev says: use reflection to pop open the curve editor.
Unfortunately the CurveEditorWindow only supports one curve at a time. It's frustrating, because reading the code in .NET Reflector it looks like Unity would only need trivial changes to unlock this functionality.
Answer by VesuvianPrime · Aug 19, 2015 at 02:15 PM
My curves PropertyAttribute:
The drawer:
The linked files won't work - they have a tonne of dependencies you need to track down from the project, would be better if you'd linked to the ZIP file to download the whole project perhaps?
Also: you've put a copyright + license on this preventing people from shipping it in their project - this is a nightmare if you ever want to share code, make an asset-store version of your code, etc - so it's not really an appropriate answer to the question (digging in the project, the stated license is currently LGPL, so I guess we could re-write it as an actual library, compile it, package it into a DLL, and then ship it with an asset-store package? But IANAL and this is a rabbit hole :)).
On the plus side, the code looks clean (apart from the long dependency chain).
Answer by wolilio · Sep 29, 2020 at 09:51 AM
you can create a AnimationClip with scale,and then use https://docs.unity3d.com/ScriptReference/AnimationClip.SampleAnimation.html to get scale over time