예제 #1
0
        // Do animations
        public async Task Animate(AnimationRequest request, CancellationToken token)
        {
            // Stop blink
            if (request.DisableBlink && !token.IsCancellationRequested)
            {
                StopBlink();
            }

            // Stop default animation loop
            if (request.StopIdlingOnStart && !token.IsCancellationRequested)
            {
                StopIdling();
            }

            // Animate sequentially
            var baseTask = PlayAnimations(request.BaseLayerAnimations, request.BaseLayerName, token);

            foreach (var anims in request.Animations)
            {
                if (anims.Key != request.BaseLayerName)
                {
                    _ = PlayAnimations(anims.Value, anims.Key, token);
                }
            }
            // Stop layered animations
            if (request.StopLayeredAnimations)
            {
                ResetLayers(request.Animations.Keys.ToList());
            }

            await baseTask;

            // Restart default animation
            if (request.StartIdlingOnEnd && request.BaseLayerAnimations.Count > 0 && request.BaseLayerAnimations.Last().Duration > 0)
            {
                _ = StartIdlingAsync();
            }

            // Restart blink
            if (request.DisableBlink && !token.IsCancellationRequested)
            {
                _ = StartBlinkAsync();
            }
        }
예제 #2
0
        public void AddIdleAnimation(string name, string layerName, float duration = 0.0f, float fadeLength = -1.0f, float weight = 1.0f, float preGap = 0.0f, bool addToLastRequest = false)
        {
            if (IdleAnimationRequests == null)
            {
                IdleAnimationRequests = new List <AnimationRequest>();
            }

            if (addToLastRequest)
            {
                var request = IdleAnimationRequests.Last();
                request.AddAnimation(name, layerName ?? request.BaseLayerName, duration == 0.0f ? IdleAnimationDefaultDuration : duration, fadeLength, weight, preGap);
            }
            else
            {
                var request = new AnimationRequest();
                request.AddAnimation(name, layerName ?? request.BaseLayerName, duration == 0.0f ? IdleAnimationDefaultDuration : duration, fadeLength, weight, preGap);
                IdleAnimationRequests.Add(request);
            }
        }