mcs_andrei wroteOkay.
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.
Nate tried to make the API across all runtimes as consistent as possible while still trying to respect how each language's standards handles things, but differences in language support and paradigm-centeredness are inevitable.
Function pointers/callbacks/events work VERY differently across different languages. The documentation happens to have been written with how Java/libGDX runtime was designed and with how Java does things. Java events are handled by creating Adapter classes that have methods that can be called as a callback. The sample uses an anonymous class that defines the callback inside it.
C# handles things a bit more like C/C++, but with a few extra features and overloaded syntax.
You should search for C# Events and Delegates (and lambdas and anonymous methods) to learn about it in depth.
But short Spine-Unity sample code for using user-defined Spine events would look like this:
void Start () {
var mySkeletonAnimation = GetComponent<SkeletonAnimation>();
mySkeletonAnimation.state.Event += delegate (Spine.AnimationState state, int trackIndex, Spine.Event e) {
if (e.Data.Name == "footstep") {
Debug.Log("event named footstep was fired!!");
}
};
}
state.Event
is of the c# event type, which you can subscribe to using the +=
operator. The right hand side of the operator can be the identifier of a method, a delegate, a lambda expression or an anonymous method.
Some of this syntax was new in C# 2.0 and 3.0. You may find some tutorials that say something different if those tutorials are old enough.
Please also see the spineboy example in the Spine unitypackage.