cocos-engine icon indicating copy to clipboard operation
cocos-engine copied to clipboard

[v3.8.5] Support difference targets in sequence and parallel chain

Open dumganhar opened this issue 1 year ago • 2 comments

Re: #16978

Changelog


Continuous Integration

This pull request:

  • [ ] needs automatic test cases check.

    Manual trigger with @cocos-robot run test cases afterward.

  • [ ] does not change any runtime related code or build configuration

    If any reviewer thinks the CI checks are needed, please uncheck this option, then close and reopen the issue.


Compatibility Check

This pull request:

  • [ ] changes public API, and have ensured backward compatibility with deprecated features.
  • [ ] affects platform compatibility, e.g. system version, browser version, platform sdk version, platform toolchain, language version, hardware compatibility etc.
  • [ ] affects file structure of the build package or build configuration which requires user project upgrade.
  • [ ] introduces breaking changes, please list all changes, affected features and the scope of violation.

dumganhar avatar May 12 '24 10:05 dumganhar

Interface Check Report

! WARNING this pull request has changed these public interfaces:

@@ -54747,9 +54747,9 @@
          * 插入一个 tween 到队列中。
          * @method then
          * @param other @en The rear tween of this tween @zh 当前缓动的后置缓动
          */
-        then(other: Tween<T>): Tween<T>;
+        then<U extends object = any>(other: Tween<U>): Tween<T>;
         /**
          * @en
          * Sets tween target.
          * @zh
@@ -54854,18 +54854,18 @@
          * 添加一个队列 action。
          * @method sequence
          * @param args @en All tween that make up the sequence @zh 组成队列的所有缓动
          */
-        sequence(...args: Tween<T>[]): Tween<T>;
+        sequence(...args: Tween<any>[]): Tween<T>;
         /**
          * @en
          * Add a parallel action.
          * @zh
          * 添加一个并行 action。
          * @method parallel
          * @param args @en The tween parallel to this tween @zh 与当前缓动并行的缓动
          */
-        parallel(...args: Tween<T>[]): Tween<T>;
+        parallel(...args: Tween<any>[]): Tween<T>;
         /**
          * @en
          * Add a repeat action.
          * This action will integrate before actions to a sequence action as their parameters.
@@ -54947,9 +54947,9 @@
     }
     export class TweenAction<T> extends __private._cocos_tween_actions_action_interval__ActionInterval {
         constructor(duration: number, props: any, opts?: ITweenOption<T>);
         clone(): TweenAction<T>;
-        startWithTarget<U>(target: U | undefined): void;
+        startWithTarget<U>(target: U | null): void;
         update(t: number): void;
         progress(start: number, end: number, current: number, t: number): number;
     }
     /**
@@ -68875,10 +68875,57 @@
              * @static
              * @default -1
              */
             static TAG_INVALID: number;
+            /**
+             * The `originalTarget` and `target` are both assigned in `startWithTarget` method,
+             * and they get the same value normally. The difference between `originalTarget` and
+             * `target` is that `target` will be set to null after `stop` method is invoked
+             * but `originalTarget` will not. Therefore, ActionManager could remove a stopped action
+             * from hash map by searching action's `originalTarget`. You could refer to
+             * ActionManager.removeAction for the details.
+             */
             protected originalTarget: unknown;
             protected target: unknown;
+            /**
+             * The `workerTarget` was added from Cocos Creator 3.8.5 and it's used for nest `Tween` functionality.
+             * It stores the target of sub-tween and its value may be different from `target`.
+             *
+             * Example 1:
+             * ```ts
+             *   tween(node).to(1, { scale: new Vec3(2, 2, 2) }).start();
+             *   // target and original target are both `node`, workerTarget is `null`.
+             * ```
+             *
+             * Example 2:
+             * ```ts
+             *   tween(node).parallel(                                        // ----- Root tween
+             *       tween(node).to(1, { scale: new Vec3(2, 2, 2) }),         // ----- Sub tween 1
+             *       tween(node).to(1, { position: new Vec3(10, 10, 10) })    // ----- Sub Tween 2
+             *   ).start();
+             *   // Note that only root tween is started here. We call tweens in `parallel`/`sequence` sub tweens.
+             *   // The `target` and `originalTarget` of all internal actions are `node`.
+             *   // Actions in root tween: workerTarget = null
+             *   // Actions in sub tween 1: workerTarget = node
+             *   // Actions in sub tween 2: workerTarget = node
+             * ```
+             *
+             * Example 3:
+             * ```ts
+             *   tween(node).parallel(                                        // ----- Root tween
+             *       tween(node).to(1, { scale: new Vec3(2, 2, 2) }),         // ----- Sub tween 1
+             *       tween(node.getComponent(UITransform)).to(1, {            // ----- Sub Tween 2
+             *           contentSize: new Size(10, 10)
+             *       })
+             *   ).start();
+             *   // Note that only root tween is started here. We call tweens in `parallel`/`sequence` sub tweens.
+             *   // The `target` and `originalTarget` of all internal actions are `node`.
+             *   // Actions in root tween: workerTarget = null
+             *   // Actions in sub tween 1: workerTarget = node
+             *   // Actions in sub tween 2: workerTarget = node's UITransform component
+             * ```
+             */
+            workerTarget: unknown;
             protected tag: number;
             /**
              * @en
              * to copy object with deep copy.
@@ -69194,9 +69241,9 @@
             protected _elapsed: number;
             protected _firstTick: boolean;
             protected _speed: number;
             protected _repeatForever: boolean;
-            _repeatMethod: boolean;
+            protected _repeatMethod: boolean;
             protected _speedMethod: boolean;
             constructor(d?: number);
             getElapsed(): number;
             initWithDuration(d: number): boolean;
@@ -69205,10 +69252,8 @@
             abstract clone(): _cocos_tween_actions_action_interval__ActionInterval;
             step(dt: number): void;
             startWithTarget<T>(target: T | null): void;
             reverse(): _cocos_tween_actions_action_interval__ActionInterval;
-            setAmplitudeRate(amp: number): void;
-            getAmplitudeRate(): number;
             /**
              * @en
              * Changes the speed of an action, making it take longer (speed>1)
              * or less (speed<1) time. <br/>

github-actions[bot] avatar May 12 '24 10:05 github-actions[bot]

TODO:

  • [x] handle .then
  • [x] nest tween in deep depth
  • [x] nest sequence and parallel
  • [x] re-targetting
  • [x] clone with target

dumganhar avatar May 12 '24 14:05 dumganhar

What's the usage with different targets?

minggo avatar May 13 '24 01:05 minggo

Could see the new code I added in the test case. Or refer to https://forum.cocos.org/t/topic/157814/7?u=dumganhar

dumganhar avatar May 13 '24 01:05 dumganhar

@cocos-robot run test cases

dumganhar avatar May 16 '24 11:05 dumganhar

@cocos-robot run test cases

dumganhar avatar May 17 '24 13:05 dumganhar

@cocos-robot run test cases

dumganhar avatar May 20 '24 03:05 dumganhar

@dumganhar, Please check the result of run test cases:

  • Test Platform: PR-Test
  • Editor Version: v3.8.5
  • Task Result: PASS
  • Task URL: https://cctest.cocos.org/#/reportview/PR-TEST/47ddeb27-a0a5-4345-8622-4e208bd07231/-1
  • GitHub Action: https://github.com/cocos/cocos-engine/actions/runs/9153183525

Task Details

github-actions[bot] avatar May 20 '24 04:05 github-actions[bot]

@dumganhar, Please check the result of run test cases:

  • Test Platform: PR-Test
  • Editor Version: v3.8.5
  • Task Result: FAIL
  • Task URL: https://cctest.cocos.org/#/reportview/PR-TEST/cabe3b59-b436-4bd3-9027-15e28ca6a423/-1
  • GitHub Action: https://github.com/cocos/cocos-engine/actions/runs/9153183525

Task Details

Platform build boot runned crashScene FailScene
web-mobile PASS PASS PASS
windows PASS PASS FAIL capture_to_web,cameraUseRenderTex,use-render-texture-asset
android PASS PASS PASS

github-actions[bot] avatar May 20 '24 04:05 github-actions[bot]

Fix a bug about union here: https://github.com/cocos/cocos-engine/pull/17020

dumganhar avatar May 21 '24 10:05 dumganhar