Using the AnimationState class?
I haven't tried it, but I looked through the code briefly and it should be possible.
Considering:
(1) AnimationState has a track system. If you call SetAnimation(0, walk, true); then SetAnimation(1, shoot, true); then both walking and shooting animations will play. walk animation pose gets applied first. Then then shoot animation is applied on top of it.
(2) Each entry on the track system (see the Spine.AnimationState.TrackEntry class) has controllable properties like TimeScale, Time and Mix.
(3) TrackEntry.Mix in particular isn't about crossfading between one animation to another. It's actually an alpha/percentage of the pose that will get applied to the skeleton. the Mix property affects the alpha parameter that gets used by AnimationState internally when it calls Animation.Apply, or in this case, Animation.Mix.
So. Theoretically, the code is:
Spine.AnimationState state = skeletonAnimation.state;
state.SetAnimation(0, walk, true); // walk on track 0.
var track = state.SetAnimation(1, run, true); // run on track 1.
track.Mix = 0.5f;
21 Mar 2016 2:52 am
Tested it with Spineboy's walk and run.
This code works. Put it in your project and test it out:
using UnityEngine;
using Spine;
public class AnimationMixerTest : MonoBehaviour {
[Range(0f, 1f)]
public float mix = 0.5f;
Spine.TrackEntry track;
void Start () {
var state = GetComponent<SkeletonAnimation>().state;
state.SetAnimation(0, "walk", true);
track = state.SetAnimation(1, "run", true);
}
void Update () {
if (track != null)
track.Mix = this.mix;
}
}
All the same, it will have to be your system that manages increasing and decreasing the mix, and fading it out/clearing the track when it needs to be cleared.