Skip to content

将 UIRenderer 的 _fillColorType 属性 改为 protected #18914

Open
finscn wants to merge 3 commits into
cocos:v3.8.8from
finscn:patch-30
Open

将 UIRenderer 的 _fillColorType 属性 改为 protected #18914
finscn wants to merge 3 commits into
cocos:v3.8.8from
finscn:patch-30

Conversation

@finscn

@finscn finscn commented Aug 19, 2025

Copy link
Copy Markdown
Contributor

修改理由:

  1. 子类可以更方便的操作该属性
  2. 子类中 如果 _fillColorType 的默认值不同, 可以直接设置, 不用再麻烦的弄个构造函数. (可以参考 MotionStreak 的更改)

Greptile Summary

Changed UIRenderer._fillColorType from private to protected with explicit type annotation, allowing subclasses to override the default value directly through property initialization instead of requiring a constructor.

  • Simplified MotionStreak by removing its constructor and directly setting _fillColorType = RenderEntityFillColorType.VERTEX
  • Added _renderEntity.setFillColorType(this._fillColorType) call in UIRenderer.onLoad() to ensure the render entity is properly configured with the (potentially overridden) fill color type
  • Added explicit type annotation : RenderEntityFillColorType to _fillColorType property for better type safety

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes are well-designed and improve code quality. The visibility change from private to protected follows proper OOP encapsulation principles, the explicit type annotation improves type safety, and the addition of setFillColorType() in onLoad() ensures proper initialization. The refactoring of MotionStreak demonstrates the benefit of this change by eliminating boilerplate constructor code. This is a clean refactoring with no functional changes to existing behavior.
  • No files require special attention

Important Files Changed

Filename Overview
cocos/2d/framework/ui-renderer.ts Changed _fillColorType from private to protected with explicit type annotation, added initialization call in onLoad()
cocos/particle-2d/motion-streak-2d.ts Removed constructor, now directly initializes _fillColorType as a protected property with VERTEX value

Sequence Diagram

sequenceDiagram
    participant Subclass as MotionStreak (Subclass)
    participant Base as UIRenderer (Base)
    participant Entity as RenderEntity
    
    Note over Subclass,Entity: Before PR: Constructor approach
    Subclass->>Base: constructor()
    Base->>Base: _fillColorType = COLOR (default)
    Base->>Entity: createRenderEntity()
    Subclass->>Base: setFillColorType(VERTEX)
    Base->>Base: _fillColorType = VERTEX
    Base->>Entity: setFillColorType(VERTEX)
    
    Note over Subclass,Entity: After PR: Property override approach
    Subclass->>Subclass: _fillColorType = VERTEX (property initialization)
    Subclass->>Base: constructor()
    Base->>Base: (skips _fillColorType init, already set)
    Base->>Entity: createRenderEntity()
    Note over Base: onLoad() lifecycle
    Base->>Entity: setFillColorType(_fillColorType)
    Entity->>Entity: Applies VERTEX value
Loading

@github-actions

github-actions Bot commented Aug 19, 2025

Copy link
Copy Markdown

Code Size Check Report

Wechat (WASM) Before After Diff
2D Empty (legacy pipeline) 1009738 bytes 1009841 bytes ⚠️ +103 bytes
2D All (legacy pipeline) 2675347 bytes 2675535 bytes ⚠️ +188 bytes
2D All (new pipeline) 2767083 bytes 2767271 bytes ⚠️ +188 bytes
(2D + 3D) All 10024081 bytes 10024269 bytes ⚠️ +188 bytes
Web (WASM + ASMJS) Before After Diff
(2D + 3D) All 16843143 bytes 16843331 bytes ⚠️ +188 bytes

Interface Check Report

! WARNING this pull request has changed these public interfaces:

@@ -1410,8 +1410,13 @@
          * @deprecated Since v3.7.0, this is an engine private interface that will be removed in the future.
          */
         get renderEntity(): __private._cocos_2d_renderer_render_entity__RenderEntity;
         /**
+         * @en UI rendering component fill color type, COLOR means using color property value to fill, VERTEX means using vertex color value to fill.
+         * @zh UI 渲染组件填充颜色类型,COLOR 表示使用 color 属性值填充,VERTEX 表示使用顶点颜色值填充。
+         */
+        protected _fillColorType: __private._cocos_2d_renderer_render_entity__RenderEntityFillColorType;
+        /**
          * @deprecated Since v3.7.0, this is an engine private interface that will be removed in the future.
          */
         protected set _useVertexOpacity(val: boolean);
         /**
@@ -46423,9 +46428,9 @@
      * @zh 运动轨迹,用于游戏对象的运动轨迹上实现拖尾渐隐效果。
      */
     export class MotionStreak extends UIRenderer {
         static Point: typeof __private._cocos_particle_2d_motion_streak_2d__Point;
-        constructor();
+        protected _fillColorType: __private._cocos_2d_renderer_render_entity__RenderEntityFillColorType;
         /**
          * @en Preview the trailing effect in editor mode.
          * @zh 在编辑器模式下预览拖尾效果。
          */

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant