LayaBox 动画可以直接使用Unity 导出的动画,但是奇怪的问题发生了,当我将动画倒放时,居然会出现无限循环播放。不知道是不是我调错接口了,跑进Laya的接口和文档中查了N久,无功而返。意识到可能又是源码bug了。
跑进去调试一下果然发现了问题所在。
直接修改 laya.d3.js 文件中 _updatePlayer 函数即可
/** *@private */ __proto._updatePlayer = function (animatorState, playState, elapsedTime, islooping) { var clipDuration = animatorState._clip._duration * (animatorState.clipEnd - animatorState.clipStart); var lastElapsedTime = playState._elapsedTime; var elapsedPlaybackTime = lastElapsedTime + elapsedTime; playState._lastElapsedTime = lastElapsedTime; playState._elapsedTime = elapsedPlaybackTime; var normalizedTime = elapsedPlaybackTime / clipDuration; playState._normalizedTime = normalizedTime; var playTime = normalizedTime % 1.0; playState._normalizedPlayTime = playTime < 0 ? playTime + 1.0 : playTime; playState._duration = clipDuration; var scripts = animatorState._scripts; // 修改后代码 [SixGod-Modify 2020年11月4日14:42:26] if ((!islooping && Math.abs(elapsedPlaybackTime) >= clipDuration)) { playState._finish = true; playState._elapsedTime = clipDuration; if (elapsedPlaybackTime > 0) { playState._normalizedPlayTime = 1.0; } else { playState._normalizedPlayTime = 0.0; } if (scripts) { for (var i = 0, n = scripts.length; i < n; i++) scripts[i].onStateExit(); } return; } // 源码 // if ((!islooping && elapsedPlaybackTime >=clipDuration)){ // playState._finish=true; // playState._elapsedTime=clipDuration; // playState._normalizedPlayTime=1.0; // if (scripts){ // for (var i=0,n=scripts.length;i < n;i++) // scripts[i].onStateExit(); // } // return; // } if (scripts) { for (i = 0, n = scripts.length; i < n; i++) scripts[i].onStateUpdate(); } }