Can I somehow obtain reference to SkeletonAnimation inside SpineEvent callback?
void Start() {
foreach (SkeletonAnimation skeletonAnim in skeletons) {
skeletonAnim.state.Event += OnSpineEvent;
}
}
void OnSpineEvent(TrackEntry te, Spine.Event e) {
// here I need reference to distinguish which skeleton animation rises event
}
Background: I have 4 characters each of them can cast spells. But spells are not cast immediately, but with some charge animation first. Then this animation rises event "spell_cast" and only then spell will be actually invoked. The problem: I do not know which player has cast spell in the time of handling event. Can I obtain this information in callback. Or at least can I pass it to animation first like index just to get same index back in event? Or any other solution?
The only idea I have now just to use 4 predefinened callbacks with only difference player index. But it is pretty boilerplate solution. Do I have a better option then:
void Start() {
skeletons[0].state.Event += OnSpineEvent1;
skeletons[1].state.Event += OnSpineEvent2;
skeletons[2].state.Event += OnSpineEvent3;
skeletons[3].state.Event += OnSpineEvent4;
}
void OnSpineEventSkeleton0(TrackEntry te, Spine.Event e) => OnSpineEvent(0, te, e);
void OnSpineEventSkeleton1(TrackEntry te, Spine.Event e) => OnSpineEvent(1, te, e);
void OnSpineEventSkeleton2(TrackEntry te, Spine.Event e) => OnSpineEvent(2, te, e);
void OnSpineEventSkeleton3(TrackEntry te, Spine.Event e) => OnSpineEvent(3, te, e);
This will do the job of course, but is pretty ugly. And (theoretically) if I would need n-sized list with unknown size this will not work at all. The best for me would be just something like:
void OnSpineEvent(TrackEntry te, Spine.Event e) {
SkeletonAnimation invoker = te.state.SkeletonAnimation; // but I can not find link to it in TrackEntry or Spine.Event.
}