public AnimationData GetAnimationData(RoleAnimationType type) { AnimationData data; m_animationsData.TryGetValue(type, out data); return(data); }
public void OnPlayOver(RoleAnimationType lastAniName) { if (null != animationStateMachine) { animationStateMachine.OnChangeState(lastAniName); } }
/// <summary> /// Play specified mesh animation with repeat setting. /// <param name="pAnimName">Name of mesh animation</param> /// <param name="pRepeat">Set playback repeat</param> /// </summary> public void Play(RoleAnimationType pAnimName, bool pRepeat) { if (null != animationStateMachine && null != CurrentAnimation) { bool bRet = animationStateMachine.IsSammeWithPrevAnim(CurrentAnimation.Type, pAnimName); if (bRet) { return; } } // IGGDebug.Assert(CurrentAnimation != null, //"MeshAnimator.Play(): Animation not found (" + pAnimName + ")", null); int start = 0; if (null != animationStateMachine) { animationStateMachine.PlayRange(pAnimName, pRepeat); } else { PlayRange(pAnimName, pRepeat, start, -1); } }
public virtual RoleAnimationType TranslateAnim(RoleAnimationType anim) { if (anim == RoleAnimationType.Wait) { if (IsPassRndSwitch()) { return(RoleAnimationType.Wait1); } else { return(RoleAnimationType.Wait2); } } else if (anim == RoleAnimationType.Attack) { //if (IsPassRndSwitch()) { // return RoleAnimationType.Attack1; //} else { // return RoleAnimationType.Attack2; //} return(RoleAnimationType.Attack1); } return(anim); }
public virtual bool IsSammeWithPrevAnim(RoleAnimationType prevAnim, RoleAnimationType anim) { //忽略进攻 if (anim == RoleAnimationType.Attack) { return(false); } return(prevAnim == anim); }
public void SetAnimationSpeedFactor(RoleAnimationType pAnimationName, float pFactor, bool pUseMachine) { if (pUseMachine && null != animationStateMachine) { animationStateMachine.SetAnimationSpeedScale(pAnimationName, pFactor); } else { AnimationData anim = AnimationGroup.GetAnimationData(pAnimationName); if (null != anim) { anim.SpeedScale = pFactor; } } }
public void PlayRange(RoleAnimationType animName, bool repeast) { switch (animName) { case RoleAnimationType.Attack: Attack(); break; case RoleAnimationType.Dead: Dead(); break; case RoleAnimationType.Hit: Hit(); break; case RoleAnimationType.Repel: Repel(); break; case RoleAnimationType.Walk: Walk(); break; case RoleAnimationType.Run: Run(); break; case RoleAnimationType.Skill1: Skill1(); break; case RoleAnimationType.Wait: Wait(); break; case RoleAnimationType.Skill2: Skill2(); break; case RoleAnimationType.Win: Win(); break; } }
public void UpdateMeshWithAttach(int pFrame, RoleAnimationType pAnimName, List <MeshFilter> pMeshFilterList) { int count = pMeshFilterList.Count; for (int i = 0; i < count; i++) { MeshFilter mf = pMeshFilterList[i]; Dictionary <RoleAnimationType, MeshAnimation> dict = m_animationsWithAttach[i]; MeshAnimation anim; bool ret = dict.TryGetValue(pAnimName, out anim); if (ret) { mf.mesh = anim.GetFrame(pFrame); } else { UnityEngine.Debug.LogError(string.Format("Not Found Animation: {0}" + pAnimName)); } } }
public void SetAnimationSpeedScale(RoleAnimationType animationName, float factor) { if (animationName == RoleAnimationType.Attack) { AnimationData anim = Animator.AnimationGroup.GetAnimationData(RoleAnimationType.Attack1); if (null != anim) { anim.SpeedScale = factor; } //anim = Animator.AnimationGroup.GetAnimationData(RoleAnimationType.Attack2); //if(null != anim) { // anim.SpeedScale = Factor; //} } else { AnimationData anim = Animator.AnimationGroup.GetAnimationData(animationName); if (null != anim) { anim.SpeedScale = factor; } } }
public virtual void OnChangeState(RoleAnimationType oldState) { switch (oldState) { case RoleAnimationType.Run: Run(); break; case RoleAnimationType.Walk: Walk(); break; case RoleAnimationType.Attack: Wait1(); break; case RoleAnimationType.Dead: break; default: Wait(); break; } }
public bool HasAnimation(RoleAnimationType type) { return(AnimationGroup.GetAnimationData(type) != null); }
/// <summary> /// Plays the animation range. Currently this is specified in frame number. May be better /// to use normalized time instead. /// </summary> /// <param name="pAnimName">Animation name</param> /// <param name="pRepeat">Play on repeat or not</param> /// <param name="pStart">Range start frame</param> /// <param name="pEnd">Range end frame</param> public void PlayRange(RoleAnimationType pAnimName, bool pRepeat, int pStart, int pEnd) { if (IsPlaying && CurrentAnimation != null) { Stop(); } CurrentAnimation = AnimationGroup.GetAnimationData(pAnimName); IsRepeatPlay = pRepeat; if (CurrentAnimation != null) { if (AnimationWillStart != null) { AnimationWillStart(CurrentAnimation); } startFrame = Mathf.Clamp(pStart, 0, CurrentAnimation.FrameCount - 1); if (pEnd == -1) { endFrame = CurrentAnimation.FrameCount - 1; } else { endFrame = Mathf.Clamp(pEnd, 0, CurrentAnimation.FrameCount - 1); } animationSpecificSpeedFactor = 1.0f / CurrentAnimation.SpeedScale; if (float.IsInfinity(animationSpecificSpeedFactor)) { animationSpecificSpeedFactor = 1; UnityEngine.Debug.LogError("animationSpecificSpeedFactor is infinity" + "MeshAnimator.PlayRange"); } frameInterval = 1.0f / ((GpuSkinAnimationGroup)AnimationGroup).Fps; nextUpdate = /*Time.time + */ frameInterval * SpeedFactor * animationSpecificSpeedFactor; CurrentFrame = startFrame; m_lastFrame = -1; m_logicTime = 0; wasUpdateSincePlay = false; if (CurrentAnimation.FrameCount == 0) { normalizedRatio = 0; } else { normalizedRatio = 1.0f / (float)CurrentAnimation.FrameCount; } SetNormalizedTime(); IsPlaying = true; if (AnimationStarted != null) { AnimationStarted(CurrentAnimation); } } }
/// <summary> /// Run the animation sequence if animation is currently running. /// Restart the animation at the end of the sequence if repeat is on, /// otherwise stop the animation. /// </summary> public void UpdateMonoBehaviour(ITime pTime) { if (CurrentAnimation == null || !IsPlaying && wasUpdateSincePlay || SpeedFactor <= 0) { return; } if (!wasUpdateSincePlay) { // considering that it was played in the previous frame. nextUpdate += pTime.FixedTime - pTime.FixedDeltaTime; wasUpdateSincePlay = true; } if (m_lastFrame != CurrentFrame) { //((MeshAnimationGroup)AnimationGroup).UpdateMeshWithAttach(CurrentFrame, CurrentAnimation.Type, m_hostMeshFilter); FrameIndex = ((GpuSkinAnimationClipData)CurrentAnimation).StartFrameIndex + CurrentFrame; m_lastFrame = CurrentFrame; } double logicFrameTime = -1; if (FrameTime > 0) { //走战斗中的帧刷新 logicFrameTime = FrameTime * SpeedFactor * animationSpecificSpeedFactor; CurrentFrame = (int)Math.Round(m_logicTime / logicFrameTime); m_logicTime += FrameTime; } else { float currentTime = pTime.FixedTime; if (currentTime > nextUpdate) { float modifiedSingleFrameTime = frameInterval * SpeedFactor * animationSpecificSpeedFactor; int frameIncrement = (int)((currentTime - lastUsedAnimationTime) / modifiedSingleFrameTime); if (frameIncrement > 0) { CurrentFrame += frameIncrement; SetNormalizedTime(); float overshoot = currentTime - nextUpdate; // calculate exactly when the next update should be nextUpdate = lastUsedAnimationTime + (frameIncrement + 1) * modifiedSingleFrameTime; lastUsedAnimationTime = currentTime - overshoot; } } } if (CurrentFrame > endFrame) { if (IsRepeatPlay) { if (AnimationLooped != null) { AnimationLooped(CurrentAnimation); } CurrentFrame = endFrame == 0 || CurrentFrame > endFrame ? 0 : CurrentFrame % endFrame; if (logicFrameTime > 0) { m_logicTime = m_logicTime % logicFrameTime; } } else { CurrentFrame = endFrame; RoleAnimationType endType = CurrentAnimation.Type; Stop(); OnPlayOver(endType); } } }
/// <summary> /// Run the animation sequence if animation is currently running. /// Restart the animation at the end of the sequence if repeat is on, /// otherwise stop the animation. /// </summary> public void UpdateMonoBehaviour(ITime pTime) { if (CurrentAnimation == null || !IsPlaying && m_wasUpdateSincePlay || SpeedFactor <= 0) { return; } if (!m_wasUpdateSincePlay) { // considering that it was played in the previous frame. m_nextUpdate += pTime.FixedTime - pTime.FixedDeltaTime; m_wasUpdateSincePlay = true; } if (m_lastFrame != CurrentFrame) { ((MeshAnimationGroup)AnimationGroup).UpdateMeshWithAttach( CurrentFrame, CurrentAnimation.Type, m_hostMeshFilter); m_lastFrame = CurrentFrame; } double logicFrameTime = -1; if (FrameTime > 0) { //走战斗中的帧刷新 logicFrameTime = FrameTime * SpeedFactor * m_animationSpecificSpeedFactor; CurrentFrame = (int)Math.Round(m_logicTime / logicFrameTime); m_logicTime += FrameTime; } else { float currentTime = pTime.FixedTime; if (currentTime > m_nextUpdate) { float modifiedSingleFrameTime = m_frameInterval * SpeedFactor * m_animationSpecificSpeedFactor; // figure out how many frames to increment, to account for skipped animation frames if framerate is too slow //int frameIncrement = Mathf.FloorToInt((currentTime - lastUsedAnimationTime) / modifiedSingleFrameTime); // Dante: code below gets rid of the division, and the FloorToInt operation from the line above. // Check http://msdn.microsoft.com/en-us/library/ms973852.aspx for more info. // // Carson: Mathf.FloorToInt is slow, but divide with (int) is faster than looping. // While loop guarantees a branch misprediction penalty. // See PerformanceTests.SubLoopSlowerThanDivCast() int frameIncrement = (int)((currentTime - m_lastUsedAnimationTime) / modifiedSingleFrameTime); if (frameIncrement > 0) { CurrentFrame += frameIncrement; SetNormalizedTime(); float overshoot = currentTime - m_nextUpdate; // calculate exactly when the next update should be m_nextUpdate = m_lastUsedAnimationTime + (frameIncrement + 1) * modifiedSingleFrameTime; m_lastUsedAnimationTime = currentTime - overshoot; } } } if (CurrentFrame > m_endFrame) { if (IsRepeatPlay) { if (AnimationLooped != null) { AnimationLooped(CurrentAnimation); } CurrentFrame = m_endFrame == 0 || CurrentFrame > m_endFrame ? 0 : CurrentFrame % m_endFrame; if (logicFrameTime > 0) { m_logicTime = m_logicTime % logicFrameTime; } } else { CurrentFrame = m_endFrame; RoleAnimationType endType = CurrentAnimation.Type; Stop(); OnPlayOver(endType); } } }