mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
The public method Tween.union() should not update workerTarget. (#17020)
* The public method `Tween.union()` should not update workerTarget. Add more unit test for tween. * Revert
This commit is contained in:
@@ -88,7 +88,7 @@ export class Tween<T extends object = any> {
|
||||
* @param other @en The rear tween of this tween @zh 当前缓动的后置缓动
|
||||
*/
|
||||
then<U extends object = any> (other: Tween<U>): Tween<T> {
|
||||
const u = other._union();
|
||||
const u = other._union(true);
|
||||
if (u) this._actions.push(u);
|
||||
return this;
|
||||
}
|
||||
@@ -177,7 +177,7 @@ export class Tween<T extends object = any> {
|
||||
* @param target @en The target of clone tween @zh 克隆缓动的目标对象
|
||||
*/
|
||||
clone<U extends object = any> (target: U): Tween<U> {
|
||||
const action = this._union();
|
||||
const action = this._union(false);
|
||||
const r = tween(target);
|
||||
return action ? r.insertAction(action) : r;
|
||||
}
|
||||
@@ -189,7 +189,7 @@ export class Tween<T extends object = any> {
|
||||
* 将之前所有的 action 整合为一个 action。
|
||||
*/
|
||||
union (): Tween<T> {
|
||||
const action = this._union();
|
||||
const action = this._union(false);
|
||||
this._actions.length = 0;
|
||||
if (action) this._actions.push(action);
|
||||
return this;
|
||||
@@ -330,7 +330,7 @@ export class Tween<T extends object = any> {
|
||||
let action: FiniteTimeAction | undefined | null;
|
||||
|
||||
if (embedTween instanceof Tween) {
|
||||
action = embedTween._union();
|
||||
action = embedTween._union(false);
|
||||
} else {
|
||||
action = actions.pop();
|
||||
}
|
||||
@@ -353,7 +353,7 @@ export class Tween<T extends object = any> {
|
||||
let action: FiniteTimeAction | undefined | null;
|
||||
|
||||
if (embedTween instanceof Tween) {
|
||||
action = embedTween._union();
|
||||
action = embedTween._union(false);
|
||||
} else {
|
||||
action = actions.pop();
|
||||
}
|
||||
@@ -380,7 +380,7 @@ export class Tween<T extends object = any> {
|
||||
let action: Action | undefined | null;
|
||||
|
||||
if (embedTween instanceof Tween) {
|
||||
action = embedTween._union();
|
||||
action = embedTween._union(false);
|
||||
} else {
|
||||
action = actions.pop();
|
||||
}
|
||||
@@ -481,7 +481,7 @@ export class Tween<T extends object = any> {
|
||||
TweenSystem.instance.ActionManager.removeAllActionsFromTarget(target);
|
||||
}
|
||||
|
||||
private _union (updateWorkerTarget: boolean = true): FiniteTimeAction | null {
|
||||
private _union (updateWorkerTarget: boolean): FiniteTimeAction | null {
|
||||
const actions = this._actions;
|
||||
if (!actions) return null;
|
||||
let action: FiniteTimeAction;
|
||||
@@ -504,7 +504,7 @@ export class Tween<T extends object = any> {
|
||||
tmp_args.length = 0;
|
||||
for (let l = args.length, i = 0; i < l; i++) {
|
||||
const arg = args[i];
|
||||
const action = arg._union();
|
||||
const action = arg._union(true);
|
||||
if (action) tmp_args.push(action);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -676,6 +676,116 @@ test('Test different target in nest sequence 1', function() {
|
||||
director.unregisterSystem(sys);
|
||||
});
|
||||
|
||||
test('Test different target and union', function() {
|
||||
const sys = new TweenSystem();
|
||||
(TweenSystem.instance as any) = sys;
|
||||
director.registerSystem(TweenSystem.ID, sys, System.Priority.MEDIUM);
|
||||
|
||||
// test begin
|
||||
const rootTarget = { position: new Vec3() };
|
||||
const uiTransformTarget = { contentSize: new Size() };
|
||||
|
||||
tween(rootTarget)
|
||||
.parallel(
|
||||
tween(rootTarget).by(1, { position: new Vec3(100, 100, 100) }, {
|
||||
onStart(target) {
|
||||
expect(target === rootTarget).toBeTruthy();
|
||||
},
|
||||
}),
|
||||
tween(uiTransformTarget).by(1, { contentSize: new Size(100, 100) }, {
|
||||
onStart(target) {
|
||||
expect(target === uiTransformTarget).toBeTruthy();
|
||||
},
|
||||
}),
|
||||
)
|
||||
.union()
|
||||
.start();
|
||||
|
||||
// The first step is from 0, so we need to add one more frame to make the action run to 1/3 time.
|
||||
for (let i = 0; i < 21; ++i) {
|
||||
game.step();
|
||||
}
|
||||
expect(new Vec3(1.0/3.0*100, 1.0/3.0*100, 1.0/3.0*100).equals(rootTarget.position)).toBeTruthy();
|
||||
expect(isSizeEqualTo(uiTransformTarget.contentSize, new Size(1.0/3.0*100, 1.0/3.0*100))).toBeTruthy();
|
||||
|
||||
// 2/3 time
|
||||
for (let i = 0; i < 20; ++i) {
|
||||
game.step();
|
||||
}
|
||||
|
||||
expect(new Vec3(2.0/3.0*100, 2.0/3.0*100, 2.0/3.0*100).equals(rootTarget.position)).toBeTruthy();
|
||||
expect(isSizeEqualTo(uiTransformTarget.contentSize, new Size(2.0/3.0*100, 2.0/3.0*100))).toBeTruthy();
|
||||
|
||||
// complete position tween
|
||||
for (let i = 0; i < 20; ++i) {
|
||||
game.step();
|
||||
}
|
||||
|
||||
expect(new Vec3(100, 100, 100).equals(rootTarget.position)).toBeTruthy();
|
||||
expect(isSizeEqualTo(uiTransformTarget.contentSize, new Size(100, 100))).toBeTruthy();
|
||||
|
||||
// test end
|
||||
director.unregisterSystem(sys);
|
||||
});
|
||||
|
||||
test('Test different target, union, repeat with embed tween', function() {
|
||||
const sys = new TweenSystem();
|
||||
(TweenSystem.instance as any) = sys;
|
||||
director.registerSystem(TweenSystem.ID, sys, System.Priority.MEDIUM);
|
||||
|
||||
// test begin
|
||||
const rootTarget = { position: new Vec3() };
|
||||
const uiTransformTarget = { contentSize: new Size() };
|
||||
|
||||
const t = tween(rootTarget).parallel(
|
||||
tween(rootTarget).by(1, { position: new Vec3(100, 100, 100) }, {
|
||||
onStart(target) {
|
||||
expect(target === rootTarget).toBeTruthy();
|
||||
},
|
||||
}),
|
||||
tween(uiTransformTarget).by(1, { contentSize: new Size(100, 100) }, {
|
||||
onStart(target) {
|
||||
expect(target === uiTransformTarget).toBeTruthy();
|
||||
},
|
||||
}),
|
||||
).union();
|
||||
|
||||
tween(rootTarget).repeat(2, t).start();
|
||||
|
||||
// The first step is from 0, so we need to add one more frame to make the action run to 1/3 time.
|
||||
for (let i = 0; i < 21; ++i) {
|
||||
game.step();
|
||||
}
|
||||
expect(new Vec3(1.0/3.0*100, 1.0/3.0*100, 1.0/3.0*100).equals(rootTarget.position)).toBeTruthy();
|
||||
expect(isSizeEqualTo(uiTransformTarget.contentSize, new Size(1.0/3.0*100, 1.0/3.0*100))).toBeTruthy();
|
||||
|
||||
// 2/3 time
|
||||
for (let i = 0; i < 20; ++i) {
|
||||
game.step();
|
||||
}
|
||||
|
||||
expect(new Vec3(2.0/3.0*100, 2.0/3.0*100, 2.0/3.0*100).equals(rootTarget.position)).toBeTruthy();
|
||||
expect(isSizeEqualTo(uiTransformTarget.contentSize, new Size(2.0/3.0*100, 2.0/3.0*100))).toBeTruthy();
|
||||
|
||||
// complete position tween
|
||||
for (let i = 0; i < 20; ++i) {
|
||||
game.step();
|
||||
}
|
||||
|
||||
expect(new Vec3(100, 100, 100).equals(rootTarget.position)).toBeTruthy();
|
||||
expect(isSizeEqualTo(uiTransformTarget.contentSize, new Size(100, 100))).toBeTruthy();
|
||||
|
||||
// 2s
|
||||
for (let i = 0; i < 60; ++i) {
|
||||
game.step();
|
||||
}
|
||||
expect(new Vec3(200, 200, 200).equals(rootTarget.position)).toBeTruthy();
|
||||
expect(isSizeEqualTo(uiTransformTarget.contentSize, new Size(200, 200))).toBeTruthy();
|
||||
|
||||
// test end
|
||||
director.unregisterSystem(sys);
|
||||
});
|
||||
|
||||
test('Test different target in nest sequence 2', function() {
|
||||
// @ts-expect-error
|
||||
director.root!._batcher = new Batcher2D(director.root!);
|
||||
|
||||
Reference in New Issue
Block a user