//检测下时间到了就更新对应的特效帧 void CheckFrame() { if (m_curGroup == null) { //如果没有特效组,但是有动作,那么要判断是不是结束 if (m_curSt != null && !m_curSt.enabled && !m_isEnd) { m_isEnd = true; } if (m_curSt != null) { m_curTotalFrame = (int)(m_curSt.time / Util.One_Frame); } return; } if (m_isEnd) { return; } //计算当前的真实的帧 int frame; int loop; bool isEnd; CalcSt(m_curSt, out frame, out loop, out isEnd); //执行,确保执行且执行一次 int maxFrame = (int)(m_curSt.length / Util.One_Frame); if (loop != m_curLoop || frame != m_curFrame) { int left; int right; for (int i = m_curLoop; i <= loop; ++i) { left = i == m_curLoop ? m_curFrame + 1 : 0; right = i == loop ? frame : maxFrame; for (int j = left; j <= right; ++j) { m_curGroup.UpdateFrame(j, i, m_isEnd, m_root);//每一帧都会执行到 ++m_curTotalFrame; } } } m_curLoop = loop; m_curFrame = frame; //如果结束了 if (isEnd) { m_curGroup.End(); m_isEnd = true; } }
public void Play(string ani, WrapMode wrapMode, AniRateCfg rateCfg, float fade = 0.2f) { Cache(); //先做些音效的处理 #if !ART_DEBUG StopSound(); m_sounds.Clear(); AniSoundCfg.Get(m_modName, ani, ref m_sounds); #endif ResetPause();//上一个动作如果卡帧中那么清空 m_curRateCfg = rateCfg; m_curRateIdx = -1; m_curRateEndFrame = -1; //如果当前动作没有结束要先结束 if (m_curGroup != null && !m_isEnd) { m_curGroup.End(); m_isEnd = true; } //播放 m_curSt = m_sts.Get(ani); if (m_curSt != null) { if (m_curRateCfg.clips.Count > 0) { m_curRateIdx = 0; m_curRateEndFrame = m_curRateCfg.clips[0].frame; } m_curSt.speed = GetRateSpeed(); m_curSt.normalizedTime = 0; m_curSt.wrapMode = wrapMode; if (fade == 0 || (m_simpleRole != null && !m_simpleRole.m_needFade)) { m_ani.Play(ani); } else { m_ani.CrossFade(ani, fade); } } else { m_ani.Stop(); Debuger.LogError("{0}找不到动作{1}", this.transform.parent.name, ani); } //当前动作的处理 m_curGroup = m_curSt == null ? null : GetGroup(ani); m_curTotalFrame = 0; if (m_curGroup != null) { CalcSt(m_curSt, out m_curFrame, out m_curLoop, out m_isEnd); m_curGroup.Begin(); m_curGroup.UpdateFrame(m_curFrame, m_curLoop, false, m_root); if (m_isEnd) { m_curGroup.End(); } } //检查播放声音 CheckSound(); }