예제 #1
0
        private void PlaySequencedAnimation(int layerID, SequencedAnimationInput SequencedAnimationInput, Action OnAnimationEnd)
        {
            if (this.AllAnimationLayersCurrentlyPlaying.ContainsKey(layerID))
            {
                this.DestroyLayer(layerID);
            }

            var SequencedAnimationLayer = new SequencedAnimationLayer(this.GlobalPlayableGraph, this.AnimationLayerMixerPlayable, layerID, SequencedAnimationInput, OnAnimationEnd);

            this.AllAnimationLayersCurrentlyPlaying[layerID] = SequencedAnimationLayer;
            this.OrderedByInputHandlerAnimationLayers.Add(SequencedAnimationLayer);

            this.SortLayers();

            PlayableExtensions.SetInputWeight(this.AnimationLayerMixerPlayable, SequencedAnimationLayer.Inputhandler, 1f);
        }
예제 #2
0
        public SequencedAnimationLayer(PlayableGraph playableGraph, AnimationLayerMixerPlayable parentAnimationLayerMixerPlayable, int layerId,
                                       SequencedAnimationInput SequencedAnimationInput, Action OnAnimationEnd) : base(layerId, parentAnimationLayerMixerPlayable)
        {
            this.SequencedAnimationInput = SequencedAnimationInput;
            this.UniqueAnimationClips    = SequencedAnimationInput.UniqueAnimationClips.ConvertAll(clip => clip.ToUniqueAnimationClip());
            this.IsTransitioningIn       = false;
            this.IsTransitioningOut      = false;
            this.HasEnded = false;

            this.AnimationMixerPlayable           = AnimationMixerPlayable.Create(playableGraph);
            this.AssociatedAnimationClipsPlayable = new AnimationClipPlayable[this.UniqueAnimationClips.Count];

            this.Inputhandler = PlayableExtensions.AddInput(this.ParentAnimationLayerMixerPlayable, this.AnimationMixerPlayable, 0);

            if (SequencedAnimationInput.AvatarMask != null)
            {
                this.ParentAnimationLayerMixerPlayable.SetLayerMaskFromAvatarMask((uint)this.Inputhandler, SequencedAnimationInput.AvatarMask);
            }

            this.ParentAnimationLayerMixerPlayable.SetLayerAdditive((uint)this.Inputhandler, SequencedAnimationInput.IsAdditive);

            if (OnAnimationEnd != null)
            {
                this.OnSequencedAnimationEnd = OnAnimationEnd;
            }

            for (var i = 0; i < this.UniqueAnimationClips.Count; i++)
            {
                this.AssociatedAnimationClipsPlayable[i] = AnimationClipPlayable.Create(playableGraph, this.UniqueAnimationClips[i].AnimationClip);
                PlayableExtensions.SetDuration(this.AssociatedAnimationClipsPlayable[i], this.UniqueAnimationClips[i].AnimationClip.length);
                this.AssociatedAnimationClipsPlayable[i].SetApplyFootIK(false);
                this.AssociatedAnimationClipsPlayable[i].SetApplyPlayableIK(false);
                this.AssociatedAnimationClipsPlayable[i].Pause();
                this.UniqueAnimationClips[i].InputHandler = PlayableExtensions.AddInput(this.AnimationMixerPlayable, this.AssociatedAnimationClipsPlayable[i], 0);
            }

            if (this.SequencedAnimationInput.BeginTransitionTime > 0f)
            {
                this.IsTransitioningIn = true;
            }
            else
            {
                SetAnimationMixerPlayableWeight(this.AnimationMixerPlayable, this.AssociatedAnimationClipsPlayable[0], this.UniqueAnimationClips[0].InputHandler, 1f);
            }


            //Calculate linear blendings times
            float virtualClipElapsedTime = 0f;


            for (var i = 0; i < this.UniqueAnimationClips.Count; i++)
            {
                float animationClipLength = this.UniqueAnimationClips[i].AnimationClip.length;
                if (this.UniqueAnimationClips[i].AnimationSpeedMultiplier != 0)
                {
                    animationClipLength = animationClipLength / this.UniqueAnimationClips[i].AnimationSpeedMultiplier;
                }

                if (i == 0)
                {
                    virtualClipElapsedTime = this.SequencedAnimationInput.BeginTransitionTime;
                    this.UniqueAnimationClips[i].TransitionBlending = this.UniqueAnimationClips[i].TransitionBlending.SetWeightTimePoints(
                        AnimationWeightStartIncreasingTime: virtualClipElapsedTime,
                        AnimationWeightEndIncreasingTime: virtualClipElapsedTime,
                        AnimationWeightStartDecreasingTime: virtualClipElapsedTime + this.UniqueAnimationClips[i].TransitionBlending.EndClipDelay + animationClipLength - this.UniqueAnimationClips[i].TransitionBlending.EndTransitionTime,
                        AnimationWeightEndDecreasingTime: virtualClipElapsedTime + this.UniqueAnimationClips[i].TransitionBlending.EndClipDelay + animationClipLength
                        );

                    virtualClipElapsedTime += animationClipLength + this.UniqueAnimationClips[i].TransitionBlending.EndClipDelay;
                }
                else if (i == this.UniqueAnimationClips.Count - 1)
                {
                    this.UniqueAnimationClips[i].TransitionBlending = this.UniqueAnimationClips[i].TransitionBlending.SetWeightTimePoints(
                        AnimationWeightStartIncreasingTime: virtualClipElapsedTime - this.UniqueAnimationClips[i - 1].TransitionBlending.EndTransitionTime,
                        AnimationWeightEndIncreasingTime: virtualClipElapsedTime,
                        AnimationWeightStartDecreasingTime: (virtualClipElapsedTime + this.UniqueAnimationClips[i].TransitionBlending.EndClipDelay - this.UniqueAnimationClips[i - 1].TransitionBlending.EndTransitionTime) + animationClipLength,
                        AnimationWeightEndDecreasingTime: (virtualClipElapsedTime + this.UniqueAnimationClips[i].TransitionBlending.EndClipDelay - this.UniqueAnimationClips[i - 1].TransitionBlending.EndTransitionTime) + animationClipLength
                        );

                    virtualClipElapsedTime += animationClipLength + this.UniqueAnimationClips[i].TransitionBlending.EndClipDelay - this.UniqueAnimationClips[i - 1].TransitionBlending.EndTransitionTime;
                }
                else
                {
                    this.UniqueAnimationClips[i].TransitionBlending = this.UniqueAnimationClips[i].TransitionBlending.SetWeightTimePoints(
                        AnimationWeightStartIncreasingTime: virtualClipElapsedTime - this.UniqueAnimationClips[i - 1].TransitionBlending.EndTransitionTime,
                        AnimationWeightEndIncreasingTime: virtualClipElapsedTime,
                        AnimationWeightStartDecreasingTime: (virtualClipElapsedTime + this.UniqueAnimationClips[i].TransitionBlending.EndClipDelay - this.UniqueAnimationClips[i - 1].TransitionBlending.EndTransitionTime) + animationClipLength -
                        this.UniqueAnimationClips[i].TransitionBlending.EndTransitionTime,
                        AnimationWeightEndDecreasingTime: (virtualClipElapsedTime + this.UniqueAnimationClips[i].TransitionBlending.EndClipDelay - this.UniqueAnimationClips[i - 1].TransitionBlending.EndTransitionTime) + animationClipLength
                        );

                    virtualClipElapsedTime += animationClipLength + this.UniqueAnimationClips[i].TransitionBlending.EndClipDelay - this.UniqueAnimationClips[i - 1].TransitionBlending.EndTransitionTime;
                }
            }

            PlayableExtensions.SetTime(this.AnimationMixerPlayable, 0);
        }