/// <summary> /// 序列动画播放完成 /// </summary> private void OnPlaySequenceAnimationEnd() { Debug.Log($"序列动画对象:{gameObject.name}动画播放完成!"); mAnimState = EAnimState.Ended; mOnSequenceAnimEndEvent?.Invoke(this); mOnSequenceAnimEndEvent = null; }
/// <summary> /// 开始插值动画 /// <param name="onlerpanimendcb"/>插值动画结束回调</param> /// <param name="onlerpanimbegincb"/>插值动画开始回调</param> /// </summary> public void StartAnim(Action <TBaseAnimation> onlerpanimendcb = null, Action <TBaseAnimation> onlerpanimbegincb = null) { if (IsAvalibleToPlay()) { if (mAnimState == EAnimState.Executing) { Debug.Log("插值动画正在进行中,强制打断重新开始!"); ForceStopAnim(); } mOnLerpAnimBeginEvent = onlerpanimbegincb; mOnLerpAnimEndEvent = onlerpanimendcb; mAnimState = EAnimState.Executing; if (Mathf.Approximately(StartDelayTime, float.Epsilon)) { mAnimCoroutine = StartCoroutine(LerpCoroutine()); } else { mDelayStartCoroutine = StartCoroutine(DelayStartCoroutine()); } } else { Debug.LogError($"当前脚本:{GetType().Name}或所在对象:{gameObject.name}处于未激活状态,播放失败!"); } }
/// <summary> /// 开始所有动画(强制所有动画重新播放) /// <param name="onsequenceanimendcb"/>插值序列动画结束回调</param> /// <param name="onsequenceanimbegincb"/>插值序列动画开始回调</param> /// </summary> public void StartAllAnim(Action <TSequenceAnimation> onsequenceanimendcb = null, Action <TSequenceAnimation> onsequenceanimbegincb = null) { if (IsAvalibleToPlay()) { if (mAnimState == EAnimState.Executing) { Debug.Log("序列动画正在进行中,强制打断重新开始!"); ForceStopAnims(); } mOnSequenceAnimBeginEvent = onsequenceanimbegincb; mOnSequenceAnimEndEvent = onsequenceanimendcb; if (SequenceType == ESequenceType.Paral) { mAnimState = EAnimState.Executing; mParalWailtedCompletedAnimationList.Clear(); for (int i = 0, length = AnimationInfoList.Count; i < length; i++) { if (AnimationInfoList[i].ControlAnimation != null) { if (AnimationInfoList[i].ControlAnimation.IsAvalibleToPlay()) { mParalWailtedCompletedAnimationList.Add(AnimationInfoList[i].ControlAnimation); AnimationInfoList[i].ControlAnimation?.StartAnim(OnParalAnimationPlayCompleted); } else { Debug.LogWarning($"动画:{AnimationInfoList[i].ControlAnimation.GetType().Name}不符合播放条件,无法通过序列组动画对象:{gameObject.name}并发播放!"); } } else { Debug.LogWarning($"序列动画索引:{i}的动画组件为空,无法并发播放!"); } } //没有有效动画的话,直接触发完成 if (mParalWailtedCompletedAnimationList.Count == 0) { OnPlaySequenceAnimationEnd(); } } else if (SequenceType == ESequenceType.Linear) { mAnimState = EAnimState.Executing; mLinearPlayAnimationNextIndex = 0; PlayNextLinearAnimation(); } else { Debug.LogError($"不支持的序列动画类型:{SequenceType}"); } } else { Debug.LogError($"当前脚本:{GetType().Name}或所在对象:{gameObject.name}处于未激活状态,播放所有失败!"); } }
/// <summary> /// 播放跑动画 /// </summary> /// <param name="param"></param> public void PlayRun(EAnimRunParam param = EAnimRunParam.Run) { m_State = EAnimState.Run; m_Param = (int)param; if (m_Animator == null) { return; } m_Animator.SetInteger(AnimParam.State, (int)EAnimState.Run); m_Animator.SetInteger(AnimParam.Param, m_Param); }
/// <summary> /// 播放待机动画 /// </summary> /// <param name="param"></param> public async CTask PlayIdle(EAnimIdleParam param = EAnimIdleParam.Idle) { m_State = EAnimState.Idle; m_Param = (int)param; if (m_Animator == null) { return; } m_Animator.SetInteger(AnimParam.State, (int)EAnimState.Idle); m_Animator.SetInteger(AnimParam.Param, m_Param); if (param != EAnimIdleParam.Idle) { await CTask.WaitForNextFrame(); if (m_Animator != null) { m_Animator.SetInteger(AnimParam.Param, (int)EAnimIdleParam.Idle); } } }
public override void Update(GameTime gameTime) { vx = 0; vy = 0; float velocityValue = mSpeed * 60 * (float)gameTime.ElapsedGameTime.TotalSeconds; if (Input.GetKey(Keys.W)) { vy -= velocityValue; AnimState = EAnimState.WALK_UP; } else if (Input.GetKey(Keys.S)) { vy += velocityValue; AnimState = EAnimState.WALK_DOWN; } if (Input.GetKey(Keys.A)) { vx -= velocityValue; AnimState = EAnimState.WALK_LEFT; } else if (Input.GetKey(Keys.D)) { vx += velocityValue; AnimState = EAnimState.WALK_RIGHT; } if (vx == 0 && vy == 0) { StopAnim(); CurrentAnimation.CurrentFrame = 0; } ManageCollision(); base.Update(gameTime); }
/// <summary> /// 插值动画结束 /// </summary> protected virtual void OnLerpAnimEnd() { mAnimState = EAnimState.Ended; mOnLerpAnimEndEvent?.Invoke(this); mOnLerpAnimEndEvent = null; }