What is the Scriptable Animator?
This asset was created as an
alternative to the mecanim animation system. When programming with Mecanim, the
transition lines become more complex as the number of states increases. The Scriptable
Animator provides simple and effective control of state transitions with lines
of code.
How can the example be used?
In order to use the example, the “StarterAssets”
projects must be imported. Then, the scene named “Playground” should be
opened from the “StarterAssets/Demos/ScriptableAnimator/Scenes” file path.
Dependencies must be installed before
using the Netcode sample. "com.unity.netcode.gameobjects" version 1.7.1 and "com.unity.multiplayer.tools" version 1.1.1 were used.
Getting Started
Inheritance:
The class that will be the controller must inherit from the
'AnimatorBehavior' class. After inheritance, the methods needed to manage
animations can be used.
Initialize:
The 'Initialize' function
should be run first in the 'Awake' method. Otherwise, the controller will not
initialize and cause an error.
Set
Animation:
It can be set via the
Inspector or in lines of code. If you want to set it in the code line, it must
be set before creating the layer. Animation can be set with the 'SetAnimation'
method in the State.
Entry:
Plays the entry
animation. 'PerformTransition' can be used instead. It's just a shorter method and
runs on entry.
Playing & Transitions:
For this, functions
inherited from 'AnimatorBehaviour' can be used. Other methods needed in
animation management can be accessed using this namespace: ‘Plugins.ScriptableAnimator.Extensions’
State can be transitioned
using the 'PerformTransition' function. If the animations need to be changed,
the state must be updated with the 'UpdateState' function. The processing cost
of the 'UpdateState' function increases as the count of animations increases.
States
‘Plugins.ScriptableAnimator.States’
These are the classes
that contain the playables. The state used can be single or mixed. The choice
should be made according to whichever is needed.
SingleAnimation:
A single clip is played.
It does not take a Threshold value.
BlendTree1:
The mix clip is played
and gets a threshold value of type 'float'. The weights of the clips played are
determined according to the threshold value.
BlendTree2:
The mix clip is played
and gets a threshold value of type 'Vector2'. The weights of the clips played
are determined according to the threshold value.
Animation Containers
‘Plugins.ScriptableAnimator.Animations.Containers’
These are containers that hold
animations to be played in the state. It is recommended that animation set or
update be done with containers. It can be created from the ‘Create/Scriptable Animator’ create menu path.