Skip to content

Commit

Permalink
feat: update code
Browse files Browse the repository at this point in the history
  • Loading branch information
cptbtptpbcptdtptp committed Dec 16, 2024
1 parent 9f71641 commit 4d6b453
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/ui/src/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 4 additions & 5 deletions packages/ui/src/component/UICanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/component/UIGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/component/UIRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion packages/ui/src/component/advanced/Label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ export class Label extends UIRenderer implements ITextRenderer {
// @ts-ignore
this.setMaterial(engine._basicResources.textDefaultMaterial);
}
z;

/**
* @internal
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/component/interactive/UIInteractive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion packages/ui/src/input/UIPointerEventEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export class UIPointerEventEmitter extends PointerEventEmitter {
}
}
}
return null;
}

override processDrag(pointer: Pointer): void {
Expand Down

0 comments on commit 4d6b453

Please sign in to comment.