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, InputWeightProvider); this.AllAnimationLayersCurrentlyPlaying[layerID] = BlendedAnimationLayer; this.OrderedByInputHandlerAnimationLayers.Add(BlendedAnimationLayer); this.SortLayers(); PlayableExtensions.SetInputWeight(this.AnimationLayerMixerPlayable, this.AllAnimationLayersCurrentlyPlaying[layerID].Inputhandler, 1f); }
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); } }
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; } }