diff --git a/packages/ui/src/Utils.ts b/packages/ui/src/Utils.ts index caa8f6d019..a788fe8968 100644 --- a/packages/ui/src/Utils.ts +++ b/packages/ui/src/Utils.ts @@ -35,7 +35,7 @@ export class Utils { listeningEntities.length = 0; } - static getCanvasInParents(entity: Entity, root?: Entity): UICanvas { + static getRootCanvasInParents(entity: Entity, root?: Entity): UICanvas { entity = entity.parent; let rootCanvas: UICanvas = null; while (entity && entity !== root) { diff --git a/packages/ui/src/component/UICanvas.ts b/packages/ui/src/component/UICanvas.ts index 4aad1202c2..bc297e7704 100644 --- a/packages/ui/src/component/UICanvas.ts +++ b/packages/ui/src/component/UICanvas.ts @@ -279,7 +279,7 @@ export class UICanvas extends Component implements IElement { const entity = this.entity; // @ts-ignore entity._dispatchModify(EntityUIModifyFlags.CanvasEnableInScene, this); - const rootCanvas = Utils.getCanvasInParents(entity); + const rootCanvas = Utils.getRootCanvasInParents(entity); if (rootCanvas) { this._setIsRootCanvas(false); Utils._registerElementToCanvas(this, null, rootCanvas); @@ -302,8 +302,7 @@ export class UICanvas extends Component implements IElement { _canvasListener(flag: number, param: any): void { if (this._isRootCanvas) { if (flag === EntityModifyFlags.Parent) { - const entity = this.entity; - const rootCanvas = Utils.getCanvasInParents(entity); + const rootCanvas = Utils.getRootCanvasInParents(this.entity); if (rootCanvas) { this._setIsRootCanvas(false); Utils._registerElementToCanvas(this, null, rootCanvas); @@ -317,7 +316,7 @@ export class UICanvas extends Component implements IElement { } } else { if (flag === EntityModifyFlags.Parent) { - const rootCanvas = Utils.getCanvasInParents(this.entity); + const rootCanvas = Utils.getRootCanvasInParents(this.entity); if (rootCanvas) { this._setIsRootCanvas(false); Utils._registerElementToCanvas(this, this._canvas, rootCanvas); @@ -538,7 +537,7 @@ export class UICanvas extends Component implements IElement { const componentType = (element as unknown as Component)._componentType; if (componentType === ComponentType.UICanvas) { const canvas = element as unknown as UICanvas; - const rootCanvas = Utils.getCanvasInParents(element.entity, root); + const rootCanvas = Utils.getRootCanvasInParents(element.entity, root); if (rootCanvas) { canvas._setIsRootCanvas(false); Utils._registerElementToCanvas(canvas, this, rootCanvas); diff --git a/packages/ui/src/component/UIGroup.ts b/packages/ui/src/component/UIGroup.ts index 05800c98f5..410ef2ce63 100644 --- a/packages/ui/src/component/UIGroup.ts +++ b/packages/ui/src/component/UIGroup.ts @@ -151,7 +151,7 @@ export class UIGroup extends Component implements IGroupAble { */ _getCanvas(): UICanvas { if (this._isCanvasDirty) { - const curCanvas = Utils.getCanvasInParents(this.entity); + const curCanvas = Utils.getRootCanvasInParents(this.entity); Utils._registerElementToCanvas(this, this._canvas, curCanvas); Utils._registerElementToCanvasListener(this, curCanvas); this._isCanvasDirty = false; diff --git a/packages/ui/src/component/UIRenderer.ts b/packages/ui/src/component/UIRenderer.ts index da08b8c7db..4fdd4d43dc 100644 --- a/packages/ui/src/component/UIRenderer.ts +++ b/packages/ui/src/component/UIRenderer.ts @@ -172,7 +172,7 @@ export abstract class UIRenderer extends Renderer implements IGraphics { */ _getCanvas(): UICanvas { if (this._isCanvasDirty) { - const curCanvas = Utils.getCanvasInParents(this.entity); + const curCanvas = Utils.getRootCanvasInParents(this.entity); Utils._registerElementToCanvas(this, this._canvas, curCanvas); Utils._registerElementToCanvasListener(this, curCanvas); this._isCanvasDirty = false; diff --git a/packages/ui/src/component/advanced/Label.ts b/packages/ui/src/component/advanced/Label.ts index 1d154e7fbc..19a21055d3 100644 --- a/packages/ui/src/component/advanced/Label.ts +++ b/packages/ui/src/component/advanced/Label.ts @@ -210,7 +210,6 @@ export class Label extends UIRenderer implements ITextRenderer { // @ts-ignore this.setMaterial(engine._basicResources.textDefaultMaterial); } - z; /** * @internal diff --git a/packages/ui/src/component/interactive/UIInteractive.ts b/packages/ui/src/component/interactive/UIInteractive.ts index bcf8dbca2e..d420c158d7 100644 --- a/packages/ui/src/component/interactive/UIInteractive.ts +++ b/packages/ui/src/component/interactive/UIInteractive.ts @@ -154,7 +154,7 @@ export class UIInteractive extends Script implements IGroupAble { */ _getCanvas(): UICanvas { if (this._isCanvasDirty) { - const curCanvas = Utils.getCanvasInParents(this.entity); + const curCanvas = Utils.getRootCanvasInParents(this.entity); Utils._registerElementToCanvas(this, this._canvas, curCanvas); Utils._registerElementToCanvasListener(this, curCanvas); this._isCanvasDirty = false; diff --git a/packages/ui/src/input/UIPointerEventEmitter.ts b/packages/ui/src/input/UIPointerEventEmitter.ts index 88f92cbd02..4764557728 100644 --- a/packages/ui/src/input/UIPointerEventEmitter.ts +++ b/packages/ui/src/input/UIPointerEventEmitter.ts @@ -86,7 +86,6 @@ export class UIPointerEventEmitter extends PointerEventEmitter { } } } - return null; } override processDrag(pointer: Pointer): void {