mcs_andrei

Hello.

I'm new to spine and using it on Unity via C#. I want to know how can we subscribe a callback such that we can track the keyframe of the current playing animation. So it would be something like OnKeyframeChanged event. This would be for additional cases I needed to support in our project.

I am aware of the Complete and End events as specified here: http://esotericsoftware.com/forum/Complete-vs-End-Runtime-Events-4050?p=19552&hilit=callback#p19552 and also making Custom Events via the editor, but I would really want is a generic callback or way in code to get the current key frame played by the current animation. How is this done using the Spine runtimes? If it is not in the runtime, what part of the runtime code should I check out to retrieve this information so I can modify the run time?

-Drei
mcs_andrei
  • Messaggi: 5

Pharan

I've actually been thinking about an OnKeyframe callback for years now. But it was mostly for mixing purposes that might be better solved in other ways. I suspect that it's easy to add, actually, if you're familiar with how the runtime works under the hood.

But adding it in as part of the official runtime might not be the best idea since not a lot of people need it. An extra null check and possible method call per keyframe probably wouldn't scale well.

As for your use, OnKeyframe might not be what you need.

(1) Custom Events
Do you mean apart from the Events you can define in the editor? http://esotericsoftware.com/spine-events
What did you mean by "Custom Events"?

(2) Determining "frame number"
If you meant to get the current frame number when an event fires, you can do that this way:
// this returns the current time in the current animation in seconds.
// this is a bit unsafe since GetCurrent(0) can return null if no animation is playing. You can add a null check.
float myTimeElapsed = mySkeletonAnimation.state.GetCurrent(0).time;

// this is now the time elapsed converted to frames. You can Mathf.Floor it or convert it to an int to get a whole number.
float myCurrentFrame = myTimeElapsed / 30f;
Avatar utente
Pharan
  • Messaggi: 5366

mcs_andrei

Hello Pharan. Thanks for replying.
And thank you for that quick example of computing the keyframe.

For #1, yes that is the "Custom Events" I was talking about.

Since your information in #2 is handy, I think I can cook up a code modification on the runtime. It is just that I need to think now whether to go with it, or go with Custom Events. I have to think this through considering our current pipeline.
mcs_andrei
  • Messaggi: 5

Mitch

Honestly I would just create an extension method for SkeletonData that analyzed the relevant timelines and added a new event where needed. No major runtime modification needed.
Avatar utente
Mitch

Mitch
  • Messaggi: 978

mcs_andrei

Okay.

Is it just me, or is the csharp + unity runtimes do not have the similar APIs indicated here: http://esotericsoftware.com/spine-events.
The TrackEntry doesn't have the setListener or similar method. And there is no AnimationStateAdapter class too?

How is Custom Events supported in csharp+unity?

Regards.
mcs_andrei
  • Messaggi: 5

Pharan

That's a good question but a bit out of topic. I'll put a new topic up for this and I'll answer you there.
Why is the Events API different from the documentation?
Avatar utente
Pharan
  • Messaggi: 5366


Torna a Off-topic