protected 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) * (1 / frameSpeed));//フレーム取得 //ループ if (nowFrame >= (int)((nowPlayAnimation.length * nowPlayAnimation.frameRate * (1.0f / frameSpeed))) && nowPlayAnimation.isLooping) { mixer.SetTime(0); _nowPlayAnimation.SetTime(0); if (_beforePlayAnimation.IsValid()) { _beforePlayAnimation.SetTime(0); } } } }
//次のアニメーションをセットするときに呼び出す public void SetPlayAnimation(AnimationClip clip, float speed, int weightFrame = 0) { setClip = clip; changeWeightFrame = weightFrame; animationSpeed = speed; frameCount = 0; if (playableGraph.IsValid() && mixer.IsValid()) { beforeClipTime = nowClipPlayable.GetTime(); mixer.SetTime(0); nowClipPlayable.SetTime(0); if (beforeClipPlayable.IsValid()) { beforeClipPlayable.SetTime(0); } } }