persist node change scene event

This commit is contained in:
Yun Hsiao Wu
2019-01-29 17:06:43 +08:00
parent 8be21ee817
commit 6dfc30de74
6 changed files with 36 additions and 6 deletions
+7 -4
View File
@@ -285,19 +285,22 @@ export class CameraComponent extends Component {
}
public onLoad () {
this.node.on(cc.Node.SCENE_CHANGED_FOR_PERSISTS, () => {
if (this._camera) { this._getRenderScene().destroyCamera(this._camera); this._camera = null; }
});
}
public onEnable () {
this._camera = this._getRenderScene().createCamera(this);
if (!this._camera) { this._camera = this._getRenderScene().createCamera(this); }
this._camera.enabled = true;
}
public onDisable () {
if (this._camera) { this._getRenderScene().destroyCamera(this._camera); }
if (this._camera) { this._camera.enabled = false; }
}
public onDestroy () {
if (this._camera) { this._getRenderScene().destroyCamera(this._camera); this._camera = null; }
}
public screenPointToRay (x: number, y: number, out?: ray) {
+9 -1
View File
@@ -250,6 +250,10 @@ export default class LightComponent extends Component {
}
}
public onLoad () {
this.node.on(cc.Node.SCENE_CHANGED_FOR_PERSISTS, () => this._destroyLight());
}
public onEnable () {
this._createLight();
if (this._light) { this._light.enabled = true; return; }
@@ -283,8 +287,12 @@ export default class LightComponent extends Component {
console.warn(`illegal light type ${this._type}`);
return;
}
if (!this._light) { console.warn('we don\'t support this many lights in forward pipeline.'); }
if (!this._light) {
console.warn('we don\'t support this many lights in forward pipeline.');
return;
}
this.color = this._color;
this._light.enabled = this.enabledInHierarchy;
}
protected _destroyLight () {
+7 -1
View File
@@ -163,7 +163,12 @@ export class ModelComponent extends RenderableComponent {
}
public onLoad () {
super.onLoad();
this.node.on(cc.Node.SCENE_CHANGED_FOR_PERSISTS, () => {
if (this._model) {
this._getRenderScene().destroyModel(this._model);
this._model = null;
}
});
}
public onEnable () {
@@ -184,6 +189,7 @@ export class ModelComponent extends RenderableComponent {
public onDestroy () {
if (this._model) {
this._getRenderScene().destroyModel(this._model);
this._model = null;
}
}
+1
View File
@@ -417,6 +417,7 @@ class Director extends EventTarget {
else {
node.parent = scene;
}
node.emit(cc.Node.SCENE_CHANGED_FOR_PERSISTS);
}
CC_BUILD && CC_DEBUG && console.timeEnd('AttachPersist');
+9
View File
@@ -35,6 +35,7 @@ export class Camera {
private _scene: RenderScene;
private _name: string;
private _enabled: boolean = false;
private _proj: CameraProjection;
private _isWindowSize: boolean = true;
private _width: number;
@@ -135,6 +136,14 @@ export class Camera {
this._frustum.update(this._matViewProj, this._matViewProjInv);
}
set enabled (val) {
this._enabled = val;
}
get enabled () {
return this._enabled;
}
get view (): RenderView {
return this._view;
}
+3
View File
@@ -5,6 +5,9 @@ export enum EventType {
POSITION_PART = 'position-part',
ROTATION_PART = 'rotation-part',
SCALE_PART = 'scale-part',
SCENE_CHANGED_FOR_PERSISTS = 'scene-changed-for-persists',
TOUCH_START = 'touch-start',
TOUCH_MOVE = 'touch-move',
TOUCH_END = 'touch-end',