@eva/plugin-transition 2.0.1-beta.3 → 2.0.1-beta.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/EVA.plugin.transition.js +7 -2
- package/dist/EVA.plugin.transition.min.js +1 -1
- package/dist/plugin-transition.cjs.js +100 -2
- package/dist/plugin-transition.cjs.prod.js +1 -1
- package/dist/plugin-transition.d.ts +97 -0
- package/dist/plugin-transition.esm.js +100 -2
- package/package.json +2 -2
|
@@ -697,10 +697,10 @@ var _EVA_IIFE_transition = function (exports, eva_js) {
|
|
|
697
697
|
}
|
|
698
698
|
this.callbacks.get(eventName).push(callback);
|
|
699
699
|
}
|
|
700
|
-
emit(eventName) {
|
|
700
|
+
emit(eventName, ...args) {
|
|
701
701
|
const callbacks = this.callbacks.get(eventName);
|
|
702
702
|
if (!callbacks || !callbacks.length) return;
|
|
703
|
-
callbacks.forEach(fn => fn());
|
|
703
|
+
callbacks.forEach(fn => fn(...args));
|
|
704
704
|
}
|
|
705
705
|
checkFinish() {
|
|
706
706
|
if (++this.finishCount == this.tweens.length) {
|
|
@@ -760,6 +760,7 @@ var _EVA_IIFE_transition = function (exports, eva_js) {
|
|
|
760
760
|
name: timeline.name,
|
|
761
761
|
value: props.value
|
|
762
762
|
});
|
|
763
|
+
this.emit('update', props.value);
|
|
763
764
|
});
|
|
764
765
|
if (j === 0) {
|
|
765
766
|
this.tweens[i] = tween;
|
|
@@ -886,6 +887,10 @@ var _EVA_IIFE_transition = function (exports, eva_js) {
|
|
|
886
887
|
newAnimation(name) {
|
|
887
888
|
const animation = new Animation(this.group[name], this.tweenGroup);
|
|
888
889
|
animation.on('finish', () => this.emit('finish', name));
|
|
890
|
+
animation.on('update', value => this.emit('update', {
|
|
891
|
+
name,
|
|
892
|
+
value
|
|
893
|
+
}));
|
|
889
894
|
this.animations[name] = animation;
|
|
890
895
|
}
|
|
891
896
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
globalThis.EVA=globalThis.EVA||{},globalThis.EVA.plugin=globalThis.EVA.plugin||{};var _EVA_IIFE_transition=function(t,e){"use strict";var i,n={Linear:{None:function(t){return t}},Quadratic:{In:function(t){return t*t},Out:function(t){return t*(2-t)},InOut:function(t){return(t*=2)<1?.5*t*t:-.5*(--t*(t-2)-1)}},Cubic:{In:function(t){return t*t*t},Out:function(t){return--t*t*t+1},InOut:function(t){return(t*=2)<1?.5*t*t*t:.5*((t-=2)*t*t+2)}},Quartic:{In:function(t){return t*t*t*t},Out:function(t){return 1- --t*t*t*t},InOut:function(t){return(t*=2)<1?.5*t*t*t*t:-.5*((t-=2)*t*t*t-2)}},Quintic:{In:function(t){return t*t*t*t*t},Out:function(t){return--t*t*t*t*t+1},InOut:function(t){return(t*=2)<1?.5*t*t*t*t*t:.5*((t-=2)*t*t*t*t+2)}},Sinusoidal:{In:function(t){return 1-Math.cos(t*Math.PI/2)},Out:function(t){return Math.sin(t*Math.PI/2)},InOut:function(t){return.5*(1-Math.cos(Math.PI*t))}},Exponential:{In:function(t){return 0===t?0:Math.pow(1024,t-1)},Out:function(t){return 1===t?1:1-Math.pow(2,-10*t)},InOut:function(t){return 0===t?0:1===t?1:(t*=2)<1?.5*Math.pow(1024,t-1):.5*(2-Math.pow(2,-10*(t-1)))}},Circular:{In:function(t){return 1-Math.sqrt(1-t*t)},Out:function(t){return Math.sqrt(1- --t*t)},InOut:function(t){return(t*=2)<1?-.5*(Math.sqrt(1-t*t)-1):.5*(Math.sqrt(1-(t-=2)*t)+1)}},Elastic:{In:function(t){return 0===t?0:1===t?1:-Math.pow(2,10*(t-1))*Math.sin(5*(t-1.1)*Math.PI)},Out:function(t){return 0===t?0:1===t?1:Math.pow(2,-10*t)*Math.sin(5*(t-.1)*Math.PI)+1},InOut:function(t){return 0===t?0:1===t?1:(t*=2)<1?-.5*Math.pow(2,10*(t-1))*Math.sin(5*(t-1.1)*Math.PI):.5*Math.pow(2,-10*(t-1))*Math.sin(5*(t-1.1)*Math.PI)+1}},Back:{In:function(t){var e=1.70158;return t*t*((e+1)*t-e)},Out:function(t){var e=1.70158;return--t*t*((e+1)*t+e)+1},InOut:function(t){var e=2.5949095;return(t*=2)<1?t*t*((e+1)*t-e)*.5:.5*((t-=2)*t*((e+1)*t+e)+2)}},Bounce:{In:function(t){return 1-n.Bounce.Out(1-t)},Out:function(t){return t<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375},InOut:function(t){return t<.5?.5*n.Bounce.In(2*t):.5*n.Bounce.Out(2*t-1)+.5}}},s="undefined"==typeof self&&"undefined"!=typeof process&&process.hrtime?function(){var t=process.hrtime();return 1e3*t[0]+t[1]/1e6}:"undefined"!=typeof self&&void 0!==self.performance&&void 0!==self.performance.now?self.performance.now.bind(self.performance):void 0!==Date.now?Date.now:function(){return(new Date).getTime()},r=function(){function t(){this._tweens={},this._tweensAddedDuringUpdate={}}return t.prototype.getAll=function(){var t=this;return Object.keys(this._tweens).map((function(e){return t._tweens[e]}))},t.prototype.removeAll=function(){this._tweens={}},t.prototype.add=function(t){this._tweens[t.getId()]=t,this._tweensAddedDuringUpdate[t.getId()]=t},t.prototype.remove=function(t){delete this._tweens[t.getId()],delete this._tweensAddedDuringUpdate[t.getId()]},t.prototype.update=function(t,e){void 0===t&&(t=s()),void 0===e&&(e=!1);var i=Object.keys(this._tweens);if(0===i.length)return!1;for(;i.length>0;){this._tweensAddedDuringUpdate={};for(var n=0;n<i.length;n++){var r=this._tweens[i[n]],o=!e;r&&!1===r.update(t,o)&&!e&&delete this._tweens[i[n]]}i=Object.keys(this._tweensAddedDuringUpdate)}return!0},t}(),o={Linear:function(t,e){var i=t.length-1,n=i*e,s=Math.floor(n),r=o.Utils.Linear;return e<0?r(t[0],t[1],n):e>1?r(t[i],t[i-1],i-n):r(t[s],t[s+1>i?i:s+1],n-s)},Bezier:function(t,e){for(var i=0,n=t.length-1,s=Math.pow,r=o.Utils.Bernstein,a=0;a<=n;a++)i+=s(1-e,n-a)*s(e,a)*t[a]*r(n,a);return i},CatmullRom:function(t,e){var i=t.length-1,n=i*e,s=Math.floor(n),r=o.Utils.CatmullRom;return t[0]===t[i]?(e<0&&(s=Math.floor(n=i*(1+e))),r(t[(s-1+i)%i],t[s],t[(s+1)%i],t[(s+2)%i],n-s)):e<0?t[0]-(r(t[0],t[0],t[1],t[1],-n)-t[0]):e>1?t[i]-(r(t[i],t[i],t[i-1],t[i-1],n-i)-t[i]):r(t[s?s-1:0],t[s],t[i<s+1?i:s+1],t[i<s+2?i:s+2],n-s)},Utils:{Linear:function(t,e,i){return(e-t)*i+t},Bernstein:function(t,e){var i=o.Utils.Factorial;return i(t)/i(e)/i(t-e)},Factorial:(i=[1],function(t){var e=1;if(i[t])return i[t];for(var n=t;n>1;n--)e*=n;return i[t]=e,e}),CatmullRom:function(t,e,i,n,s){var r=.5*(i-t),o=.5*(n-e),a=s*s;return(2*e-2*i+r+o)*(s*a)+(-3*e+3*i-2*r-o)*a+r*s+e}}},a=function(){function t(){}return t.nextId=function(){return t._nextId++},t._nextId=0,t}(),h=new r,u=function(){function t(t,e){void 0===e&&(e=h),this._object=t,this._group=e,this._isPaused=!1,this._pauseStart=0,this._valuesStart={},this._valuesEnd={},this._valuesStartRepeat={},this._duration=1e3,this._initialRepeat=0,this._repeat=0,this._yoyo=!1,this._isPlaying=!1,this._reversed=!1,this._delayTime=0,this._startTime=0,this._easingFunction=n.Linear.None,this._interpolationFunction=o.Linear,this._chainedTweens=[],this._onStartCallbackFired=!1,this._id=a.nextId(),this._isChainStopped=!1,this._goToEnd=!1}return t.prototype.getId=function(){return this._id},t.prototype.isPlaying=function(){return this._isPlaying},t.prototype.isPaused=function(){return this._isPaused},t.prototype.to=function(t,e){return this._valuesEnd=Object.create(t),void 0!==e&&(this._duration=e),this},t.prototype.duration=function(t){return this._duration=t,this},t.prototype.start=function(t){if(this._isPlaying)return this;if(this._group&&this._group.add(this),this._repeat=this._initialRepeat,this._reversed)for(var e in this._reversed=!1,this._valuesStartRepeat)this._swapEndStartRepeatValues(e),this._valuesStart[e]=this._valuesStartRepeat[e];return this._isPlaying=!0,this._isPaused=!1,this._onStartCallbackFired=!1,this._isChainStopped=!1,this._startTime=void 0!==t?"string"==typeof t?s()+parseFloat(t):t:s(),this._startTime+=this._delayTime,this._setupProperties(this._object,this._valuesStart,this._valuesEnd,this._valuesStartRepeat),this},t.prototype._setupProperties=function(t,e,i,n){for(var s in i){var r=t[s],o=Array.isArray(r),a=o?"array":typeof r,h=!o&&Array.isArray(i[s]);if("undefined"!==a&&"function"!==a){if(h){var u=i[s];if(0===u.length)continue;u=u.map(this._handleRelativeValue.bind(this,r)),i[s]=[r].concat(u)}if("object"!==a&&!o||!r||h)void 0===e[s]&&(e[s]=r),o||(e[s]*=1),n[s]=h?i[s].slice().reverse():e[s]||0;else{for(var c in e[s]=o?[]:{},r)e[s][c]=r[c];n[s]=o?[]:{},this._setupProperties(r,e[s],i[s],n[s])}}}},t.prototype.stop=function(){return this._isChainStopped||(this._isChainStopped=!0,this.stopChainedTweens()),this._isPlaying?(this._group&&this._group.remove(this),this._isPlaying=!1,this._isPaused=!1,this._onStopCallback&&this._onStopCallback(this._object),this):this},t.prototype.end=function(){return this._goToEnd=!0,this.update(1/0),this},t.prototype.pause=function(t){return void 0===t&&(t=s()),this._isPaused||!this._isPlaying||(this._isPaused=!0,this._pauseStart=t,this._group&&this._group.remove(this)),this},t.prototype.resume=function(t){return void 0===t&&(t=s()),this._isPaused&&this._isPlaying?(this._isPaused=!1,this._startTime+=t-this._pauseStart,this._pauseStart=0,this._group&&this._group.add(this),this):this},t.prototype.stopChainedTweens=function(){for(var t=0,e=this._chainedTweens.length;t<e;t++)this._chainedTweens[t].stop();return this},t.prototype.group=function(t){return this._group=t,this},t.prototype.delay=function(t){return this._delayTime=t,this},t.prototype.repeat=function(t){return this._initialRepeat=t,this._repeat=t,this},t.prototype.repeatDelay=function(t){return this._repeatDelayTime=t,this},t.prototype.yoyo=function(t){return this._yoyo=t,this},t.prototype.easing=function(t){return this._easingFunction=t,this},t.prototype.interpolation=function(t){return this._interpolationFunction=t,this},t.prototype.chain=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return this._chainedTweens=t,this},t.prototype.onStart=function(t){return this._onStartCallback=t,this},t.prototype.onUpdate=function(t){return this._onUpdateCallback=t,this},t.prototype.onRepeat=function(t){return this._onRepeatCallback=t,this},t.prototype.onComplete=function(t){return this._onCompleteCallback=t,this},t.prototype.onStop=function(t){return this._onStopCallback=t,this},t.prototype.update=function(t,e){if(void 0===t&&(t=s()),void 0===e&&(e=!0),this._isPaused)return!0;var i,n,r=this._startTime+this._duration;if(!this._goToEnd&&!this._isPlaying){if(t>r)return!1;e&&this.start(t)}if(this._goToEnd=!1,t<this._startTime)return!0;!1===this._onStartCallbackFired&&(this._onStartCallback&&this._onStartCallback(this._object),this._onStartCallbackFired=!0),n=(t-this._startTime)/this._duration,n=0===this._duration||n>1?1:n;var o=this._easingFunction(n);if(this._updateProperties(this._object,this._valuesStart,this._valuesEnd,o),this._onUpdateCallback&&this._onUpdateCallback(this._object,n),1===n){if(this._repeat>0){for(i in isFinite(this._repeat)&&this._repeat--,this._valuesStartRepeat)this._yoyo||"string"!=typeof this._valuesEnd[i]||(this._valuesStartRepeat[i]=this._valuesStartRepeat[i]+parseFloat(this._valuesEnd[i])),this._yoyo&&this._swapEndStartRepeatValues(i),this._valuesStart[i]=this._valuesStartRepeat[i];return this._yoyo&&(this._reversed=!this._reversed),void 0!==this._repeatDelayTime?this._startTime=t+this._repeatDelayTime:this._startTime=t+this._delayTime,this._onRepeatCallback&&this._onRepeatCallback(this._object),!0}this._onCompleteCallback&&this._onCompleteCallback(this._object);for(var a=0,h=this._chainedTweens.length;a<h;a++)this._chainedTweens[a].start(this._startTime+this._duration);return this._isPlaying=!1,!1}return!0},t.prototype._updateProperties=function(t,e,i,n){for(var s in i)if(void 0!==e[s]){var r=e[s]||0,o=i[s],a=Array.isArray(t[s]),h=Array.isArray(o);!a&&h?t[s]=this._interpolationFunction(o,n):"object"==typeof o&&o?this._updateProperties(t[s],r,o,n):"number"==typeof(o=this._handleRelativeValue(r,o))&&(t[s]=r+(o-r)*n)}},t.prototype._handleRelativeValue=function(t,e){return"string"!=typeof e?e:"+"===e.charAt(0)||"-"===e.charAt(0)?t+parseFloat(e):parseFloat(e)},t.prototype._swapEndStartRepeatValues=function(t){var e=this._valuesStartRepeat[t],i=this._valuesEnd[t];this._valuesStartRepeat[t]="string"==typeof i?this._valuesStartRepeat[t]+parseFloat(i):this._valuesEnd[t],this._valuesEnd[t]=e},t}();a.nextId;var c=h;c.getAll.bind(c),c.removeAll.bind(c),c.add.bind(c),c.remove.bind(c),c.update.bind(c);const l={linear:n.Linear.None,"ease-in":n.Quadratic.In,"ease-out":n.Quadratic.Out,"ease-in-out":n.Quadratic.InOut,"bounce-in":n.Bounce.In,"bounce-out":n.Bounce.Out,"bounce-in-out":n.Bounce.InOut,none:t=>~~t};class p{constructor(t,e){this.tweens=[],this.timelines=[],this.finishCount=0,this.callbacks=new Map,this.objectCache={},this.currIteration=0,this.timelines=t,this.tweenGroup=e}on(t,e){this.callbacks[t]||this.callbacks.set(t,[]),this.callbacks.get(t).push(e)}emit(t){const e=this.callbacks.get(t);e&&e.length&&e.forEach((t=>t()))}checkFinish(){if(++this.finishCount==this.tweens.length)if(++this.currIteration==this.iteration)this.emit("finish");else{if(this.stoped)return;this.start()}}getObjectCache(t,e){const i=`${t.gameObject.id}${t.name}`;if(this.objectCache[i]||(this.objectCache[i]={}),this.objectCache[i][e])return this.objectCache[i][e];const n=e.split("."),s=n.length-1;let r=t;for(let t=0;t<s;t++)r=r[n[t]];return this.objectCache[i][e]={property:r,key:n[s]},this.objectCache[i][e]}doAnim({component:t,name:e,value:i}){const{property:n,key:s}=this.getObjectCache(t,e);n[s]=i}init(){let t;this.checkFinishFunc=this.checkFinish.bind(this),this.timelines.forEach(((e,i)=>{for(let n=0;n<e.values.length-1;n++){const s=e.values[n],r=e.values[n+1],o=new u({value:s.value},this.tweenGroup).to({value:r.value}).duration(r.time-s.time).easing(l[s.tween]).onUpdate((t=>{this.doAnim({component:e.component,name:e.name,value:t.value})}));0===n?this.tweens[i]=o:t.chain(o),t=o}t&&t.onComplete((()=>this.checkFinishFunc()))}))}play(t=1,e){this.currentTime=e,this.stoped=!1,this.start(),this.currIteration=0,this.iteration=t}start(){this.finishCount=0,this.tweens.length=0,this.init(),this.tweens.forEach((t=>t.start(this.currentTime)))}pause(){this.tweens.forEach((t=>t.pause(this.currentTime)))}resume(){this.tweens.forEach((t=>t.resume(this.currentTime)))}stop(){this.stoped=!0,this.tweens.forEach((t=>t.stop()))}destroy(){this.stop(),this.tweens=null,this.timelines=null,this.objectCache=null,this.callbacks.clear(),this.callbacks=null}}class _ extends e.Component{constructor(){super(...arguments),this.animations={},this.group={},this.currentTime=0,this.needPlay=[]}init({group:t}={group:{}}){this.group=t,this.tweenGroup=new r}awake(){for(const t in this.group)this.newAnimation(t)}play(t,e){t||(t=Object.keys(this.group)[0]),t&&!this.animations[t]&&this.group[t]&&this.newAnimation(t),t&&this.animations[t]&&this.needPlay.push({name:t,iteration:e})}stop(t){var e,i;if(t)null===(i=this.animations[t])||void 0===i||i.stop();else for(const t in this.animations)null===(e=this.animations[t])||void 0===e||e.stop()}onPause(){var t;for(const e in this.animations)null===(t=this.animations[e])||void 0===t||t.pause()}onResume(){var t;for(const e in this.animations)null===(t=this.animations[e])||void 0===t||t.resume()}onDestroy(){var t;for(const e in this.animations)null===(t=this.animations[e])||void 0===t||t.destroy();this.tweenGroup.removeAll(),this.tweenGroup=null,this.group=null,this.animations=null,this.removeAllListeners()}update(t){var e;this.currentTime=t.time;for(const e in this.animations)this.animations[e].currentTime=t.time;this.tweenGroup.update(t.time);for(const t of this.needPlay)null===(e=this.animations[t.name])||void 0===e||e.play(t.iteration,this.currentTime);this.needPlay.length=0}newAnimation(t){const e=new p(this.group[t],this.tweenGroup);e.on("finish",(()=>this.emit("finish",t))),this.animations[t]=e}}_.componentName="Transition";class d extends e.System{constructor(){super(...arguments),this.name="transition"}}return d.systemName="transition",t.Transition=_,t.TransitionSystem=d,Object.defineProperty(t,"__esModule",{value:!0}),t}({},EVA);globalThis.EVA.plugin.transition=globalThis.EVA.plugin.transition||_EVA_IIFE_transition;
|
|
1
|
+
globalThis.EVA=globalThis.EVA||{},globalThis.EVA.plugin=globalThis.EVA.plugin||{};var _EVA_IIFE_transition=function(t,e){"use strict";var i,n={Linear:{None:function(t){return t}},Quadratic:{In:function(t){return t*t},Out:function(t){return t*(2-t)},InOut:function(t){return(t*=2)<1?.5*t*t:-.5*(--t*(t-2)-1)}},Cubic:{In:function(t){return t*t*t},Out:function(t){return--t*t*t+1},InOut:function(t){return(t*=2)<1?.5*t*t*t:.5*((t-=2)*t*t+2)}},Quartic:{In:function(t){return t*t*t*t},Out:function(t){return 1- --t*t*t*t},InOut:function(t){return(t*=2)<1?.5*t*t*t*t:-.5*((t-=2)*t*t*t-2)}},Quintic:{In:function(t){return t*t*t*t*t},Out:function(t){return--t*t*t*t*t+1},InOut:function(t){return(t*=2)<1?.5*t*t*t*t*t:.5*((t-=2)*t*t*t*t+2)}},Sinusoidal:{In:function(t){return 1-Math.cos(t*Math.PI/2)},Out:function(t){return Math.sin(t*Math.PI/2)},InOut:function(t){return.5*(1-Math.cos(Math.PI*t))}},Exponential:{In:function(t){return 0===t?0:Math.pow(1024,t-1)},Out:function(t){return 1===t?1:1-Math.pow(2,-10*t)},InOut:function(t){return 0===t?0:1===t?1:(t*=2)<1?.5*Math.pow(1024,t-1):.5*(2-Math.pow(2,-10*(t-1)))}},Circular:{In:function(t){return 1-Math.sqrt(1-t*t)},Out:function(t){return Math.sqrt(1- --t*t)},InOut:function(t){return(t*=2)<1?-.5*(Math.sqrt(1-t*t)-1):.5*(Math.sqrt(1-(t-=2)*t)+1)}},Elastic:{In:function(t){return 0===t?0:1===t?1:-Math.pow(2,10*(t-1))*Math.sin(5*(t-1.1)*Math.PI)},Out:function(t){return 0===t?0:1===t?1:Math.pow(2,-10*t)*Math.sin(5*(t-.1)*Math.PI)+1},InOut:function(t){return 0===t?0:1===t?1:(t*=2)<1?-.5*Math.pow(2,10*(t-1))*Math.sin(5*(t-1.1)*Math.PI):.5*Math.pow(2,-10*(t-1))*Math.sin(5*(t-1.1)*Math.PI)+1}},Back:{In:function(t){var e=1.70158;return t*t*((e+1)*t-e)},Out:function(t){var e=1.70158;return--t*t*((e+1)*t+e)+1},InOut:function(t){var e=2.5949095;return(t*=2)<1?t*t*((e+1)*t-e)*.5:.5*((t-=2)*t*((e+1)*t+e)+2)}},Bounce:{In:function(t){return 1-n.Bounce.Out(1-t)},Out:function(t){return t<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375},InOut:function(t){return t<.5?.5*n.Bounce.In(2*t):.5*n.Bounce.Out(2*t-1)+.5}}},s="undefined"==typeof self&&"undefined"!=typeof process&&process.hrtime?function(){var t=process.hrtime();return 1e3*t[0]+t[1]/1e6}:"undefined"!=typeof self&&void 0!==self.performance&&void 0!==self.performance.now?self.performance.now.bind(self.performance):void 0!==Date.now?Date.now:function(){return(new Date).getTime()},r=function(){function t(){this._tweens={},this._tweensAddedDuringUpdate={}}return t.prototype.getAll=function(){var t=this;return Object.keys(this._tweens).map((function(e){return t._tweens[e]}))},t.prototype.removeAll=function(){this._tweens={}},t.prototype.add=function(t){this._tweens[t.getId()]=t,this._tweensAddedDuringUpdate[t.getId()]=t},t.prototype.remove=function(t){delete this._tweens[t.getId()],delete this._tweensAddedDuringUpdate[t.getId()]},t.prototype.update=function(t,e){void 0===t&&(t=s()),void 0===e&&(e=!1);var i=Object.keys(this._tweens);if(0===i.length)return!1;for(;i.length>0;){this._tweensAddedDuringUpdate={};for(var n=0;n<i.length;n++){var r=this._tweens[i[n]],a=!e;r&&!1===r.update(t,a)&&!e&&delete this._tweens[i[n]]}i=Object.keys(this._tweensAddedDuringUpdate)}return!0},t}(),a={Linear:function(t,e){var i=t.length-1,n=i*e,s=Math.floor(n),r=a.Utils.Linear;return e<0?r(t[0],t[1],n):e>1?r(t[i],t[i-1],i-n):r(t[s],t[s+1>i?i:s+1],n-s)},Bezier:function(t,e){for(var i=0,n=t.length-1,s=Math.pow,r=a.Utils.Bernstein,o=0;o<=n;o++)i+=s(1-e,n-o)*s(e,o)*t[o]*r(n,o);return i},CatmullRom:function(t,e){var i=t.length-1,n=i*e,s=Math.floor(n),r=a.Utils.CatmullRom;return t[0]===t[i]?(e<0&&(s=Math.floor(n=i*(1+e))),r(t[(s-1+i)%i],t[s],t[(s+1)%i],t[(s+2)%i],n-s)):e<0?t[0]-(r(t[0],t[0],t[1],t[1],-n)-t[0]):e>1?t[i]-(r(t[i],t[i],t[i-1],t[i-1],n-i)-t[i]):r(t[s?s-1:0],t[s],t[i<s+1?i:s+1],t[i<s+2?i:s+2],n-s)},Utils:{Linear:function(t,e,i){return(e-t)*i+t},Bernstein:function(t,e){var i=a.Utils.Factorial;return i(t)/i(e)/i(t-e)},Factorial:(i=[1],function(t){var e=1;if(i[t])return i[t];for(var n=t;n>1;n--)e*=n;return i[t]=e,e}),CatmullRom:function(t,e,i,n,s){var r=.5*(i-t),a=.5*(n-e),o=s*s;return(2*e-2*i+r+a)*(s*o)+(-3*e+3*i-2*r-a)*o+r*s+e}}},o=function(){function t(){}return t.nextId=function(){return t._nextId++},t._nextId=0,t}(),h=new r,u=function(){function t(t,e){void 0===e&&(e=h),this._object=t,this._group=e,this._isPaused=!1,this._pauseStart=0,this._valuesStart={},this._valuesEnd={},this._valuesStartRepeat={},this._duration=1e3,this._initialRepeat=0,this._repeat=0,this._yoyo=!1,this._isPlaying=!1,this._reversed=!1,this._delayTime=0,this._startTime=0,this._easingFunction=n.Linear.None,this._interpolationFunction=a.Linear,this._chainedTweens=[],this._onStartCallbackFired=!1,this._id=o.nextId(),this._isChainStopped=!1,this._goToEnd=!1}return t.prototype.getId=function(){return this._id},t.prototype.isPlaying=function(){return this._isPlaying},t.prototype.isPaused=function(){return this._isPaused},t.prototype.to=function(t,e){return this._valuesEnd=Object.create(t),void 0!==e&&(this._duration=e),this},t.prototype.duration=function(t){return this._duration=t,this},t.prototype.start=function(t){if(this._isPlaying)return this;if(this._group&&this._group.add(this),this._repeat=this._initialRepeat,this._reversed)for(var e in this._reversed=!1,this._valuesStartRepeat)this._swapEndStartRepeatValues(e),this._valuesStart[e]=this._valuesStartRepeat[e];return this._isPlaying=!0,this._isPaused=!1,this._onStartCallbackFired=!1,this._isChainStopped=!1,this._startTime=void 0!==t?"string"==typeof t?s()+parseFloat(t):t:s(),this._startTime+=this._delayTime,this._setupProperties(this._object,this._valuesStart,this._valuesEnd,this._valuesStartRepeat),this},t.prototype._setupProperties=function(t,e,i,n){for(var s in i){var r=t[s],a=Array.isArray(r),o=a?"array":typeof r,h=!a&&Array.isArray(i[s]);if("undefined"!==o&&"function"!==o){if(h){var u=i[s];if(0===u.length)continue;u=u.map(this._handleRelativeValue.bind(this,r)),i[s]=[r].concat(u)}if("object"!==o&&!a||!r||h)void 0===e[s]&&(e[s]=r),a||(e[s]*=1),n[s]=h?i[s].slice().reverse():e[s]||0;else{for(var l in e[s]=a?[]:{},r)e[s][l]=r[l];n[s]=a?[]:{},this._setupProperties(r,e[s],i[s],n[s])}}}},t.prototype.stop=function(){return this._isChainStopped||(this._isChainStopped=!0,this.stopChainedTweens()),this._isPlaying?(this._group&&this._group.remove(this),this._isPlaying=!1,this._isPaused=!1,this._onStopCallback&&this._onStopCallback(this._object),this):this},t.prototype.end=function(){return this._goToEnd=!0,this.update(1/0),this},t.prototype.pause=function(t){return void 0===t&&(t=s()),this._isPaused||!this._isPlaying||(this._isPaused=!0,this._pauseStart=t,this._group&&this._group.remove(this)),this},t.prototype.resume=function(t){return void 0===t&&(t=s()),this._isPaused&&this._isPlaying?(this._isPaused=!1,this._startTime+=t-this._pauseStart,this._pauseStart=0,this._group&&this._group.add(this),this):this},t.prototype.stopChainedTweens=function(){for(var t=0,e=this._chainedTweens.length;t<e;t++)this._chainedTweens[t].stop();return this},t.prototype.group=function(t){return this._group=t,this},t.prototype.delay=function(t){return this._delayTime=t,this},t.prototype.repeat=function(t){return this._initialRepeat=t,this._repeat=t,this},t.prototype.repeatDelay=function(t){return this._repeatDelayTime=t,this},t.prototype.yoyo=function(t){return this._yoyo=t,this},t.prototype.easing=function(t){return this._easingFunction=t,this},t.prototype.interpolation=function(t){return this._interpolationFunction=t,this},t.prototype.chain=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return this._chainedTweens=t,this},t.prototype.onStart=function(t){return this._onStartCallback=t,this},t.prototype.onUpdate=function(t){return this._onUpdateCallback=t,this},t.prototype.onRepeat=function(t){return this._onRepeatCallback=t,this},t.prototype.onComplete=function(t){return this._onCompleteCallback=t,this},t.prototype.onStop=function(t){return this._onStopCallback=t,this},t.prototype.update=function(t,e){if(void 0===t&&(t=s()),void 0===e&&(e=!0),this._isPaused)return!0;var i,n,r=this._startTime+this._duration;if(!this._goToEnd&&!this._isPlaying){if(t>r)return!1;e&&this.start(t)}if(this._goToEnd=!1,t<this._startTime)return!0;!1===this._onStartCallbackFired&&(this._onStartCallback&&this._onStartCallback(this._object),this._onStartCallbackFired=!0),n=(t-this._startTime)/this._duration,n=0===this._duration||n>1?1:n;var a=this._easingFunction(n);if(this._updateProperties(this._object,this._valuesStart,this._valuesEnd,a),this._onUpdateCallback&&this._onUpdateCallback(this._object,n),1===n){if(this._repeat>0){for(i in isFinite(this._repeat)&&this._repeat--,this._valuesStartRepeat)this._yoyo||"string"!=typeof this._valuesEnd[i]||(this._valuesStartRepeat[i]=this._valuesStartRepeat[i]+parseFloat(this._valuesEnd[i])),this._yoyo&&this._swapEndStartRepeatValues(i),this._valuesStart[i]=this._valuesStartRepeat[i];return this._yoyo&&(this._reversed=!this._reversed),void 0!==this._repeatDelayTime?this._startTime=t+this._repeatDelayTime:this._startTime=t+this._delayTime,this._onRepeatCallback&&this._onRepeatCallback(this._object),!0}this._onCompleteCallback&&this._onCompleteCallback(this._object);for(var o=0,h=this._chainedTweens.length;o<h;o++)this._chainedTweens[o].start(this._startTime+this._duration);return this._isPlaying=!1,!1}return!0},t.prototype._updateProperties=function(t,e,i,n){for(var s in i)if(void 0!==e[s]){var r=e[s]||0,a=i[s],o=Array.isArray(t[s]),h=Array.isArray(a);!o&&h?t[s]=this._interpolationFunction(a,n):"object"==typeof a&&a?this._updateProperties(t[s],r,a,n):"number"==typeof(a=this._handleRelativeValue(r,a))&&(t[s]=r+(a-r)*n)}},t.prototype._handleRelativeValue=function(t,e){return"string"!=typeof e?e:"+"===e.charAt(0)||"-"===e.charAt(0)?t+parseFloat(e):parseFloat(e)},t.prototype._swapEndStartRepeatValues=function(t){var e=this._valuesStartRepeat[t],i=this._valuesEnd[t];this._valuesStartRepeat[t]="string"==typeof i?this._valuesStartRepeat[t]+parseFloat(i):this._valuesEnd[t],this._valuesEnd[t]=e},t}();o.nextId;var l=h;l.getAll.bind(l),l.removeAll.bind(l),l.add.bind(l),l.remove.bind(l),l.update.bind(l);const c={linear:n.Linear.None,"ease-in":n.Quadratic.In,"ease-out":n.Quadratic.Out,"ease-in-out":n.Quadratic.InOut,"bounce-in":n.Bounce.In,"bounce-out":n.Bounce.Out,"bounce-in-out":n.Bounce.InOut,none:t=>~~t};class p{constructor(t,e){this.tweens=[],this.timelines=[],this.finishCount=0,this.callbacks=new Map,this.objectCache={},this.currIteration=0,this.timelines=t,this.tweenGroup=e}on(t,e){this.callbacks[t]||this.callbacks.set(t,[]),this.callbacks.get(t).push(e)}emit(t,...e){const i=this.callbacks.get(t);i&&i.length&&i.forEach((t=>t(...e)))}checkFinish(){if(++this.finishCount==this.tweens.length)if(++this.currIteration==this.iteration)this.emit("finish");else{if(this.stoped)return;this.start()}}getObjectCache(t,e){const i=`${t.gameObject.id}${t.name}`;if(this.objectCache[i]||(this.objectCache[i]={}),this.objectCache[i][e])return this.objectCache[i][e];const n=e.split("."),s=n.length-1;let r=t;for(let t=0;t<s;t++)r=r[n[t]];return this.objectCache[i][e]={property:r,key:n[s]},this.objectCache[i][e]}doAnim({component:t,name:e,value:i}){const{property:n,key:s}=this.getObjectCache(t,e);n[s]=i}init(){let t;this.checkFinishFunc=this.checkFinish.bind(this),this.timelines.forEach(((e,i)=>{for(let n=0;n<e.values.length-1;n++){const s=e.values[n],r=e.values[n+1],a=new u({value:s.value},this.tweenGroup).to({value:r.value}).duration(r.time-s.time).easing(c[s.tween]).onUpdate((t=>{this.doAnim({component:e.component,name:e.name,value:t.value}),this.emit("update",t.value)}));0===n?this.tweens[i]=a:t.chain(a),t=a}t&&t.onComplete((()=>this.checkFinishFunc()))}))}play(t=1,e){this.currentTime=e,this.stoped=!1,this.start(),this.currIteration=0,this.iteration=t}start(){this.finishCount=0,this.tweens.length=0,this.init(),this.tweens.forEach((t=>t.start(this.currentTime)))}pause(){this.tweens.forEach((t=>t.pause(this.currentTime)))}resume(){this.tweens.forEach((t=>t.resume(this.currentTime)))}stop(){this.stoped=!0,this.tweens.forEach((t=>t.stop()))}destroy(){this.stop(),this.tweens=null,this.timelines=null,this.objectCache=null,this.callbacks.clear(),this.callbacks=null}}class _ extends e.Component{constructor(){super(...arguments),this.animations={},this.group={},this.currentTime=0,this.needPlay=[]}init({group:t}={group:{}}){this.group=t,this.tweenGroup=new r}awake(){for(const t in this.group)this.newAnimation(t)}play(t,e){t||(t=Object.keys(this.group)[0]),t&&!this.animations[t]&&this.group[t]&&this.newAnimation(t),t&&this.animations[t]&&this.needPlay.push({name:t,iteration:e})}stop(t){var e,i;if(t)null===(i=this.animations[t])||void 0===i||i.stop();else for(const t in this.animations)null===(e=this.animations[t])||void 0===e||e.stop()}onPause(){var t;for(const e in this.animations)null===(t=this.animations[e])||void 0===t||t.pause()}onResume(){var t;for(const e in this.animations)null===(t=this.animations[e])||void 0===t||t.resume()}onDestroy(){var t;for(const e in this.animations)null===(t=this.animations[e])||void 0===t||t.destroy();this.tweenGroup.removeAll(),this.tweenGroup=null,this.group=null,this.animations=null,this.removeAllListeners()}update(t){var e;this.currentTime=t.time;for(const e in this.animations)this.animations[e].currentTime=t.time;this.tweenGroup.update(t.time);for(const t of this.needPlay)null===(e=this.animations[t.name])||void 0===e||e.play(t.iteration,this.currentTime);this.needPlay.length=0}newAnimation(t){const e=new p(this.group[t],this.tweenGroup);e.on("finish",(()=>this.emit("finish",t))),e.on("update",(e=>this.emit("update",{name:t,value:e}))),this.animations[t]=e}}_.componentName="Transition";class d extends e.System{constructor(){super(...arguments),this.name="transition"}}return d.systemName="transition",t.Transition=_,t.TransitionSystem=d,Object.defineProperty(t,"__esModule",{value:!0}),t}({},EVA);globalThis.EVA.plugin.transition=globalThis.EVA.plugin.transition||_EVA_IIFE_transition;
|
|
@@ -32,11 +32,11 @@ class Animation {
|
|
|
32
32
|
}
|
|
33
33
|
this.callbacks.get(eventName).push(callback);
|
|
34
34
|
}
|
|
35
|
-
emit(eventName) {
|
|
35
|
+
emit(eventName, ...args) {
|
|
36
36
|
const callbacks = this.callbacks.get(eventName);
|
|
37
37
|
if (!callbacks || !callbacks.length)
|
|
38
38
|
return;
|
|
39
|
-
callbacks.forEach(fn => fn());
|
|
39
|
+
callbacks.forEach(fn => fn(...args));
|
|
40
40
|
}
|
|
41
41
|
checkFinish() {
|
|
42
42
|
if (++this.finishCount == this.tweens.length) {
|
|
@@ -88,6 +88,7 @@ class Animation {
|
|
|
88
88
|
name: timeline.name,
|
|
89
89
|
value: props.value,
|
|
90
90
|
});
|
|
91
|
+
this.emit('update', props.value);
|
|
91
92
|
});
|
|
92
93
|
if (j === 0) {
|
|
93
94
|
this.tweens[i] = tween;
|
|
@@ -133,14 +134,72 @@ class Animation {
|
|
|
133
134
|
}
|
|
134
135
|
}
|
|
135
136
|
|
|
137
|
+
/**
|
|
138
|
+
* 过渡动画组件(基于 Tween.js)
|
|
139
|
+
*
|
|
140
|
+
* Transition 组件为游戏对象提供补间动画功能,可以平滑地改变组件属性。
|
|
141
|
+
* 它基于 Tween.js 实现,支持多种缓动函数、动画组、循环播放等高级功能。
|
|
142
|
+
*
|
|
143
|
+
* 主要功能:
|
|
144
|
+
* - 支持多个命名动画组
|
|
145
|
+
* - 可配置关键帧和缓动函数
|
|
146
|
+
* - 支持动画循环和迭代次数
|
|
147
|
+
* - 提供播放、暂停、停止控制
|
|
148
|
+
* - 支持动画完成和更新事件
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```typescript
|
|
152
|
+
* const sprite = new GameObject('sprite');
|
|
153
|
+
* sprite.addComponent(new Transition({
|
|
154
|
+
* group: {
|
|
155
|
+
* fadeIn: [{
|
|
156
|
+
* name: 'alpha',
|
|
157
|
+
* component: sprite.getComponent('Sprite'),
|
|
158
|
+
* values: [
|
|
159
|
+
* { time: 0, value: 0, tween: 'ease-in' },
|
|
160
|
+
* { time: 1000, value: 1 }
|
|
161
|
+
* ]
|
|
162
|
+
* }],
|
|
163
|
+
* moveRight: [{
|
|
164
|
+
* name: 'position.x',
|
|
165
|
+
* component: sprite.getComponent('Transform'),
|
|
166
|
+
* values: [
|
|
167
|
+
* { time: 0, value: 0 },
|
|
168
|
+
* { time: 2000, value: 500, tween: 'ease-out-quad' }
|
|
169
|
+
* ]
|
|
170
|
+
* }]
|
|
171
|
+
* }
|
|
172
|
+
* }));
|
|
173
|
+
*
|
|
174
|
+
* // 播放动画
|
|
175
|
+
* const transition = sprite.getComponent('Transition');
|
|
176
|
+
* transition.play('fadeIn'); // 播放一次
|
|
177
|
+
* transition.play('moveRight', Infinity); // 无限循环
|
|
178
|
+
*
|
|
179
|
+
* // 监听动画事件
|
|
180
|
+
* transition.on('finish', (name) => {
|
|
181
|
+
* console.log('动画完成:', name);
|
|
182
|
+
* });
|
|
183
|
+
* ```
|
|
184
|
+
*/
|
|
136
185
|
class Transition extends eva_js.Component {
|
|
137
186
|
constructor() {
|
|
138
187
|
super(...arguments);
|
|
188
|
+
/** 动画实例映射表 */
|
|
139
189
|
this.animations = {};
|
|
190
|
+
/** 动画组配置,key 为动画名称,value 为动画配置数组 */
|
|
140
191
|
this.group = {};
|
|
192
|
+
/** 当前时间戳 */
|
|
141
193
|
this.currentTime = 0;
|
|
194
|
+
/** 待播放的动画队列 */
|
|
142
195
|
this.needPlay = [];
|
|
143
196
|
}
|
|
197
|
+
/**
|
|
198
|
+
* 初始化组件
|
|
199
|
+
*
|
|
200
|
+
* @param params - 初始化参数
|
|
201
|
+
* @param params.group - 动画组配置对象
|
|
202
|
+
*/
|
|
144
203
|
init({ group } = { group: {} }) {
|
|
145
204
|
this.group = group;
|
|
146
205
|
this.tweenGroup = new tween_js.Group();
|
|
@@ -150,6 +209,19 @@ class Transition extends eva_js.Component {
|
|
|
150
209
|
this.newAnimation(name);
|
|
151
210
|
}
|
|
152
211
|
}
|
|
212
|
+
/**
|
|
213
|
+
* 播放动画
|
|
214
|
+
*
|
|
215
|
+
* @param name - 动画名称,如果不传则播放第一个动画
|
|
216
|
+
* @param iteration - 循环次数,默认 1,传 Infinity 为无限循环
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```typescript
|
|
220
|
+
* transition.play('fadeIn'); // 播放一次
|
|
221
|
+
* transition.play('rotate', 3); // 循环播放 3 次
|
|
222
|
+
* transition.play('bounce', Infinity); // 无限循环
|
|
223
|
+
* ```
|
|
224
|
+
*/
|
|
153
225
|
play(name, iteration) {
|
|
154
226
|
if (!name) {
|
|
155
227
|
name = Object.keys(this.group)[0];
|
|
@@ -161,6 +233,17 @@ class Transition extends eva_js.Component {
|
|
|
161
233
|
this.needPlay.push({ name, iteration });
|
|
162
234
|
}
|
|
163
235
|
}
|
|
236
|
+
/**
|
|
237
|
+
* 停止动画
|
|
238
|
+
*
|
|
239
|
+
* @param name - 动画名称,如果不传则停止所有动画
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* ```typescript
|
|
243
|
+
* transition.stop('fadeIn'); // 停止指定动画
|
|
244
|
+
* transition.stop(); // 停止所有动画
|
|
245
|
+
* ```
|
|
246
|
+
*/
|
|
164
247
|
stop(name) {
|
|
165
248
|
var _a, _b;
|
|
166
249
|
if (!name) {
|
|
@@ -210,17 +293,32 @@ class Transition extends eva_js.Component {
|
|
|
210
293
|
newAnimation(name) {
|
|
211
294
|
const animation = new Animation(this.group[name], this.tweenGroup);
|
|
212
295
|
animation.on('finish', () => this.emit('finish', name));
|
|
296
|
+
animation.on('update', value => this.emit('update', { name, value }));
|
|
213
297
|
this.animations[name] = animation;
|
|
214
298
|
}
|
|
215
299
|
}
|
|
300
|
+
/** 组件名称 */
|
|
216
301
|
Transition.componentName = 'Transition';
|
|
217
302
|
|
|
303
|
+
/**
|
|
304
|
+
* 过渡动画系统
|
|
305
|
+
*
|
|
306
|
+
* TransitionSystem 是一个轻量级系统,主要用于注册 Transition 插件到游戏中。
|
|
307
|
+
* 实际的动画逻辑由 Transition 组件自身的 update 方法处理。
|
|
308
|
+
*
|
|
309
|
+
* @example
|
|
310
|
+
* ```typescript
|
|
311
|
+
* game.addSystem(new TransitionSystem());
|
|
312
|
+
* ```
|
|
313
|
+
*/
|
|
218
314
|
class TransitionSystem extends eva_js.System {
|
|
219
315
|
constructor() {
|
|
220
316
|
super(...arguments);
|
|
317
|
+
/** 系统实例名称 */
|
|
221
318
|
this.name = 'transition';
|
|
222
319
|
}
|
|
223
320
|
}
|
|
321
|
+
/** 系统名称 */
|
|
224
322
|
TransitionSystem.systemName = 'transition';
|
|
225
323
|
|
|
226
324
|
exports.Transition = Transition;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@tweenjs/tween.js"),i=require("@eva/eva.js");const e={linear:t.Easing.Linear.None,"ease-in":t.Easing.Quadratic.In,"ease-out":t.Easing.Quadratic.Out,"ease-in-out":t.Easing.Quadratic.InOut,"bounce-in":t.Easing.Bounce.In,"bounce-out":t.Easing.Bounce.Out,"bounce-in-out":t.Easing.Bounce.InOut,none:t=>~~t};class s{constructor(t,i){this.tweens=[],this.timelines=[],this.finishCount=0,this.callbacks=new Map,this.objectCache={},this.currIteration=0,this.timelines=t,this.tweenGroup=i}on(t,i){this.callbacks[t]||this.callbacks.set(t,[]),this.callbacks.get(t).push(i)}emit(t){const
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@tweenjs/tween.js"),i=require("@eva/eva.js");const e={linear:t.Easing.Linear.None,"ease-in":t.Easing.Quadratic.In,"ease-out":t.Easing.Quadratic.Out,"ease-in-out":t.Easing.Quadratic.InOut,"bounce-in":t.Easing.Bounce.In,"bounce-out":t.Easing.Bounce.Out,"bounce-in-out":t.Easing.Bounce.InOut,none:t=>~~t};class s{constructor(t,i){this.tweens=[],this.timelines=[],this.finishCount=0,this.callbacks=new Map,this.objectCache={},this.currIteration=0,this.timelines=t,this.tweenGroup=i}on(t,i){this.callbacks[t]||this.callbacks.set(t,[]),this.callbacks.get(t).push(i)}emit(t,...i){const e=this.callbacks.get(t);e&&e.length&&e.forEach((t=>t(...i)))}checkFinish(){if(++this.finishCount==this.tweens.length)if(++this.currIteration==this.iteration)this.emit("finish");else{if(this.stoped)return;this.start()}}getObjectCache(t,i){const e=`${t.gameObject.id}${t.name}`;if(this.objectCache[e]||(this.objectCache[e]={}),this.objectCache[e][i])return this.objectCache[e][i];const s=i.split("."),n=s.length-1;let a=t;for(let t=0;t<n;t++)a=a[s[t]];return this.objectCache[e][i]={property:a,key:s[n]},this.objectCache[e][i]}doAnim({component:t,name:i,value:e}){const{property:s,key:n}=this.getObjectCache(t,i);s[n]=e}init(){let i;this.checkFinishFunc=this.checkFinish.bind(this),this.timelines.forEach(((s,n)=>{for(let a=0;a<s.values.length-1;a++){const o=s.values[a],h=s.values[a+1],r=new t.Tween({value:o.value},this.tweenGroup).to({value:h.value}).duration(h.time-o.time).easing(e[o.tween]).onUpdate((t=>{this.doAnim({component:s.component,name:s.name,value:t.value}),this.emit("update",t.value)}));0===a?this.tweens[n]=r:i.chain(r),i=r}i&&i.onComplete((()=>this.checkFinishFunc()))}))}play(t=1,i){this.currentTime=i,this.stoped=!1,this.start(),this.currIteration=0,this.iteration=t}start(){this.finishCount=0,this.tweens.length=0,this.init(),this.tweens.forEach((t=>t.start(this.currentTime)))}pause(){this.tweens.forEach((t=>t.pause(this.currentTime)))}resume(){this.tweens.forEach((t=>t.resume(this.currentTime)))}stop(){this.stoped=!0,this.tweens.forEach((t=>t.stop()))}destroy(){this.stop(),this.tweens=null,this.timelines=null,this.objectCache=null,this.callbacks.clear(),this.callbacks=null}}class n extends i.Component{constructor(){super(...arguments),this.animations={},this.group={},this.currentTime=0,this.needPlay=[]}init({group:i}={group:{}}){this.group=i,this.tweenGroup=new t.Group}awake(){for(const t in this.group)this.newAnimation(t)}play(t,i){t||(t=Object.keys(this.group)[0]),t&&!this.animations[t]&&this.group[t]&&this.newAnimation(t),t&&this.animations[t]&&this.needPlay.push({name:t,iteration:i})}stop(t){var i,e;if(t)null===(e=this.animations[t])||void 0===e||e.stop();else for(const t in this.animations)null===(i=this.animations[t])||void 0===i||i.stop()}onPause(){var t;for(const i in this.animations)null===(t=this.animations[i])||void 0===t||t.pause()}onResume(){var t;for(const i in this.animations)null===(t=this.animations[i])||void 0===t||t.resume()}onDestroy(){var t;for(const i in this.animations)null===(t=this.animations[i])||void 0===t||t.destroy();this.tweenGroup.removeAll(),this.tweenGroup=null,this.group=null,this.animations=null,this.removeAllListeners()}update(t){var i;this.currentTime=t.time;for(const i in this.animations)this.animations[i].currentTime=t.time;this.tweenGroup.update(t.time);for(const t of this.needPlay)null===(i=this.animations[t.name])||void 0===i||i.play(t.iteration,this.currentTime);this.needPlay.length=0}newAnimation(t){const i=new s(this.group[t],this.tweenGroup);i.on("finish",(()=>this.emit("finish",t))),i.on("update",(i=>this.emit("update",{name:t,value:i}))),this.animations[t]=i}}n.componentName="Transition";class a extends i.System{constructor(){super(...arguments),this.name="transition"}}a.systemName="transition",exports.Transition=n,exports.TransitionSystem=a;
|
|
@@ -12,18 +12,102 @@ declare interface AnimationStruct {
|
|
|
12
12
|
}[];
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* 过渡动画组件(基于 Tween.js)
|
|
17
|
+
*
|
|
18
|
+
* Transition 组件为游戏对象提供补间动画功能,可以平滑地改变组件属性。
|
|
19
|
+
* 它基于 Tween.js 实现,支持多种缓动函数、动画组、循环播放等高级功能。
|
|
20
|
+
*
|
|
21
|
+
* 主要功能:
|
|
22
|
+
* - 支持多个命名动画组
|
|
23
|
+
* - 可配置关键帧和缓动函数
|
|
24
|
+
* - 支持动画循环和迭代次数
|
|
25
|
+
* - 提供播放、暂停、停止控制
|
|
26
|
+
* - 支持动画完成和更新事件
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* const sprite = new GameObject('sprite');
|
|
31
|
+
* sprite.addComponent(new Transition({
|
|
32
|
+
* group: {
|
|
33
|
+
* fadeIn: [{
|
|
34
|
+
* name: 'alpha',
|
|
35
|
+
* component: sprite.getComponent('Sprite'),
|
|
36
|
+
* values: [
|
|
37
|
+
* { time: 0, value: 0, tween: 'ease-in' },
|
|
38
|
+
* { time: 1000, value: 1 }
|
|
39
|
+
* ]
|
|
40
|
+
* }],
|
|
41
|
+
* moveRight: [{
|
|
42
|
+
* name: 'position.x',
|
|
43
|
+
* component: sprite.getComponent('Transform'),
|
|
44
|
+
* values: [
|
|
45
|
+
* { time: 0, value: 0 },
|
|
46
|
+
* { time: 2000, value: 500, tween: 'ease-out-quad' }
|
|
47
|
+
* ]
|
|
48
|
+
* }]
|
|
49
|
+
* }
|
|
50
|
+
* }));
|
|
51
|
+
*
|
|
52
|
+
* // 播放动画
|
|
53
|
+
* const transition = sprite.getComponent('Transition');
|
|
54
|
+
* transition.play('fadeIn'); // 播放一次
|
|
55
|
+
* transition.play('moveRight', Infinity); // 无限循环
|
|
56
|
+
*
|
|
57
|
+
* // 监听动画事件
|
|
58
|
+
* transition.on('finish', (name) => {
|
|
59
|
+
* console.log('动画完成:', name);
|
|
60
|
+
* });
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
15
63
|
export declare class Transition extends Component<TransitionParams> {
|
|
64
|
+
/** 组件名称 */
|
|
16
65
|
static componentName: string;
|
|
66
|
+
/** 动画实例映射表 */
|
|
17
67
|
private animations;
|
|
68
|
+
/** Tween.js 动画组 */
|
|
18
69
|
tweenGroup: Group;
|
|
70
|
+
/** 动画组配置,key 为动画名称,value 为动画配置数组 */
|
|
19
71
|
group: Record<string, AnimationStruct[]>;
|
|
72
|
+
/** 当前时间戳 */
|
|
20
73
|
private currentTime;
|
|
74
|
+
/** 待播放的动画队列 */
|
|
21
75
|
private needPlay;
|
|
76
|
+
/**
|
|
77
|
+
* 初始化组件
|
|
78
|
+
*
|
|
79
|
+
* @param params - 初始化参数
|
|
80
|
+
* @param params.group - 动画组配置对象
|
|
81
|
+
*/
|
|
22
82
|
init({ group }?: {
|
|
23
83
|
group: {};
|
|
24
84
|
}): void;
|
|
25
85
|
awake(): void;
|
|
86
|
+
/**
|
|
87
|
+
* 播放动画
|
|
88
|
+
*
|
|
89
|
+
* @param name - 动画名称,如果不传则播放第一个动画
|
|
90
|
+
* @param iteration - 循环次数,默认 1,传 Infinity 为无限循环
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* transition.play('fadeIn'); // 播放一次
|
|
95
|
+
* transition.play('rotate', 3); // 循环播放 3 次
|
|
96
|
+
* transition.play('bounce', Infinity); // 无限循环
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
26
99
|
play(name: string, iteration?: number): void;
|
|
100
|
+
/**
|
|
101
|
+
* 停止动画
|
|
102
|
+
*
|
|
103
|
+
* @param name - 动画名称,如果不传则停止所有动画
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* transition.stop('fadeIn'); // 停止指定动画
|
|
108
|
+
* transition.stop(); // 停止所有动画
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
27
111
|
stop(name: any): void;
|
|
28
112
|
onPause(): void;
|
|
29
113
|
onResume(): void;
|
|
@@ -36,8 +120,21 @@ declare interface TransitionParams {
|
|
|
36
120
|
group: Record<string, AnimationStruct[]>;
|
|
37
121
|
}
|
|
38
122
|
|
|
123
|
+
/**
|
|
124
|
+
* 过渡动画系统
|
|
125
|
+
*
|
|
126
|
+
* TransitionSystem 是一个轻量级系统,主要用于注册 Transition 插件到游戏中。
|
|
127
|
+
* 实际的动画逻辑由 Transition 组件自身的 update 方法处理。
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* game.addSystem(new TransitionSystem());
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
39
134
|
export declare class TransitionSystem extends System {
|
|
135
|
+
/** 系统名称 */
|
|
40
136
|
static systemName: string;
|
|
137
|
+
/** 系统实例名称 */
|
|
41
138
|
readonly name = "transition";
|
|
42
139
|
}
|
|
43
140
|
|
|
@@ -28,11 +28,11 @@ class Animation {
|
|
|
28
28
|
}
|
|
29
29
|
this.callbacks.get(eventName).push(callback);
|
|
30
30
|
}
|
|
31
|
-
emit(eventName) {
|
|
31
|
+
emit(eventName, ...args) {
|
|
32
32
|
const callbacks = this.callbacks.get(eventName);
|
|
33
33
|
if (!callbacks || !callbacks.length)
|
|
34
34
|
return;
|
|
35
|
-
callbacks.forEach(fn => fn());
|
|
35
|
+
callbacks.forEach(fn => fn(...args));
|
|
36
36
|
}
|
|
37
37
|
checkFinish() {
|
|
38
38
|
if (++this.finishCount == this.tweens.length) {
|
|
@@ -84,6 +84,7 @@ class Animation {
|
|
|
84
84
|
name: timeline.name,
|
|
85
85
|
value: props.value,
|
|
86
86
|
});
|
|
87
|
+
this.emit('update', props.value);
|
|
87
88
|
});
|
|
88
89
|
if (j === 0) {
|
|
89
90
|
this.tweens[i] = tween;
|
|
@@ -129,14 +130,72 @@ class Animation {
|
|
|
129
130
|
}
|
|
130
131
|
}
|
|
131
132
|
|
|
133
|
+
/**
|
|
134
|
+
* 过渡动画组件(基于 Tween.js)
|
|
135
|
+
*
|
|
136
|
+
* Transition 组件为游戏对象提供补间动画功能,可以平滑地改变组件属性。
|
|
137
|
+
* 它基于 Tween.js 实现,支持多种缓动函数、动画组、循环播放等高级功能。
|
|
138
|
+
*
|
|
139
|
+
* 主要功能:
|
|
140
|
+
* - 支持多个命名动画组
|
|
141
|
+
* - 可配置关键帧和缓动函数
|
|
142
|
+
* - 支持动画循环和迭代次数
|
|
143
|
+
* - 提供播放、暂停、停止控制
|
|
144
|
+
* - 支持动画完成和更新事件
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* const sprite = new GameObject('sprite');
|
|
149
|
+
* sprite.addComponent(new Transition({
|
|
150
|
+
* group: {
|
|
151
|
+
* fadeIn: [{
|
|
152
|
+
* name: 'alpha',
|
|
153
|
+
* component: sprite.getComponent('Sprite'),
|
|
154
|
+
* values: [
|
|
155
|
+
* { time: 0, value: 0, tween: 'ease-in' },
|
|
156
|
+
* { time: 1000, value: 1 }
|
|
157
|
+
* ]
|
|
158
|
+
* }],
|
|
159
|
+
* moveRight: [{
|
|
160
|
+
* name: 'position.x',
|
|
161
|
+
* component: sprite.getComponent('Transform'),
|
|
162
|
+
* values: [
|
|
163
|
+
* { time: 0, value: 0 },
|
|
164
|
+
* { time: 2000, value: 500, tween: 'ease-out-quad' }
|
|
165
|
+
* ]
|
|
166
|
+
* }]
|
|
167
|
+
* }
|
|
168
|
+
* }));
|
|
169
|
+
*
|
|
170
|
+
* // 播放动画
|
|
171
|
+
* const transition = sprite.getComponent('Transition');
|
|
172
|
+
* transition.play('fadeIn'); // 播放一次
|
|
173
|
+
* transition.play('moveRight', Infinity); // 无限循环
|
|
174
|
+
*
|
|
175
|
+
* // 监听动画事件
|
|
176
|
+
* transition.on('finish', (name) => {
|
|
177
|
+
* console.log('动画完成:', name);
|
|
178
|
+
* });
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
132
181
|
class Transition extends Component {
|
|
133
182
|
constructor() {
|
|
134
183
|
super(...arguments);
|
|
184
|
+
/** 动画实例映射表 */
|
|
135
185
|
this.animations = {};
|
|
186
|
+
/** 动画组配置,key 为动画名称,value 为动画配置数组 */
|
|
136
187
|
this.group = {};
|
|
188
|
+
/** 当前时间戳 */
|
|
137
189
|
this.currentTime = 0;
|
|
190
|
+
/** 待播放的动画队列 */
|
|
138
191
|
this.needPlay = [];
|
|
139
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* 初始化组件
|
|
195
|
+
*
|
|
196
|
+
* @param params - 初始化参数
|
|
197
|
+
* @param params.group - 动画组配置对象
|
|
198
|
+
*/
|
|
140
199
|
init({ group } = { group: {} }) {
|
|
141
200
|
this.group = group;
|
|
142
201
|
this.tweenGroup = new Group();
|
|
@@ -146,6 +205,19 @@ class Transition extends Component {
|
|
|
146
205
|
this.newAnimation(name);
|
|
147
206
|
}
|
|
148
207
|
}
|
|
208
|
+
/**
|
|
209
|
+
* 播放动画
|
|
210
|
+
*
|
|
211
|
+
* @param name - 动画名称,如果不传则播放第一个动画
|
|
212
|
+
* @param iteration - 循环次数,默认 1,传 Infinity 为无限循环
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```typescript
|
|
216
|
+
* transition.play('fadeIn'); // 播放一次
|
|
217
|
+
* transition.play('rotate', 3); // 循环播放 3 次
|
|
218
|
+
* transition.play('bounce', Infinity); // 无限循环
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
149
221
|
play(name, iteration) {
|
|
150
222
|
if (!name) {
|
|
151
223
|
name = Object.keys(this.group)[0];
|
|
@@ -157,6 +229,17 @@ class Transition extends Component {
|
|
|
157
229
|
this.needPlay.push({ name, iteration });
|
|
158
230
|
}
|
|
159
231
|
}
|
|
232
|
+
/**
|
|
233
|
+
* 停止动画
|
|
234
|
+
*
|
|
235
|
+
* @param name - 动画名称,如果不传则停止所有动画
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```typescript
|
|
239
|
+
* transition.stop('fadeIn'); // 停止指定动画
|
|
240
|
+
* transition.stop(); // 停止所有动画
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
160
243
|
stop(name) {
|
|
161
244
|
var _a, _b;
|
|
162
245
|
if (!name) {
|
|
@@ -206,17 +289,32 @@ class Transition extends Component {
|
|
|
206
289
|
newAnimation(name) {
|
|
207
290
|
const animation = new Animation(this.group[name], this.tweenGroup);
|
|
208
291
|
animation.on('finish', () => this.emit('finish', name));
|
|
292
|
+
animation.on('update', value => this.emit('update', { name, value }));
|
|
209
293
|
this.animations[name] = animation;
|
|
210
294
|
}
|
|
211
295
|
}
|
|
296
|
+
/** 组件名称 */
|
|
212
297
|
Transition.componentName = 'Transition';
|
|
213
298
|
|
|
299
|
+
/**
|
|
300
|
+
* 过渡动画系统
|
|
301
|
+
*
|
|
302
|
+
* TransitionSystem 是一个轻量级系统,主要用于注册 Transition 插件到游戏中。
|
|
303
|
+
* 实际的动画逻辑由 Transition 组件自身的 update 方法处理。
|
|
304
|
+
*
|
|
305
|
+
* @example
|
|
306
|
+
* ```typescript
|
|
307
|
+
* game.addSystem(new TransitionSystem());
|
|
308
|
+
* ```
|
|
309
|
+
*/
|
|
214
310
|
class TransitionSystem extends System {
|
|
215
311
|
constructor() {
|
|
216
312
|
super(...arguments);
|
|
313
|
+
/** 系统实例名称 */
|
|
217
314
|
this.name = 'transition';
|
|
218
315
|
}
|
|
219
316
|
}
|
|
317
|
+
/** 系统名称 */
|
|
220
318
|
TransitionSystem.systemName = 'transition';
|
|
221
319
|
|
|
222
320
|
export { Transition, TransitionSystem };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eva/plugin-transition",
|
|
3
|
-
"version": "2.0.1-beta.
|
|
3
|
+
"version": "2.0.1-beta.30",
|
|
4
4
|
"description": "@eva/plugin-transition",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "dist/plugin-transition.esm.js",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"homepage": "https://eva.js.org",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@eva/eva.js": "2.0.1-beta.
|
|
21
|
+
"@eva/eva.js": "2.0.1-beta.30",
|
|
22
22
|
"@tweenjs/tween.js": "^18.6.4",
|
|
23
23
|
"sprite-timeline": "^1.10.2"
|
|
24
24
|
}
|