コード例 #1
0
 protected void Cleanup()
 {
     if (graph.IsValid())
     {
         graph.Stop();
     }
     if (mixerCoroutine != null)
     {
         StopCoroutine(mixerCoroutine);
         mixerCoroutine = null;
     }
     if (currentPlayable.IsValid())
     {
         currentPlayable.Destroy();
     }
     if (previousPlayable.IsValid())
     {
         previousPlayable.Destroy();
     }
     if (mixer.IsValid())
     {
         mixer.Destroy();
     }
     if (graph.IsValid())
     {
         graph.Destroy();
     }
 }
コード例 #2
0
 private void Update()
 {
     if (nowPlayAnimation == null)
     {
         if (mixer.IsValid())
         {
             mixer.Destroy();
         }
         _beforeNowPlayClip = null;
     }
     else if (_beforeNowPlayClip != nowPlayAnimation)
     {
         SetPlayAnimation(nowPlayAnimation, frameSpeed, changeFrameNow);
     }
     SetNextAnimationPlayable();
     if (playableGraph.IsValid() && mixer.IsValid())
     {
         if (frameSpeed <= 0)
         {
             return;
         }
         if (changeWeightFrame > 0)
         {
             mixer.SetInputWeight(0, (1.0f - num) - ((1.0f) - (((float)_nowChangeFrame) / ((float)changeWeightFrame))));
             mixer.SetInputWeight(1, num + ((1.0f) - (((float)_nowChangeFrame) / ((float)changeWeightFrame))));
             if (_nowChangeFrame >= changeWeightFrame)
             {
                 changeWeightFrame = 0;
                 _nowChangeFrame   = 0;
             }
             _nowChangeFrame++;
         }
         else
         {
             mixer.SetInputWeight(0, (1.0f - num));
             mixer.SetInputWeight(1, num);
         }
         playableGraph.Evaluate((1.0f / nowPlayAnimation.frameRate) * frameSpeed);
         nowFrame = (int)(((float)mixer.GetTime() * nowPlayAnimation.frameRate) * frameSpeed);
         //ループ
         if (nowFrame >= (nowPlayAnimation.length * nowPlayAnimation.frameRate * frameSpeed) && nowPlayAnimation.isLooping)
         {
             mixer.SetTime(0);
             _nowPlayAnimation.SetTime(0);
             if (_beforePlayAnimation.IsValid())
             {
                 _beforePlayAnimation.SetTime(0);
             }
         }
     }
 }
コード例 #3
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;
        }
コード例 #4
0
 //Updateの最初に処理する
 private void AnimationPlayableSetting()
 {
     //playableGraphが登録されていなければ登録
     if (!(playableGraph.IsValid()))
     {
         playableGraph = PlayableGraph.Create();
     }
     //再生中のアニメーションがなければmixerを削除して停止
     if (nowClip == null)
     {
         if (mixer.IsValid())
         {
             mixer.Destroy();                 //mixerの削除
         }
         beforeClip = null;
     }
     //再生中のAnimationClipが変更されたら再生を変更(Editor上で入れ替える時に使用、同じアニメーションクリップを連続で再生は出来ない)
     else if (beforeClip != nowClip)
     {
         SetPlayAnimation(nowClip, animationSpeed, changeWeightFrame);
     }
     //別のAnimationが次に再生するアニメーションとしてセットされたらPlayableを変更する
     SetAnimationPlayable();
 }
コード例 #5
0
ファイル: MMAgent.cs プロジェクト: unitycoder/MotionMatching
 private void OnDestroy()
 {
     m_currentClip.Destroy();
     m_mixer.Destroy();
     m_graph.Destroy();
 }