Esempio n. 1
0
        public TwoDBlendTree(int layerId, PlayableGraph PlayableGraph, AnimationLayerMixerPlayable parentAnimationLayerMixerPlayable,
                             TwoDAnimationInput TwoDAnimationInput) : base(layerId, parentAnimationLayerMixerPlayable)
        {
            this.TwoDAnimationInput                   = TwoDAnimationInput;
            this.TwoDBlendTreeAnimationClips          = TwoDAnimationInput.TwoDBlendTreeAnimationClipInputs.ConvertAll(i => new TwoDBlendTreeAnimationClip(i.AnimationClip, i.TreePosition, i.Speed));
            this.TwoDBlendTreeAnimationClipsPositions = this.TwoDBlendTreeAnimationClips.ConvertAll(c => c.TreePosition).ToArray();
            this.Weights = new float[this.TwoDBlendTreeAnimationClipsPositions.Length];

            //create a playable mixer
            this.AnimationMixerPlayable = AnimationMixerPlayable.Create(PlayableGraph);

            foreach (var TwoDBlendTreeAnimationClip in TwoDBlendTreeAnimationClips)
            {
                var animationClipPlayable = AnimationClipPlayable.Create(PlayableGraph, TwoDBlendTreeAnimationClip.AnimationClip);
                animationClipPlayable.SetApplyFootIK(false);
                animationClipPlayable.SetApplyPlayableIK(false);
                animationClipPlayable.SetSpeed(TwoDBlendTreeAnimationClip.Speed);
                TwoDBlendTreeAnimationClip.InputHandler = PlayableExtensions.AddInput(this.AnimationMixerPlayable, animationClipPlayable, 0);
                PlayableExtensions.Play(animationClipPlayable);
                TwoDBlendTreeAnimationClip.AnimationClipPlayable = animationClipPlayable;
            }

            this.Inputhandler = PlayableExtensions.AddInput(parentAnimationLayerMixerPlayable, this.AnimationMixerPlayable, 0);
            if (TwoDAnimationInput.AvatarMask != null)
            {
                parentAnimationLayerMixerPlayable.SetLayerMaskFromAvatarMask((uint)this.Inputhandler, TwoDAnimationInput.AvatarMask);
            }
        }
Esempio n. 2
0
        public BlendedAnimationLayer(PlayableGraph PlayableGraph, AnimationLayerMixerPlayable parentAnimationLayerMixerPlayable,
                                     int layerId, List <BlendedAnimationClip> blendedAnimationClips, BlendedAnimationSpeedCurve BlendedAnimationSpeedCurve) : base(layerId, parentAnimationLayerMixerPlayable)
        {
            BlendedAnimationClips           = blendedAnimationClips;
            this.BlendedAnimationSpeedCurve = BlendedAnimationSpeedCurve;
            //create a playable mixer
            this.AnimationMixerPlayable = AnimationMixerPlayable.Create(PlayableGraph);

            foreach (var blendedAnimationClip in blendedAnimationClips)
            {
                var animationClipPlayable = AnimationClipPlayable.Create(PlayableGraph, blendedAnimationClip.AnimationClip);
                animationClipPlayable.SetApplyFootIK(false);
                animationClipPlayable.SetApplyPlayableIK(false);
                blendedAnimationClip.InputHandler = PlayableExtensions.AddInput(this.AnimationMixerPlayable, animationClipPlayable, 0);
                PlayableExtensions.Play(animationClipPlayable);
                blendedAnimationClip.AnimationClipPlayable = animationClipPlayable;
            }

            //calculate blendings
            for (var i = 0; i < blendedAnimationClips.Count; i++)
            {
                if (i == 0)
                {
                    blendedAnimationClips[i].Blending = blendedAnimationClips[i].Blending.SetWeightTimePoints(
                        AnimationWeightStartIncreasingTime: 0f,
                        AnimationWeightEndIncreasingTime: blendedAnimationClips[i].WeightTime,
                        AnimationWeightStartDecreasingTime: blendedAnimationClips[i].WeightTime,
                        AnimationWeightEndDecreasingTime: blendedAnimationClips[i + 1].WeightTime
                        );
                }
                else if (i == blendedAnimationClips.Count - 1)
                {
                    blendedAnimationClips[i].Blending = blendedAnimationClips[i].Blending.SetWeightTimePoints(
                        AnimationWeightStartIncreasingTime: blendedAnimationClips[i - 1].WeightTime,
                        AnimationWeightEndIncreasingTime: blendedAnimationClips[i].WeightTime,
                        AnimationWeightStartDecreasingTime: blendedAnimationClips[i].WeightTime,
                        AnimationWeightEndDecreasingTime: 1f
                        );
                }
                else
                {
                    blendedAnimationClips[i].Blending = blendedAnimationClips[i].Blending.SetWeightTimePoints(
                        AnimationWeightStartIncreasingTime: blendedAnimationClips[i - 1].WeightTime,
                        AnimationWeightEndIncreasingTime: blendedAnimationClips[i].WeightTime,
                        AnimationWeightStartDecreasingTime: blendedAnimationClips[i].WeightTime,
                        AnimationWeightEndDecreasingTime: blendedAnimationClips[i + 1].WeightTime
                        );
                }
            }
        }
Esempio n. 3
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.UniqueAnimationClips.ConvertAll(clip => clip.ToUniqueAnimationClip()),
                                                                      SequencedAnimationInput.isInfinite, SequencedAnimationInput.BeginTransitionTime, SequencedAnimationInput.EndTransitionTime);

            SequencedAnimationLayer.Inputhandler             = PlayableExtensions.AddInput(this.AnimationLayerMixerPlayable, SequencedAnimationLayer.AnimationMixerPlayable, 0);
            this.AllAnimationLayersCurrentlyPlaying[layerID] = SequencedAnimationLayer;
            this.OrderedByInputHandlerAnimationLayers.Add(SequencedAnimationLayer);

            this.SortLayers();

            PlayableExtensions.SetInputWeight(this.AnimationLayerMixerPlayable, SequencedAnimationLayer.Inputhandler, 1f);

            if (OnAnimationEnd != null)
            {
                SequencedAnimationLayer.ReigsterOnSequencedAnimationEnd(OnAnimationEnd);
            }
        }
Esempio n. 4
0
        private void PlayBlendedAnimation(int layerID, BlendedAnimationInput BlendedAnimationInput, Func <float> InputWeightProvider)
        {
            if (this.AllAnimationLayersCurrentlyPlaying.ContainsKey(layerID))
            {
                this.DestroyLayer(layerID);
            }

            BlendedAnimationLayer BlendedAnimationLayer = new BlendedAnimationLayer(this.GlobalPlayableGraph, this.AnimationLayerMixerPlayable, layerID,
                                                                                    BlendedAnimationInput.BlendedAnimationClips.ConvertAll(i => i.ToBlendedAnimationClip()), BlendedAnimationInput.BlendedAnimationSpeedCurve);

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

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

            this.SortLayers();

            PlayableExtensions.SetInputWeight(this.AnimationLayerMixerPlayable, this.AllAnimationLayersCurrentlyPlaying[layerID].Inputhandler, 1f);

            if (InputWeightProvider != null)
            {
                BlendedAnimationLayer.RegisterInputWeightProvider(InputWeightProvider);
            }
        }
Esempio n. 5
0
        public BlendedAnimationLayer(PlayableGraph PlayableGraph, AnimationLayerMixerPlayable parentAnimationLayerMixerPlayable,
                                     int layerId, BlendedAnimationInput BlendedAnimationInput, Func <float> InputWeightProvider) : base(layerId, parentAnimationLayerMixerPlayable)
        {
            this.BlendedAnimationInput = BlendedAnimationInput;
            this.BlendedAnimationClips = BlendedAnimationInput.BlendedAnimationClips.ConvertAll(i => i.ToBlendedAnimationClip());

            //create a playable mixer
            this.AnimationMixerPlayable = AnimationMixerPlayable.Create(PlayableGraph);

            foreach (var blendedAnimationClip in  this.BlendedAnimationClips)
            {
                var animationClipPlayable = AnimationClipPlayable.Create(PlayableGraph, blendedAnimationClip.AnimationClip);
                animationClipPlayable.SetApplyFootIK(false);
                animationClipPlayable.SetApplyPlayableIK(false);
                blendedAnimationClip.InputHandler = PlayableExtensions.AddInput(this.AnimationMixerPlayable, animationClipPlayable, 0);
                PlayableExtensions.Play(animationClipPlayable);
                blendedAnimationClip.AnimationClipPlayable = animationClipPlayable;
            }

            //calculate blendings
            for (var i = 0; i < this.BlendedAnimationClips.Count; i++)
            {
                if (i == 0)
                {
                    this.BlendedAnimationClips[i].Blending = this.BlendedAnimationClips[i].Blending.SetWeightTimePoints(
                        AnimationWeightStartIncreasingTime: 0f,
                        AnimationWeightEndIncreasingTime:  this.BlendedAnimationClips[i].WeightTime,
                        AnimationWeightStartDecreasingTime:  this.BlendedAnimationClips[i].WeightTime,
                        AnimationWeightEndDecreasingTime:  this.BlendedAnimationClips[i + 1].WeightTime
                        );
                }
                else if (i == this.BlendedAnimationClips.Count - 1)
                {
                    this.BlendedAnimationClips[i].Blending = this.BlendedAnimationClips[i].Blending.SetWeightTimePoints(
                        AnimationWeightStartIncreasingTime:  this.BlendedAnimationClips[i - 1].WeightTime,
                        AnimationWeightEndIncreasingTime:  this.BlendedAnimationClips[i].WeightTime,
                        AnimationWeightStartDecreasingTime:  this.BlendedAnimationClips[i].WeightTime,
                        AnimationWeightEndDecreasingTime: 1f
                        );
                }
                else
                {
                    this.BlendedAnimationClips[i].Blending = this.BlendedAnimationClips[i].Blending.SetWeightTimePoints(
                        AnimationWeightStartIncreasingTime:  this.BlendedAnimationClips[i - 1].WeightTime,
                        AnimationWeightEndIncreasingTime:  this.BlendedAnimationClips[i].WeightTime,
                        AnimationWeightStartDecreasingTime:  this.BlendedAnimationClips[i].WeightTime,
                        AnimationWeightEndDecreasingTime:  this.BlendedAnimationClips[i + 1].WeightTime
                        );
                }
            }

            this.Inputhandler = PlayableExtensions.AddInput(parentAnimationLayerMixerPlayable, this.AnimationMixerPlayable, 0);
            parentAnimationLayerMixerPlayable.SetLayerAdditive((uint)layerId, BlendedAnimationInput.IsAdditive);
            if (BlendedAnimationInput.AvatarMask != null)
            {
                parentAnimationLayerMixerPlayable.SetLayerMaskFromAvatarMask((uint)layerId, BlendedAnimationInput.AvatarMask);
            }

            if (InputWeightProvider != null)
            {
                this.inputWeightProvider = InputWeightProvider;
            }
        }
Esempio n. 6
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);
        }
Esempio n. 7
0
        public SequencedAnimationLayer(PlayableGraph playableGraph, AnimationLayerMixerPlayable parentAnimationLayerMixerPlayable,
                                       int layerId, List <UniqueAnimationClip> uniqueAnimationClips, bool isInfinite, float BeginTransitionTime, float EndTransitionTime) : base(layerId, parentAnimationLayerMixerPlayable)
        {
            this.isInfinite           = isInfinite;
            this.UniqueAnimationClips = uniqueAnimationClips;
            this.BeginTransitionTime  = BeginTransitionTime;
            this.EndTransitionTime    = EndTransitionTime;
            this.IsTransitioningIn    = false;
            this.IsTransitioningOut   = false;
            this.HasEnded             = false;

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

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

            if (this.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 < uniqueAnimationClips.Count; i++)
            {
                if (i == 0)
                {
                    virtualClipElapsedTime = this.BeginTransitionTime;
                    this.UniqueAnimationClips[i].TransitionBlending = this.UniqueAnimationClips[i].TransitionBlending.SetWeightTimePoints(
                        AnimationWeightStartIncreasingTime: virtualClipElapsedTime,
                        AnimationWeightEndIncreasingTime: virtualClipElapsedTime,
                        AnimationWeightStartDecreasingTime: virtualClipElapsedTime + this.UniqueAnimationClips[i].TransitionBlending.EndClipDelay + this.UniqueAnimationClips[i].AnimationClip.length - this.UniqueAnimationClips[i].TransitionBlending.EndTransitionTime,
                        AnimationWeightEndDecreasingTime: virtualClipElapsedTime + this.UniqueAnimationClips[i].TransitionBlending.EndClipDelay + this.UniqueAnimationClips[i].AnimationClip.length
                        );

                    virtualClipElapsedTime += this.UniqueAnimationClips[i].AnimationClip.length + 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) + this.UniqueAnimationClips[i].AnimationClip.length,
                        AnimationWeightEndDecreasingTime: (virtualClipElapsedTime + this.UniqueAnimationClips[i].TransitionBlending.EndClipDelay - this.UniqueAnimationClips[i - 1].TransitionBlending.EndTransitionTime) + this.UniqueAnimationClips[i].AnimationClip.length
                        );

                    virtualClipElapsedTime += this.UniqueAnimationClips[i].AnimationClip.length + 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) + this.UniqueAnimationClips[i].AnimationClip.length -
                        this.UniqueAnimationClips[i].TransitionBlending.EndTransitionTime,
                        AnimationWeightEndDecreasingTime: (virtualClipElapsedTime + this.UniqueAnimationClips[i].TransitionBlending.EndClipDelay - this.UniqueAnimationClips[i - 1].TransitionBlending.EndTransitionTime) + this.UniqueAnimationClips[i].AnimationClip.length
                        );

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

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