Hi,
I would like to know what is the best way to work with delegate, as I am not confident how the TrackEntry life cycle works under the hood.
I want a one-time event when this specific animation ends and never again.
Two options, which is better?
var trackEntry = skeletonAnimation.SetAnimation(0, someAnimation, false);
trackEntry.End += _ => DoSomethingOnEnd();
// Fire and forget about unsubscribing
Or
var trackEntry = skeletonAnimation.SetAnimation(0, someAnimation, false);
trackEntry.End += OnEnd;
//...
private void OnEnd(TrackEntry trackEntry)
{
trackEntry.End -= OnEnd; // Doing unsubscription - is this step necessery??
DoSomethingOnEnd();
}
I am using almost all the time the second pattern just to be careful, but is it really needed? The first one is obviously simpler.