fix window err when scene changed (#5448)

fix scene-gizmo err when scene changed
This commit is contained in:
JoneLau
2019-09-24 19:16:25 +08:00
committed by pandamicro
parent 01cef26d55
commit 28eb22d64e
2 changed files with 15 additions and 4 deletions
+13 -1
View File
@@ -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) {