• Editor
  • How to implement events

Hi there, I am new to events... I understand the concept but I haven't been able to find a tutorial anywhere.

How does one implement an event?

Thank you.

Related Discussions
...

Which runtime are you using?

They vary greatly depending on the runtime because I think Nate made them so that they follow the conventions of the specific runtime you use. (Also because different programming languages handle the concept of events, callback functions and function/method pointers differently.)

In Unity you can do the following to find, for instance the end event for an animation.

[SerializeField]
private SkeletonAnimation mySpineAnim;

void Start()
{
	mySpineAnim.state.End += AnimationEndHandler;
}

private void AnimationEndHandler(object sender, StartEndArgs args)
{
	state.End -= AnimationEndHandler;
	Spine.AnimationState state = (Spine.AnimationState)sender;
	
//Note: SourceAnimation does not currently exist on Unity runtime out of the box
state.SourceAnimation.gameObject.SetActive(false);
}

I've added a public member property SourceAnimation to the Spine.Animation class. I thought that this was missing, it's really useful to be able to tell which GameObject has just sent that event as the example above shows.

Maybe we could suggest that to Nate?

AnimationState is in spine-csharp, it isn't specific to Unity. Probably you attach your script to the GameObject, so you already know which one it is? If not, you could create an instance of a "listener" class that has a reference to the GameObject (or whatever context information you like) and use a method on the listener object for the callback.

I think these are two different topics. I don't think OP uses Unity.