Skip to content

Commit

Permalink
Added animation layer support for sequence.
Browse files Browse the repository at this point in the history
  • Loading branch information
vchelaru committed Nov 24, 2023
1 parent 286b891 commit 1d04cba
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class AnimationLayer : INameable
/// is facing left/right.
/// </remarks>
public Func<string> EveryFrameAction;
public Func<List<string>> EveryFrameActionSequence;

public Action OnAnimationFinished;

/// <summary>
Expand Down Expand Up @@ -103,6 +105,49 @@ internal void Activity()
{
cachedChainName = EveryFrameAction();
}
else if(EveryFrameActionSequence != null)
{
var list = EveryFrameActionSequence();

if(list?.Count > 0)
{
// start the sequence, just in case there are no other animations...

cachedChainName = list[0];
var animatable = Container?.AnimatedObject;

if(animatable != null)
{

var indexToShow = 0;

int? matchingIndex = 0;
for(int i = 0; i < list.Count; i++)
{
if (animatable.IsPlayingAnimation(list[i]))
{
matchingIndex = i;
if(animatable.DidAnimationFinishOrLoop)
{
var nextIndex = i < list.Count-1
? i + 1
: i; // don't loop the sequence. Maybe we'll add that option later.
cachedChainName = list[nextIndex];
}
else
{
cachedChainName = list[i];
}
break;
}
}
}
}
else
{
cachedChainName = null;
}
}
else
{
var playingModeThisFrame = playingMode;
Expand Down

This file was deleted.

0 comments on commit 1d04cba

Please sign in to comment.