mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 08:02:39 +08:00
fix window err when scene changed (#5448)
fix scene-gizmo err when scene changed
This commit is contained in:
@@ -111,6 +111,7 @@ export class CameraComponent extends Component {
|
||||
protected _targetTexture: RenderTexture | null = null;
|
||||
|
||||
protected _camera: Camera | null = null;
|
||||
protected _inEditorMode = false;
|
||||
|
||||
/**
|
||||
* @en The projection type of the camera
|
||||
@@ -336,6 +337,17 @@ export class CameraComponent extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
get inEditorMode() {
|
||||
return this._inEditorMode;
|
||||
}
|
||||
|
||||
set inEditorMode(value) {
|
||||
this._inEditorMode = value;
|
||||
if (this._camera) {
|
||||
this._camera.changeTargetWindow(value ? cc.director.root && cc.director.root.mainWindow : cc.director.root && cc.director.root.tempWindow);
|
||||
}
|
||||
}
|
||||
|
||||
public onLoad () {
|
||||
cc.director.on(cc.Director.EVENT_AFTER_SCENE_LAUNCH, this.onSceneChanged, this);
|
||||
}
|
||||
@@ -387,7 +399,7 @@ export class CameraComponent extends Component {
|
||||
name: this.node.name,
|
||||
node: this.node,
|
||||
projection: this._projection,
|
||||
window: cc.director.root && cc.director.root.tempWindow,
|
||||
window: this._inEditorMode ? cc.director.root && cc.director.root.mainWindow : cc.director.root && cc.director.root.tempWindow,
|
||||
priority: this._priority,
|
||||
});
|
||||
|
||||
|
||||
@@ -104,6 +104,8 @@ export class EditorCameraComponent extends CameraComponent {
|
||||
|
||||
public onLoad () {
|
||||
super.onLoad();
|
||||
|
||||
this._inEditorMode = true;
|
||||
}
|
||||
|
||||
public onEnable () {
|
||||
@@ -125,9 +127,6 @@ export class EditorCameraComponent extends CameraComponent {
|
||||
protected _createCamera () {
|
||||
const priorCamera = this._camera;
|
||||
super._createCamera();
|
||||
if(this._camera){
|
||||
this._camera.changeTargetWindow(cc.director.root.mainWindow);
|
||||
}
|
||||
|
||||
if (this._camera !== priorCamera && this._camera) {
|
||||
if (this._uiEditorCamera) {
|
||||
|
||||
Reference in New Issue
Block a user