コード例 #1
0
 void Update()
 {
     delayTime -= Time.deltaTime;
     if (delayTime < 0)
     {
         if (leftTime > 0)
         {
             leftTime = Mathf.Clamp(leftTime - Time.deltaTime, 0, tranTime);
             float weight = leftTime / tranTime;
             m_Mixer.SetInputWeight(0, weight);
             m_Mixer.SetInputWeight(1, 1 - weight);
         }
     }
 }
コード例 #2
0
        //===========================================================================================

        /**
         *  @brief
         *
         *********************************************************************************************/
        private void SetupPreviewGraph()
        {
            List <AnimationClip> clips = m_data.Clips;

            m_blendWeights = new List <float>(clips.Count + 1);

            AnimationMixerPlayable mixer = MxMPreviewScene.Mixer;

            mixer.SetInputCount(clips.Count);

            float blendSpaceLength    = clips[0].length;
            float normalizedClipSpeed = 1f;

            for (int i = 0; i < clips.Count; ++i)
            {
                AnimationClip clip = clips[i];

                var clipPlayable = AnimationClipPlayable.Create(MxMPreviewScene.PlayableGraph, clip);

                if (clipPlayable.IsValid())
                {
                    if (m_spNormalizeTime.boolValue)
                    {
                        normalizedClipSpeed = clip.length / blendSpaceLength;
                    }

                    clipPlayable.SetTime(0.0);
                    clipPlayable.SetSpeed(normalizedClipSpeed);
                    mixer.ConnectInput(i, clipPlayable, 0);

                    if (i > 0)
                    {
                        mixer.SetInputWeight(i, 0f);
                        m_blendWeights.Add(0f);
                    }
                    else
                    {
                        mixer.SetInputWeight(i, 1f);
                        m_blendWeights.Add(1f);
                    }
                }
            }

            CalculateBlendWeights();
            ApplyBlendWeights();

            m_lastPlayIncTime = (float)EditorApplication.timeSinceStartup;
        }
コード例 #3
0
ファイル: AnimGraph_Emote.cs プロジェクト: TashaSkyUp/Staging
        public Instance(EntityManager entityManager, Entity owner, PlayableGraph graph, Entity animStateOwner, AnimGraph_Emote settings)
        {
            m_EntityManager  = entityManager;
            m_Owner          = owner;
            m_AnimStateOwner = animStateOwner;
            m_settings       = settings;

            m_mixer = AnimationMixerPlayable.Create(graph, settings.emoteData.Length + 1);

            var ports = new int[m_settings.emoteData.Length + 1];

            for (var i = 0; i < ports.Length; i++)
            {
                ports[i] = i;
            }

            m_Transition = new SimpleTranstion <AnimationMixerPlayable>(m_mixer, ports);

            for (int i = 0; i < settings.emoteData.Length; i++)
            {
                var clip         = settings.emoteData[i].clip;
                var clipPlayable = AnimationClipPlayable.Create(graph, clip);
                clipPlayable.SetDuration(clip.length);
                clipPlayable.Pause();

                var port = i + 1;
                m_mixer.ConnectInput(port, clipPlayable, 0);
                m_mixer.SetInputWeight(port, 0.0f);
            }
        }
コード例 #4
0
        public void PlayAnimation(Playable owner, AnimationClip clip)
        {
            var bindIndex = _clipData.FindIndex(cd => cd.Clip == clip);

            if (bindIndex == -1)
            {
                owner.Pause();
                return;
            }

            var data = _clipData[bindIndex];

            CurrentClipIndex = data.MixerIndex;

            var clipPlayable = (AnimationClipPlayable)Mixer.GetInput(CurrentClipIndex);

            clipPlayable.SetTime(0.0);

            var inputCount = Mixer.GetInputCount();

            for (var idx = 0; idx < inputCount; idx++)
            {
                Mixer.SetInputWeight(idx, idx != CurrentClipIndex ? 0.0f : 1.0f);
            }

            owner.Play();
        }
コード例 #5
0
        public static void RemoveZeroWeightsInputs(AnimationMixerPlayable mixer)
        {
            int size = mixer.GetInputCount();

            for (int i = 0; i < size; i++)
            {
                if (mixer.GetInputWeight(i) <= 0)
                {
                    mixer.GetInput(i).Destroy();
                    for (int j = i + 1; j < size; j++)
                    {
                        // double localTime = ((AnimationClipPlayable)mixer.GetInput(j)).GetTime();
                        float    _weight = mixer.GetInputWeight(j);
                        Playable clip    = mixer.GetInput(j);
                        // clip.SetTime(localTime);
                        mixer.DisconnectInput(j);
                        mixer.ConnectInput(j - 1, clip, 0);
                        mixer.SetInputWeight(j - 1, _weight);
                    }
                    i--;
                    size--;
                    mixer.SetInputCount(size);
                }
            }
        }
コード例 #6
0
    public override void PrepareFrame(Playable owner, FrameData info)
    {
        int ClipCount = m_mixerPlayable.GetInputCount();

        if (ClipCount == 0)
        {
            return;
        }

        m_timeToNextClip -= info.deltaTime;

        if (m_timeToNextClip <= 0.0f)
        {
            m_currentClipIndex++;
            if (m_currentClipIndex >= ClipCount)
            {
                m_currentClipIndex = 0;
            }
            var currentClip = (AnimationClipPlayable)m_mixerPlayable.GetInput(m_currentClipIndex);

            //SetTime(0),从头开始播放动画
            currentClip.SetTime(0);
            m_timeToNextClip = currentClip.GetAnimationClip().length;
        }

        //利用权重来设置当前播放的Clip
        for (int clipIndex = 0; clipIndex < ClipCount; ++clipIndex)
        {
            m_mixerPlayable.SetInputWeight(clipIndex, clipIndex == m_currentClipIndex ? 1 : 0);
        }
    }
コード例 #7
0
            public Instance(AnimStateController controller, PlayableGraph graph, AnimGraphStand settings)
            {
                m_Settings       = settings;
                m_AnimState      = controller.GetComponent <AnimStateData>();
                m_PredictedState = controller.GetComponent <LogicStateData>();

                m_Mask = 1 << LayerMask.NameToLayer("Default") | 1 << LayerMask.NameToLayer("Platform");

                m_LocomotionMixer = AnimationMixerPlayable.Create(graph, (int)LocoMixerPort.Count);

                m_AnimIdle = AnimationClipPlayable.Create(graph, settings.animIdle);
                graph.Connect(m_AnimIdle, 0, m_LocomotionMixer, (int)LocoMixerPort.Idle);
                m_LocomotionMixer.SetInputWeight((int)LocoMixerPort.Idle, 1.0f);

                m_AnimTurnL = CreateTurnPlayable(graph, settings.animTurnL, m_LocomotionMixer, LocoMixerPort.TurnL);
                m_AnimTurnR = CreateTurnPlayable(graph, settings.animTurnR, m_LocomotionMixer, LocoMixerPort.TurnR);

                var ports = new int[] { (int)LocoMixerPort.Idle, (int)LocoMixerPort.TurnL, (int)LocoMixerPort.TurnR };

                m_Transition = new SimpleTranstion <AnimationMixerPlayable>(m_LocomotionMixer, ports);

                if (settings.animTurnL.events.Length != 0)
                {
                    m_LeftTurnFootFalls  = ExtractFootFalls(settings.animTurnL);
                    m_RightTurnFootFalls = ExtractFootFalls(settings.animTurnR);
                }

                var animator  = controller.GetComponent <Animator>();
                var skeleton  = controller.GetComponent <Skeleton>();
                var leftToes  = skeleton.bones[skeleton.GetBoneIndex(settings.leftToeBone.GetHashCode())];
                var rightToes = skeleton.bones[skeleton.GetBoneIndex(settings.rightToeBone.GetHashCode())];

                var ikJob = new FootIkJob
                {
                    settings = settings.footIK,
                    leftToe  = animator.BindStreamTransform(leftToes),
                    rightToe = animator.BindStreamTransform(rightToes)
                };

                m_FootIk = AnimationScriptPlayable.Create(graph, ikJob, 1);
                graph.Connect(m_LocomotionMixer, 0, m_FootIk, 0);
                m_FootIk.SetInputWeight(0, 1f);

                m_AimMixer = AnimationMixerPlayable.Create(graph, (int)AimMixerPort.Count, true);

                m_AnimAimLeft  = CreateAimPlayable(graph, settings.animAimLeft, m_AimMixer, AimMixerPort.AimLeft);
                m_AnimAimMid   = CreateAimPlayable(graph, settings.animAimMid, m_AimMixer, AimMixerPort.AimMid);
                m_AnimAimRight = CreateAimPlayable(graph, settings.animAimRight, m_AimMixer, AimMixerPort.AimRight);

                m_AdditiveMixer = AnimationLayerMixerPlayable.Create(graph);

                var locoMixerPort = m_AdditiveMixer.AddInput(m_FootIk, 0);

                m_AdditiveMixer.SetInputWeight(locoMixerPort, 1);

                var aimMixerPort = m_AdditiveMixer.AddInput(m_AimMixer, 0);

                m_AdditiveMixer.SetInputWeight(aimMixerPort, 1);
                m_AdditiveMixer.SetLayerAdditive((uint)aimMixerPort, true);
            }
コード例 #8
0
    void Update()
    {
        if (!mixer.IsValid() || Speed == 0)
        {
            return;
        }
        var cWeight = mixer.GetInputWeight(0);

        if (cWeight < 1)
        {
            cWeight = Mathf.Lerp(0, 1, (Time.time - changeTime) / blendTime);
            mixer.SetInputWeight(0, cWeight);
            mixer.SetInputWeight(1, 1 - cWeight);
        }
        graph.Evaluate(Time.deltaTime * Speed);
    }
コード例 #9
0
        internal Playable CompileTrackPlayable(PlayableGraph graph, TrackAsset track, GameObject go, IntervalTree <RuntimeElement> tree)
        {
            AnimationMixerPlayable animationMixerPlayable = AnimationMixerPlayable.Create(graph, track.clips.Length, false);

            for (int i = 0; i < track.clips.Length; i++)
            {
                TimelineClip  timelineClip  = track.clips[i];
                PlayableAsset playableAsset = timelineClip.asset as PlayableAsset;
                if (!(playableAsset == null))
                {
                    if (timelineClip.recordable)
                    {
                        AnimationPlayableAsset animationPlayableAsset = playableAsset as AnimationPlayableAsset;
                        if (animationPlayableAsset != null)
                        {
                            animationPlayableAsset.removeStartOffset = !timelineClip.recordable;
                        }
                    }
                    Playable playable = playableAsset.CreatePlayable(graph, go);
                    if (playable.IsValid <Playable>())
                    {
                        RuntimeClip item = new RuntimeClip(timelineClip, playable, animationMixerPlayable);
                        tree.Add(item);
                        graph.Connect <Playable, AnimationMixerPlayable>(playable, 0, animationMixerPlayable, i);
                        animationMixerPlayable.SetInputWeight(i, 0f);
                    }
                }
            }
            return(this.ApplyTrackOffset(graph, animationMixerPlayable));
        }
コード例 #10
0
        public void BlendPlayablesInStateMixer(
            ref AnimationMixerPlayable stateMixer,
            List <float> blendingSpeeds,
            List <float> currentWeights,
            float minWeightToAchive = 0f,
            float blendTime         = 0.5f
            )
        {
            int   size      = stateMixer.GetInputCount();
            float weightSum = 0;

            for (int i = 0; i < size; i++)
            {
                if (i < (size - 1) && minWeightToAchive <= currentWeights[i] && blendingSpeeds[i] > 0)
                {
                    blendingSpeeds[i] = -(currentWeights[i] / blendTime);
                }
                currentWeights[i] = Mathf.Clamp01(currentWeights[i] + (blendingSpeeds[i] * Time.deltaTime));
                weightSum        += currentWeights[i];
            }

            for (int i = 0; i < size; i++)
            {
                stateMixer.SetInputWeight(i, currentWeights[i] / weightSum);
            }
        }
コード例 #11
0
        private void Start()
        {
            playableGraph = PlayableGraph.Create();
            var playableOutput = AnimationPlayableOutput.Create(playableGraph, "Animation", GetComponent <Animator>());

            mixerPlayable = AnimationMixerPlayable.Create(playableGraph, 2);
            playableOutput.SetSourcePlayable(mixerPlayable);
            var clipPlayable0 = AnimationClipPlayable.Create(playableGraph, clip0);
            var clipPlayable1 = AnimationClipPlayable.Create(playableGraph, clip1);

            playableGraph.Connect(clipPlayable0, 0, mixerPlayable, 0);
            playableGraph.Connect(clipPlayable1, 0, mixerPlayable, 1);
            mixerPlayable.SetInputWeight(0, 1.0f);
            mixerPlayable.SetInputWeight(1, 1.0f);
            clipPlayable1.SetPlayState(PlayState.Paused);
            playableGraph.Play();
        }
コード例 #12
0
    // Use this for initialization
    void Start()
    {
        animator = GetComponent <Animator>();

        playableGraph = PlayableGraph.Create("ClairePlayableGraph");
        playableGraph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);
        var playableOutput = AnimationPlayableOutput.Create(playableGraph, "Animation", animator);

        // Create Top Level Layer Mixer
        AnimationLayerMixerPlayable mixerLayerPlayable = AnimationLayerMixerPlayable.Create(playableGraph, 2);

        playableOutput.SetSourcePlayable(mixerLayerPlayable);

        // Create an Emotion Mixer
        mixerEmotionPlayable = AnimationMixerPlayable.Create(playableGraph, 4);

        // Wrap AnimController
        runtimeAnimController = animator.runtimeAnimatorController;
        var runtimeAnimControllerPlayable = AnimatorControllerPlayable.Create(playableGraph, runtimeAnimController);

        // Connect to Top Level Layer Mixer
        playableGraph.Connect(runtimeAnimControllerPlayable, 0, mixerLayerPlayable, 0);
        playableGraph.Connect(mixerEmotionPlayable, 0, mixerLayerPlayable, 1);
        mixerLayerPlayable.SetInputWeight(0, 1.0f);
        mixerLayerPlayable.SetInputWeight(1, 1.0f);
        mixerLayerPlayable.SetLayerMaskFromAvatarMask(1, headMask);

        // Wrap the clips in a playable
        pHappy             = AnimationClipPlayable.Create(playableGraph, happy);
        pHappyTransitionIn = AnimationClipPlayable.Create(playableGraph, happyTransitionIn);
        pAngry             = AnimationClipPlayable.Create(playableGraph, angry);
        pAngryTransitionIn = AnimationClipPlayable.Create(playableGraph, angryTransitionIn);
        pTPose             = AnimationClipPlayable.Create(playableGraph, tPose);

        // Setup Durations for IsDone Checks
        pHappyTransitionIn.SetDuration(happyTransitionIn.length);
        pAngryTransitionIn.SetDuration(angryTransitionIn.length);

        // Connect to Emotion Mixer
        mixerEmotionPlayable.SetInputCount(5); // InputCount needs to be == to the number of connected clips (for normalization purposes)
        playableGraph.Connect(pHappy, 0, mixerEmotionPlayable, 0);
        playableGraph.Connect(pHappyTransitionIn, 0, mixerEmotionPlayable, 1);
        playableGraph.Connect(pAngry, 0, mixerEmotionPlayable, 2);
        playableGraph.Connect(pAngryTransitionIn, 0, mixerEmotionPlayable, 3);
        playableGraph.Connect(pTPose, 0, mixerEmotionPlayable, 4);

        Debug.Log("INputLength: " + mixerEmotionPlayable.GetInputCount());



        // Activate T Pose
        mixerEmotionPlayable.SetInputWeight(4, 1.0f);

        Debug.Log("Happy Transition Time: " + pHappyTransitionIn.GetDuration());

        // Plays the Graph
        playableGraph.Play();
    }
コード例 #13
0
 public void UpdateGraph()
 {
     for (var i = 0; i < m_Clips.Length; i++)
     {
         m_Mixer.SetInputWeight(i, m_Weights[i]);
         m_Clips[i].SetSpeed(m_Nodes[i].clipLength / m_BlendedClipLength);
         m_Clips[i].SetApplyFootIK(footIk);
     }
 }
コード例 #14
0
        public void Blend(AnimationScriptPlayable playable, float duration, AnimationCurve transitionCurve)
        {
            if (tweening && lastTween != null)
            {
                lastTween.callOnCompletes();
                lastTween.setOnUpdate((float value) => { });
                lastTween.setOnComplete(() => { });
                // LeanTween.pause(lastTween.id);
            }

            // tweenPlayable = AnimatorControllerPlayable.Create(playableGraph, ac);
            tweenPlayable = playable;
            mixerPlayable = AnimationMixerPlayable.Create(playableGraph, 2);

            mixerPlayable.ConnectInput(0, activePlayable, 0);
            mixerPlayable.ConnectInput(1, tweenPlayable, 0);

            // Plays the Graph.
            mixerPlayable.SetInputWeight(0, 1);
            playableOutput.SetSourcePlayable(mixerPlayable);

            lastTween = LeanTween
                        .value(playerController.gameObject, 0f, 1f, duration)
                        .setEase(transitionCurve)
                        .setOnUpdate((float value) =>
            {
                mixerPlayable.SetInputWeight(0, 1f - value);
                mixerPlayable.SetInputWeight(1, value);
            })
                        .setOnComplete(() =>
            {
                tweening = false;

                playableGraph.Disconnect(mixerPlayable, 0);
                playableGraph.Disconnect(mixerPlayable, 1);
                playableOutput.SetSourcePlayable(tweenPlayable);
                var prevActive = activePlayable;
                activePlayable = tweenPlayable;
                // prevActive.Destroy();
                mixerPlayable.Destroy();
            });

            tweening = true;
        }
コード例 #15
0
 // Update is called once per frame
 void Update()
 {
     mixerEmotionPlayable.SetInputWeight(0, weightInterested);
     mixerEmotionPlayable.SetInputWeight(1, weightInterested2);
     mixerEmotionPlayable.SetInputWeight(2, weightEntertained);
     mixerEmotionPlayable.SetInputWeight(3, weightUncomfortable);
     mixerEmotionPlayable.SetInputWeight(4, weightConfused);
     mixerEmotionPlayable.SetInputWeight(5, weightBored);
     mixerEmotionPlayable.SetInputWeight(6, weightNeutral);
     normalizeWeights();
 }
コード例 #16
0
        /// <summary>
        /// Use this for initialization
        /// </summary>
        private void Awake()
        {
            // Create playable graph.
            playableGraph = PlayableGraph.Create();

            // Create playable output node.
            var playableOutput = AnimationPlayableOutput.Create(playableGraph, "Animation", GetComponent <Animator>());

            // Create animation mixer playerable node.
            int animationClipsLength = animationClips == null ? 0 : animationClips.Length;

            animationMixer = AnimationMixerPlayable.Create(playableGraph, animationClipsLength);

            // Connect the mixer to an output.
            playableOutput.SetSourcePlayable(animationMixer);

            // Create clip playable node for all animations.
            for (int i = 0; i < animationClipsLength; i++)
            {
                // Wrap the clip in a playable.
                var clipPlayable = AnimationClipPlayable.Create(playableGraph, animationClips[i]);

                playableGraph.Connect(clipPlayable, 0, animationMixer, i);
                animationMixer.SetInputWeight(i, 0.0f);
            }

            // Create audio output node.
            var audioOutput = AudioPlayableOutput.Create(playableGraph, "Audio", GetComponent <AudioSource>());

            // Create audio mixer playerable node.
            int audioClipsLength = audioClips == null ? 0 : audioClips.Length;

            audioMixer = AudioMixerPlayable.Create(playableGraph, audioClipsLength);

            // Connect the mixer to an output.
            audioOutput.SetSourcePlayable(audioMixer);

            // Create clip playable node for all audios.
            for (int i = 0; i < audioClipsLength; i++)
            {
                // Wrap the clip in a playable.
                var clipPlayable = AudioClipPlayable.Create(playableGraph, audioClips[i], false);

                playableGraph.Connect(clipPlayable, 0, audioMixer, i);
                audioMixer.SetInputWeight(i, 0.0f);
            }

            // Init the animation component list.
            currentAnimationList = new List <AnimationComponent>();

            // Plays the playable graph.
            playableGraph.Play();

            // Register graph visual client to show debug messages.
            GraphVisualizerClient.Show(playableGraph, "Animation Engine Graph");
        }
コード例 #17
0
        public PlayingState(PlayableGraph playableGraph, AnimationMixerPlayable rootMixerPlayable, State state)
        {
            this.state             = state;
            this.playableGraph     = playableGraph;
            this.rootMixerPlayable = rootMixerPlayable;

            clipPlayable = AnimationClipPlayable.Create(playableGraph, state.enterAnimation);
            playableGraph.Connect(clipPlayable, 0, rootMixerPlayable, 0);
            rootMixerPlayable.SetInputWeight(0, 1);
            clipPlayable.Play();
        }
コード例 #18
0
 public void SetWeight(int index, float weight)
 {
     if (!Animation.IsNull() && Animation.IsValid())
     {
         Animation.SetInputWeight(index, weight);
     }
     if (!Audio.IsNull() && Audio.IsValid())
     {
         Audio.SetInputWeight(index, weight);
     }
 }
コード例 #19
0
    void Update()
    {
        if (Input.GetKey(KeyCode.J))
        {
            // Bind the playable graph to the player
            mixer.SetInputWeight(0, 1);
            mixer.SetInputWeight(1, 0);
            animator.Play(mixer);
        }

        if (Input.GetKey(KeyCode.U))
        {
            mixer.SetInputWeight(0, 0);
            mixer.SetInputWeight(1, 1);
            //animator.Play(mixer);

            // rewind otherwise the give clip is not played.
            clipPlayable.time = 0f;
        }
    }
コード例 #20
0
    public void PlayClip(string clipName)
    {
        if (!clipIndexes.ContainsKey(clipName))
        {
            return;
        }
        int playingClipIndex = clipIndexes[clipName];

        for (int i = 0; i < animationMixer.GetInputCount(); i++)
        {
            if (i != playingClipIndex)
            {
                animationMixer.SetInputWeight(i, 0);
            }
            else
            {
                animationMixer.SetInputWeight(i, 1);
            }
        }
    }
コード例 #21
0
        protected void InitPlayable()
        {
            graph = PlayableGraph.Create();
            mixer = AnimationMixerPlayable.Create(graph, 2, true);
            mixer.ConnectInput(0, currentPlayable, 0);
            mixer.SetInputWeight(0, 1);
            var output = AnimationPlayableOutput.Create(graph, name + " output", animator);

            output.SetSourcePlayable(mixer, 0);
            graph.Play();
        }
コード例 #22
0
        public override void OnChangeClip(ClipBehaviour fromClip, float fromWeight, ClipBehaviour toClip, float toWeight)
        {
            m_Mixer.DisconnectInput(0);
            m_Mixer.DisconnectInput(1);

            if (fromClip != null)
            {
                var playable = ((AnimationClipBehaviour)fromClip).Playable;
                m_Mixer.ConnectInput(0, playable, 0, fromWeight);
            }

            if (toClip != null)
            {
                var playable = ((AnimationClipBehaviour)toClip).Playable;
                m_Mixer.ConnectInput(1, playable, 0, toWeight);
            }

            m_Mixer.SetInputWeight(0, fromWeight);
            m_Mixer.SetInputWeight(1, toWeight);
        }
コード例 #23
0
        /*
         * //</private Methods>
         */


        private IEnumerator Trans()
        {
            var wait_time = Time.timeSinceLevelLoad + transtime;

            yield return(new WaitWhile(() => {
                var diff = wait_time - Time.timeSinceLevelLoad;
                if (diff <= 0)
                {
                    mixer.SetInputWeight(1, 0);
                    mixer.SetInputWeight(0, 1);
                    return false;
                }
                else
                {
                    var rate = Mathf.Clamp01(diff / transtime);
                    mixer.SetInputWeight(1, rate);
                    mixer.SetInputWeight(0, 1 - rate);
                    return true;
                }
            }));
        }
コード例 #24
0
    public void SetAnimationClip(AnimationClip clip, AnimationClip endClip)
    {
        clipPlayable    = AnimationClipPlayable.Create(playableGraph, clip);
        endClipPlayable = AnimationClipPlayable.Create(playableGraph, endClip);

        inputIndex    = animMixer.AddInput(clipPlayable, 0, 0);
        inputIndexEnd = animMixer.AddInput(endClipPlayable, 0, 0);
        animMixer.SetInputWeight(inputIndex, 0);
        animMixer.SetInputWeight(inputIndexEnd, 0);
    }
        public void Update(MotionMatchingPlayableGraph graph, bool passIK, bool passFootIK, float deltaTime)
        {
            currentClipTime += deltaTime;

            float seqLocalTime = GetLocalTime();

            for (int i = 0; i < data.clips.Count; i++)
            {
                float currentPlayableTime = GetPlayableTimeInSequenceLocalTime(seqLocalTime, i);
                float currentWeight       = mixer.GetInputWeight(i);
                float desiredWeight       = GetPlayableWeightInPlayableTime(currentPlayableTime, i);

                if (currentWeight <= 0f && desiredWeight > 0f)
                {
                    mixer.GetInput(i).SetTime(currentPlayableTime - Time.deltaTime);
                    mixer.GetInput(i).SetTime(currentPlayableTime);
                }
                mixer.SetInputWeight(i, desiredWeight);
            }
            NormalizeMixerInputWeights();
        }
コード例 #26
0
    // Start is called before the first frame update
    void Start()
    {
        PlayableGraph          graph = PlayableGraph.Create();
        AnimationClipPlayable  clip1 = AnimationClipPlayable.Create(graph, clip01);
        AnimationClipPlayable  clip2 = AnimationClipPlayable.Create(graph, clip02);
        AnimationMixerPlayable mixer = AnimationMixerPlayable.Create(graph, 2, true);

        mixer.SetInputWeight(4, 0.5f);
        mixer.SetInputWeight(9, 0.5f);

        AnimationPlayableOutput output = AnimationPlayableOutput.Create(graph, "out", GetComponent <Animator>());

        graph.Connect(clip1, 0, mixer, 4);
        graph.Connect(clip2, 0, mixer, 9);
        Playable playable = Playable.Create(graph, 1);

        graph.Connect(mixer, 0, playable, 0);
        output.SetSourcePlayable(playable);

        graph.Play();
    }
コード例 #27
0
        void CreatePlayableGraph()
        {
            playableGraph = PlayableGraph.Create();
            var playableOutput = AnimationPlayableOutput.Create(playableGraph, "PlayableGraphSample", GetComponent <Animator>());

            mixerPlayable = AnimationMixerPlayable.Create(playableGraph, 2);
            playableOutput.SetSourcePlayable(mixerPlayable);
            var clipPlayable1 = AnimationClipPlayable.Create(playableGraph, clip1);
            var clipPlayable2 = AnimationClipPlayable.Create(playableGraph, clip2);

            //playableGraph.Connect(clipPlayable1,0,mixerPlayable,0);
            //playableGraph.Connect(clipPlayable2, 0, mixerPlayable, 1);
            //上面的两行与下面的两行代码是等价的
            mixerPlayable.ConnectInput(0, clipPlayable1, 0);
            mixerPlayable.ConnectInput(1, clipPlayable2, 0);
            weight = Mathf.Clamp01(weight);
            mixerPlayable.SetInputWeight(0, 1.0f - weight);//分别设置两个数据端口的权重
            mixerPlayable.SetInputWeight(1, weight);
            playableGraph.Play();
            GraphVisualizerClient.Show(playableGraph, this.GetType().Name);
        }
コード例 #28
0
 public bool ChangeAnimation(RuntimeAnimatorController animatorController, float time)
 {
     StopAllCoroutines();
     animatorPlayables[next] = AnimatorControllerPlayable.Create(playableGraph, animatorController);
     playableGraph.Disconnect(mixPlayable, next);
     playableGraph.Connect(animatorPlayables[next], 0, mixPlayable, next);
     mixPlayable.SetInputWeight(current, 1);
     mixPlayable.SetInputWeight(next, 0);
     nextAnimatorController = animatorController;
     transit = true;
     this.NumericAnimate(time, tick: (t) =>
     {
         //Debug.Log(t);
         mixPlayable.SetInputWeight(current, 1 - t);
         mixPlayable.SetInputWeight(next, t);
     }, complete: () =>
     {
         mixPlayable.SetInputWeight(current, 0);
         mixPlayable.SetInputWeight(next, 1);
         current++;
         currentAnimatorController = nextAnimatorController;
         nextAnimatorController    = null;
         transit = false;
     });
     return(true);
 }
コード例 #29
0
            static AnimationClipPlayable CreateTurnPlayable(PlayableGraph graph, AnimationClip clip, AnimationMixerPlayable mixer, LocoMixerPort mixerPort)
            {
                AnimationClipPlayable playable = AnimationClipPlayable.Create(graph, clip);

                playable.SetApplyFootIK(true);
                playable.Pause();
                playable.SetDuration(clip.length);

                graph.Connect(playable, 0, mixer, (int)mixerPort);
                mixer.SetInputWeight((int)mixerPort, 0.0f);

                return(playable);
            }
コード例 #30
0
        public void Tick(float deltaTime)
        {
            _playableGraph.Evaluate(deltaTime);

            for (int i = 0; i < AnimationPlayLayers.Length; i++)
            {
                var currLayer = AnimationPlayLayers[i];

                if (currLayer.GetWeight(out var aW, out var bW))
                {
                    mixerPlayable.SetInputWeight(currLayer.aInputIndex, aW);
                    mixerPlayable.SetInputWeight(currLayer.bInputIndex, bW);

                    if (aW <= 0)
                    {
                        mixerPlayable.DisconnectInput(currLayer.aInputIndex);
                        currLayer.EndBInput();
                    }
                }
                currLayer.Time += deltaTime;
            }
        }