Multiple events on the same animation could have the same key.
That can already be done by calling state.Events.IndexOf(name, startIndex) in a loop. Each time it finds an index you call SetCallback(index, callback) then repeat the IndexOf call starting at the index it just found +1 to keep searching the rest of the sequence.
Solution
Add this to AnimancerEvent.Sequence.cs:
public int AddCallbacks(string name, Action callback)
{
var count = 0;
var index = -1;
while (true)
{
index = IndexOf(name, index + 1);
if (index < 0)
return count;
count++;
AddCallback(index, callback);
}
}
A SetCallbacks method would be identical except for its AddCallback being replaced by SetCallback.
Unfortunately, it wouldn't be able to handle nested states because the AnimancerEvent.Sequence has no connection to a state or transition, so I'll need to add recursive methods to the appropriate states and transitions like the one I gave you a while ago which could now simply call AddCallbacks.
Use Case
This issue is split out from https://github.com/KybernetikGames/animancer/issues/262 since it could be implemented separately from the main idea presented there.
That can already be done by calling
state.Events.IndexOf(name, startIndex)
in a loop. Each time it finds an index you callSetCallback(index, callback)
then repeat theIndexOf
call starting at the index it just found +1 to keep searching the rest of the sequence.Solution
Add this to
AnimancerEvent.Sequence.cs
:A
SetCallbacks
method would be identical except for itsAddCallback
being replaced bySetCallback
.Unfortunately, it wouldn't be able to handle nested states because the
AnimancerEvent.Sequence
has no connection to a state or transition, so I'll need to add recursive methods to the appropriate states and transitions like the one I gave you a while ago which could now simply callAddCallbacks
.