zoukankan      html  css  js  c++  java
  • LayaBox 3D 动画播放/倒放Bug问题解决

    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();
        }
    }
  • 相关阅读:
    0593. Valid Square (M)
    0832. Flipping an Image (E)
    1026. Maximum Difference Between Node and Ancestor (M)
    0563. Binary Tree Tilt (E)
    0445. Add Two Numbers II (M)
    1283. Find the Smallest Divisor Given a Threshold (M)
    C Primer Plus note9
    C Primer Plus note8
    C Primer Plus note7
    C Primer Plus note6
  • 原文地址:https://www.cnblogs.com/huojiaoqingchun0123/p/13925844.html
Copyright © 2011-2022 走看看