public void CheckStateAnimation(AnimatorParamer paramer) { if (ShouldPlay && Animator != default) { if (!IsAniPlaying) { IsAniPlaying = true; if (MotionRepeates > 0) { mTotalNormalizedTime = MotionRepeates * 1f; paramer.SetMotionCount(MotionRepeates); } else { paramer.SetMotionCount(1); } if (!paramer.IsSetWillPlay) { paramer.SetMotionWillPlay(AnimationName, StateName, LayerIndex);//同步状态数据到参数器中 } else { } PlayMotion(ref paramer); } else { } } else { } }
public override void Dispose() { base.Dispose(); AniParamer?.Clear(); AniParamer = default; }
protected virtual void PlayMotion(ref AnimatorParamer paramer) { if (mParamerFields == default) { mParamerFields = new ParamerFields(); } else { } if (IsRewind)//是否倒播 { paramer.SetNormalizedTime(1f); mParamerFields.speedRevert = Animator.GetFloat(mParamerFields.speedField); Animator.SetFloat(mParamerFields.speedField, -1f); } else { } mMotionNameTemp = paramer.MotionName; //设置动画名 int layerIndex = paramer.AniMaskLayerWillPlay; //设置遮罩层索引 float normalizedTime = paramer.NormalizedTime; //设置播放起点的标准化时间 Animator.Play(mMotionNameTemp, layerIndex, normalizedTime); //播放动画 }
public AnimatorStateMachine(Animator target, int name, Action <IStateMachine> fsmRegister = default) : base(name, fsmRegister) { AniParamer = new AnimatorParamer(); Init(ref target); AniParamer.SetAnimator(ref target); }
private void MotionCompletionRepeatable(ref AnimatorParamer paramer) { bool isCompleted = IsAnimationComplete(ref paramer); if (isCompleted) { mTotalNormalizedTime = MotionRepeates * 1f - paramer.GetStateInfo(LayerIndex).normalizedTime; if (isCompleted && mTotalNormalizedTime <= 0f) { IsAniPlaying = false; } else { } } else { } }
public void CheckMotionComplete(AnimatorParamer paramer) { if (IsAniPlaying) { CheckFSMNotEmpty(); if (MotionRepeates > 0) { MotionCompletionRepeatable(ref paramer); } else { if (IsAnimationComplete(ref paramer)) { IsAniPlaying = false; } else { } } if (!IsAniPlaying) { mTotalNormalizedTime = 0f; AfterMotionCompleted(); OnAniCompleted?.Invoke(); paramer.ResetMotionState(); paramer.ResetMotionWillPlay(); } else { } } else { } }
protected virtual bool IsAnimationComplete(ref AnimatorParamer paramer) { return(paramer.IsMotionCompleted(AnimationName, 1f, LayerIndex, IsRewind)); }