Skip to content

Commit

Permalink
Fix editor preview, canvas component calculates Camera invalidly (#17856
Browse files Browse the repository at this point in the history
)
  • Loading branch information
knoxHuang authored Nov 18, 2024
1 parent 8ffae0e commit eac044e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions cocos/2d/framework/canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import { ccclass, help, disallowMultiple, executeInEditMode,
executionOrder, menu, tooltip, type, serializable } from 'cc.decorator';
import { EDITOR } from 'internal:constants';
import { EDITOR_NOT_IN_PREVIEW } from 'internal:constants';
import { Camera, CameraEvent } from '../../misc/camera-component';
import { Widget } from '../../ui/widget';
import { Vec3, screen, Enum, cclegacy, visibleRect } from '../../core';
Expand Down Expand Up @@ -132,7 +132,7 @@ export class Canvas extends RenderRoot2D {
super();
this._thisOnCameraResized = this._onResizeCamera.bind(this);

if (EDITOR) {
if (EDITOR_NOT_IN_PREVIEW) {
this.fitDesignResolution_EDITOR = (): void => {
// TODO: support paddings of locked widget
this.node.getPosition(this._pos);
Expand Down Expand Up @@ -175,11 +175,11 @@ export class Canvas extends RenderRoot2D {
const widget = this.getComponent('cc.Widget') as unknown as Widget;
if (widget) {
widget.updateAlignment();
} else if (EDITOR) {
} else if (EDITOR_NOT_IN_PREVIEW) {
this.fitDesignResolution_EDITOR!();
}

if (!EDITOR) {
if (!EDITOR_NOT_IN_PREVIEW) {
if (this._cameraComponent) {
this._cameraComponent._createCamera();
this._cameraComponent.node.on(CameraEvent.TARGET_TEXTURE_CHANGE, this._thisOnCameraResized);
Expand All @@ -188,7 +188,7 @@ export class Canvas extends RenderRoot2D {

this._onResizeCamera();

if (EDITOR) {
if (EDITOR_NOT_IN_PREVIEW) {
// In Editor can not edit these attrs.
// (Position in Node, contentSize in uiTransform)
// (anchor in uiTransform, but it can edit, this is different from cocos creator)
Expand All @@ -202,7 +202,7 @@ export class Canvas extends RenderRoot2D {

public onEnable (): void {
super.onEnable();
if (!EDITOR && this._cameraComponent) {
if (!EDITOR_NOT_IN_PREVIEW && this._cameraComponent) {
this._cameraComponent.node.on(CameraEvent.TARGET_TEXTURE_CHANGE, this._thisOnCameraResized);
}
}
Expand Down

0 comments on commit eac044e

Please sign in to comment.