From 19384c8618acba56a8904c576aa43afdb09400c7 Mon Sep 17 00:00:00 2001 From: ChiaNing Date: Tue, 8 Aug 2023 18:22:03 +0800 Subject: [PATCH] bug fix --- cocos/2d/assembler/label/ttfUtils.ts | 5 +++-- cocos/2d/components/label.ts | 2 ++ cocos/2d/framework/ui-system.ts | 32 ++++++++-------------------- cocos/tiledmap/assembler/simple.ts | 2 +- cocos/ui/scroll-view.ts | 2 +- 5 files changed, 16 insertions(+), 27 deletions(-) diff --git a/cocos/2d/assembler/label/ttfUtils.ts b/cocos/2d/assembler/label/ttfUtils.ts index 3da906055f7..3dcd9c632ab 100644 --- a/cocos/2d/assembler/label/ttfUtils.ts +++ b/cocos/2d/assembler/label/ttfUtils.ts @@ -124,7 +124,7 @@ export const ttfUtils = { }, updateLayoutData (comp: Label): void { - if (comp.layoutDirty) { + if (comp.layoutDirty && comp.assemblerData) { const trans = comp.node._uiProps.uiTransformComp!; const processing = TextProcessing.instance; const style = comp.textStyle; @@ -133,7 +133,7 @@ export const ttfUtils = { style.fontScale = view.getScaleX(); this.updateLayoutProcessingData(style, layout, outputLayoutData, comp, trans); // use canvas in assemblerData // to do to optimize - processing.setCanvasUsed(comp.assemblerData!.canvas, comp.assemblerData!.context); + processing.setCanvasUsed(comp.assemblerData.canvas, comp.assemblerData.context); style.fontFamily = this._updateFontFamily(comp); // TextProcessing @@ -159,6 +159,7 @@ export const ttfUtils = { this._resetDynamicAtlas(comp); + processing.setCanvasUsed(comp.assemblerData!.canvas, comp.assemblerData!.context); processing.generateRenderInfo(false, style, layout, outputLayoutData, outputRenderData, comp.string, this.generateVertexData); const renderData = comp.renderData; diff --git a/cocos/2d/components/label.ts b/cocos/2d/components/label.ts index 6a80880aaa5..00a960a7ffc 100644 --- a/cocos/2d/components/label.ts +++ b/cocos/2d/components/label.ts @@ -836,6 +836,7 @@ export class Label extends UIRenderer { this._applyFontTexture(); } if (this._assembler) { + this._assembler.updateLayoutData(this); this._assembler.updateRenderData(this); } } @@ -914,6 +915,7 @@ export class Label extends UIRenderer { } this.changeMaterialForDefine(); if (this._assembler) { + this._assembler.updateLayoutData(this); this._assembler.updateRenderData(this); } } diff --git a/cocos/2d/framework/ui-system.ts b/cocos/2d/framework/ui-system.ts index 334b99311a4..aa1b39292ba 100644 --- a/cocos/2d/framework/ui-system.ts +++ b/cocos/2d/framework/ui-system.ts @@ -28,18 +28,8 @@ import { uiRendererManager } from './ui-renderer-manager'; import { uiLayoutManager } from './ui-layout-manager'; import { Batcher2D } from '../renderer/batcher-2d'; -class FunctionCallbackInfo { - public callback: AnyFunction; - public target: any; - constructor (callback: AnyFunction, target: any) { - this.callback = callback; - this.target = target; - } -} - export class UISystem extends System { private _batcher: Batcher2D | null = null; - private _extraPartBeforeUpdate: FunctionCallbackInfo[] = []; /** * @en The draw batch manager for 2D UI, for engine internal usage, user do not need to use this. @@ -57,13 +47,20 @@ export class UISystem extends System { director.on(Director.EVENT_AFTER_SCENE_LAUNCH, this.afterSceneLaunch, this); director.on(Director.EVENT_BEFORE_UPDATE, this.beforeUpdate, this); director.on(Director.EVENT_AFTER_UPDATE, this.afterUpdate, this); - director.on(Director.EVENT_BEFORE_DRAW, this.beforeDraw, this); director.on(Director.EVENT_UPDATE_UI, this.tick, this); - director.on(Director.EVENT_BEFORE_COMMIT, this.render, this); + director.on(Director.EVENT_BEFORE_DRAW, this.beforeDraw, this); director.on(Director.EVENT_AFTER_DRAW, this.afterDraw, this); + director.on(Director.EVENT_BEFORE_COMMIT, this.render, this); } public destroy (): void { + director.off(Director.EVENT_AFTER_SCENE_LAUNCH, this.afterSceneLaunch, this); + director.off(Director.EVENT_BEFORE_UPDATE, this.beforeUpdate, this); + director.off(Director.EVENT_AFTER_UPDATE, this.afterUpdate, this); + director.off(Director.EVENT_UPDATE_UI, this.tick, this); + director.off(Director.EVENT_BEFORE_DRAW, this.beforeDraw, this); + director.off(Director.EVENT_AFTER_DRAW, this.afterDraw, this); + director.off(Director.EVENT_BEFORE_COMMIT, this.render, this); if (this._batcher) { this._batcher.destroy(); this._batcher = null; @@ -101,17 +98,6 @@ export class UISystem extends System { } private beforeDraw (): void { - for (let i = 0, length = this._extraPartBeforeUpdate.length; i < length; i++) { - const info = this._extraPartBeforeUpdate[i]; - const callback = info.callback; - const target = info.target; - callback.call(target); - } - this._extraPartBeforeUpdate.length = 0; - } - - public addCallbackToBeforeUpdate (callback: AnyFunction, target: any): void { - this._extraPartBeforeUpdate.push(new FunctionCallbackInfo(callback, target)); } } diff --git a/cocos/tiledmap/assembler/simple.ts b/cocos/tiledmap/assembler/simple.ts index 41a9a4b2cb3..e0ed4948781 100644 --- a/cocos/tiledmap/assembler/simple.ts +++ b/cocos/tiledmap/assembler/simple.ts @@ -73,7 +73,7 @@ export const simple: IAssembler = { const device = director.root!.device; _accessor = new StaticVBAccessor(device, vfmtPosUvColor, this.vCount); //batcher.registerBufferAccessor(Number.parseInt('TILED-MAP', 36), _accessor); - director.on(Director.EVENT_BEFORE_DRAW, () => { // 额外改造,解除事件依赖,每帧重置 + director.on(Director.EVENT_AFTER_UPDATE, () => { _accessor.reset(); }); } diff --git a/cocos/ui/scroll-view.ts b/cocos/ui/scroll-view.ts index 3d455b775ac..cadea746bc6 100644 --- a/cocos/ui/scroll-view.ts +++ b/cocos/ui/scroll-view.ts @@ -974,7 +974,7 @@ export class ScrollView extends ViewGroup { // Because widget component will adjust content position and scrollView position is correct after visit // So this event could make sure the content is on the correct position after loading. if (this._content) { - uiSystem.addCallbackToBeforeUpdate(this._adjustContentOutOfBoundary, this); + director.once(Director.EVENT_AFTER_UPDATE, this._adjustContentOutOfBoundary, this); } }