/// <summary> /// Returns an awaitable object that will be completed when the animation is removed from the PlayingAnimation list. /// This happens when: /// - RepeatMode is PlayOnce and animation reached end /// - Animation faded out completely (due to blend to 0.0 or crossfade out) /// - Animation was manually removed from AnimationComponent.PlayingAnimations /// </summary> /// <returns></returns> public Task Ended(PlayingAnimation animation) { if (!playingAnimations.Contains(animation)) { throw new InvalidOperationException("Trying to await end of an animation which is not playing"); } if (animation.endedTCS == null) { Interlocked.CompareExchange(ref animation.endedTCS, new TaskCompletionSource <bool>(), null); } return(animation.endedTCS.Task); }