Hi,
I'm wondering how to play 2 animations at the same time with Unity runtimes, the first one being a Walk animation, and the second one just rotating an arm, the last should override the animation of the arms.
Any clues?
Thanks!
Hi,
I'm wondering how to play 2 animations at the same time with Unity runtimes, the first one being a Walk animation, and the second one just rotating an arm, the last should override the animation of the arms.
Any clues?
Thanks!
To do this you'll need to extend SkeletonComponent so you can have 2 AnimationStates. Here's some code:
class YourSkeletonComponent extends SkeletonComponent {
public Spine.AnimationState state1;
public Spine.AnimationState state2;
public void Initialize () {
super.Initialize();
state1 = new Spine.AnimationState(skeletonDataAsset.GetAnimationStateData());
state2 = new Spine.AnimationState(skeletonDataAsset.GetAnimationStateData());
}
public void UpdateAnimation () {
skeleton.Update(Time.deltaTime * timeScale);
state1.Update(Time.deltaTime * timeScale);
state2.Update(Time.deltaTime * timeScale);
state1.Apply(skeleton);
state2.Apply(skeleton);
skeleton.UpdateWorldTransform();
}
}
...
YourSkeletonComponent yourSkeletonComponent = ...
yourSkeletonComponent.state1.setAnimation("walk", true); // true means loop
yourSkeletonComponent.state2.setAnimation("rotateArm", false); // false means don't loop
You just blew my mind, Nate.
I didn't think of using it this way. The separation of Skeleton and AnimationState makes complete sense like this. I'm going to try this right now.
Is the AnimationStateData from the skeletonDataAsset just for crossfade durations?
Note: The C# syntax for class inheritance is
public class YourNewClass : Superclass {
...
}
Java's "super" is also "base" in C#
and you need to specify if you want to hide (new keyword) or override (override keyword) a superclass/base class method.
see: http://social.msdn.microsoft.com/Forums ... bb83de350/
(had to look these up. :drunk: )
*update: having some problems with inheritance and method overriding syntax. I'm also more familiar with Java so this is new to me.
Yeah, I had facerolled the keyboard to come up with that code sample. :p
SkeletonData stores the setup pose and data like skins, attachments, animations. Skeleton stores the state for an instance. Diagram here. AnimationState is a convenience class that makes it easy to mix (crossfade) and queue (for later playback) animations. You could do what AnimationState does yourself if you like, just by using Animation mix() and apply(). SkeletonComponent is really only needed to draw the skeleton. You can extend it to do your own skeleton manipulation, either by getting bones and changing their values or by applying animations however you like.
It just makes sense to extend SkeletonComponent and use AnimationState this way though. It's like giving the upper body its own animation state, and the legs its own animation state, or say, facial expression has its own animation state. Then you can manage and animate each of them kinda separately and cleanly.
Anyway, I just learned that the base (SkeletonComponent) class' methods need to be declared as virtual if you want to override them. http://msdn.microsoft.com/en-us/library ... 71%29.aspx
The virtual-override pair seems to be something of a self-documentation feature of languages (for when you expect a method to be overridden) that even the C++11 spec adopted.
I've refactored spine-unity a bit. There is now SkeletonComponent, which only draws the skeleton. Extend it to do your own thing. There is also SkeletonAnimation which extends SkeletonComponent and has an AnimationState. The AnimationState can either be controlled through the Inspector, or set the animation to <No Change> if you want to control the AnimationState via code.
Thanks a lot Nate,
yesterday I tried something similar (with no results ) changing SkeletonComponent class.
Thanks for the solution!