KybernetikGames / animancer

Documentation for the Animancer Unity Plugin.
65 stars 8 forks source link

Multiple Animancer Events with the same name #263

Closed KybernetikGames closed 3 weeks ago

KybernetikGames commented 1 year ago

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.

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.

KybernetikGames commented 2 months ago

Animancer v8.0 is now available for Alpha Testing and includes these new methods..

KybernetikGames commented 3 weeks ago

Animancer v8.0 is now fully released.