diff --git a/cocos/tween/tween-action.ts b/cocos/tween/tween-action.ts index da6f06bf043..7d1595c1ca7 100644 --- a/cocos/tween/tween-action.ts +++ b/cocos/tween/tween-action.ts @@ -213,6 +213,19 @@ export class TweenAction extends ActionInterval { prop.end.w = value.w; } prop.type = 'rect'; + } else if (_t instanceof Quat) { + if (prop.start == null) { + prop.start = new Quat(); prop.current = new Quat(); prop.end = new Quat(); + } + prop.start.set(_t); + prop.current.set(_t); + if (relative) { + Quat.multiply(prop.end, _t, value); + } else { + prop.end.set(value); + } + prop.type = 'quat'; + warn('Quaternion only support slerp interpolation method.'); } else if (typeof _t === 'object') { if (_t instanceof Vec2) { if (prop.start == null) { @@ -234,19 +247,14 @@ export class TweenAction extends ActionInterval { prop.start = new Size(); prop.current = new Size(); prop.end = new Size(); } prop.type = 'size'; - } else if (_t instanceof Quat) { - if (prop.start == null) { - prop.start = new Quat(); prop.current = new Quat(); prop.end = new Quat(); - } - prop.type = 'quat'; } else if (prop.start == null) { prop.start = {}; prop.current = {}; prop.end = {}; } for (const k in value) { // filtering if it not a number - // eslint-disable-next-line no-restricted-globals, @typescript-eslint/no-unsafe-argument - if (isNaN(_t[k])) continue; + // eslint-disable-next-line no-restricted-globals + if (isNaN(_t[k] as number)) continue; prop.start[k] = _t[k]; prop.current[k] = _t[k]; // eslint-disable-next-line @typescript-eslint/restrict-plus-operands @@ -309,12 +317,6 @@ export class TweenAction extends ActionInterval { Quat.slerp(prop.current, start, end, time as number); } else { for (const k in start) { - // if (value[k].easing) { - // time = value[k].easing(t); - // } - // if (value[k].progress) { - // interpolation = value[k].easing(t); - // } prop.current[k] = interpolation(start[k], end[k], prop.current[k], time); } } diff --git a/tests/tween/tween.test.ts b/tests/tween/tween.test.ts index 6bf67c57aed..995d059c8f3 100644 --- a/tests/tween/tween.test.ts +++ b/tests/tween/tween.test.ts @@ -44,15 +44,21 @@ test('destroySelf', function () { }); test('type color', function () { + const sys = new TweenSystem(); + (TweenSystem.instance as any) = sys; + director.registerSystem(TweenSystem.ID, sys, System.Priority.MEDIUM); + const shadow = new Shadows(); shadow.shadowColor.set(200, 100, 50, 250); const target = Color.TRANSPARENT; const tweenact = tween(shadow).to(1, {shadowColor: target}); tweenact.start(); + for (let i = 0; i < 100; ++i) { + game.step(); + } // @ts-expect-error access private property const action = tweenact._actions[0] as TweenAction; - action.update(1.0); // @ts-expect-error access private property const props = action._props; for (const property in props) { @@ -60,17 +66,24 @@ test('type color', function () { expect(prop.current instanceof Color).toBeTruthy(); expect(Color.equals(prop.current, target)).toBeTruthy(); } + director.unregisterSystem(sys); }); test('type quat', function () { + const sys = new TweenSystem(); + (TweenSystem.instance as any) = sys; + director.registerSystem(TweenSystem.ID, sys, System.Priority.MEDIUM); + const node = new Node(); const target = new Quat(1, 1, 1, 1); const tweenact = tween(node).to(1, {rotation: target}); tweenact.start(); + for (let i = 0; i < 100; ++i) { + game.step(); + } // @ts-expect-error access private property const action = tweenact._actions[0] as TweenAction; - action.update(1.0); // @ts-expect-error access private property const props = action._props; for (const property in props) { @@ -78,71 +91,99 @@ test('type quat', function () { expect(prop.current instanceof Quat).toBeTruthy(); expect(Quat.equals(prop.current, target)).toBeTruthy(); } + director.unregisterSystem(sys); }); test('type rect', function () { + const sys = new TweenSystem(); + (TweenSystem.instance as any) = sys; + director.registerSystem(TweenSystem.ID, sys, System.Priority.MEDIUM); + const camera = new CameraComponent(); const target = new Rect(1, 1, 10, 20); const tweenact = tween(camera).to(1, {rect: target}); tweenact.start(); + for (let i = 0; i < 100; ++i) { + game.step(); + } // @ts-expect-error access private property const action = tweenact._actions[0] as TweenAction; - action.update(1.0); // @ts-expect-error access private property const props = action._props; for (const property in props) { const prop = props[property]; expect(prop.current instanceof Rect).toBeTruthy(); expect(Rect.equals(prop.current, target)).toBeTruthy(); - } + } + director.unregisterSystem(sys); }); test('type size', function () { + const sys = new TweenSystem(); + (TweenSystem.instance as any) = sys; + director.registerSystem(TweenSystem.ID, sys, System.Priority.MEDIUM); + const rect = new Rect(); const target = new Size(800, 600); const tweenact = tween(rect).to(1, {size: target}); tweenact.start(); + for (let i = 0; i < 100; ++i) { + game.step(); + } // @ts-expect-error access private property const action = tweenact._actions[0] as TweenAction; - action.update(1.0); // @ts-expect-error access private property const props = action._props; for (const property in props) { const prop = props[property]; expect(prop.current instanceof Size).toBeTruthy(); expect(Rect.equals(prop.current, target)).toBeTruthy(); - } + } + director.unregisterSystem(sys); }); test('type vec2', function () { + const sys = new TweenSystem(); + (TweenSystem.instance as any) = sys; + director.registerSystem(TweenSystem.ID, sys, System.Priority.MEDIUM); + const rect = new Rect(); const target = new Vec2(20, 10); const tweenact = tween(rect).to(1, {origin: target}); tweenact.start(); + for (let i = 0; i < 100; ++i) { + game.step(); + } // @ts-expect-error access private property const action = tweenact._actions[0] as TweenAction; - action.update(1.0); // @ts-expect-error access private property const props = action._props; for (const property in props) { const prop = props[property]; expect(prop.current instanceof Vec2).toBeTruthy(); expect(Vec2.equals(prop.current, target)).toBeTruthy(); - } + } + director.unregisterSystem(sys); }); test('type vec3', function () { + const sys = new TweenSystem(); + (TweenSystem.instance as any) = sys; + director.registerSystem(TweenSystem.ID, sys, System.Priority.MEDIUM); + const node = new Node(); const target = new Vec3(10, 20, 30); const tweenact = tween(node).to(1, {position: target}); tweenact.start(); + for (let i = 0; i < 100; ++i) { + game.step(); + } // @ts-expect-error access private property const action = tweenact._actions[0] as TweenAction; - action.update(1.0); // @ts-expect-error access private property const props = action._props; for (const property in props) { @@ -150,22 +191,30 @@ test('type vec3', function () { expect(prop.current instanceof Vec3).toBeTruthy(); expect(Vec3.equals(prop.current, target)).toBeTruthy(); } + director.unregisterSystem(sys); }); test('type vec4', function () { + const sys = new TweenSystem(); + (TweenSystem.instance as any) = sys; + director.registerSystem(TweenSystem.ID, sys, System.Priority.MEDIUM); + const shadowLayer = new CSMShadowLayer(4); const target = new Vec4(10, 20, 30, 40); const tweenact = tween(shadowLayer).to(1, {csmAtlas: target}); tweenact.start(); + for (let i = 0; i < 100; ++i) { + game.step(); + } // @ts-expect-error access private property const action = tweenact._actions[0] as TweenAction; - action.update(1.0); // @ts-expect-error access private property const props = action._props; for (const property in props) { const prop = props[property]; expect(prop.current instanceof Vec4).toBeTruthy(); expect(Vec4.equals(prop.current, target)).toBeTruthy(); - } + } + director.unregisterSystem(sys); }); \ No newline at end of file