fix ui performance (#4511)

1. label ui drawcall too much high
2. switch visibility when parent changed
This commit is contained in:
JoneLau
2019-05-30 11:33:38 +08:00
committed by pandamicro
parent eee5fbcd89
commit d2f79a0fab
2 changed files with 38 additions and 13 deletions
+36 -7
View File
@@ -1,6 +1,8 @@
import { Component } from '../../../components';
import { SystemEventType } from '../../../core';
import { ccclass, executeInEditMode, executionOrder, property } from '../../../core/data/class-decorator';
import { UI } from '../../../renderer/ui/ui';
import { Node } from '../../../scene-graph';
import { CanvasComponent } from './canvas-component';
/**
@@ -42,7 +44,35 @@ export class UIComponent extends Component {
protected _visibility = -1;
private _lastParent: Node | null = null;
public onEnable () {
this._lastParent = this.node.parent;
this._updateVisibility();
if (this._lastParent) {
this.node.on(SystemEventType.CHILD_REMOVED, this._parentChanged, this);
}
}
public onDisable () {
this._cancelEventFromParent();
}
public updateAssembler (render: UI) {
}
public postUpdateAssembler (render: UI) {
}
private _parentChanged (node: Node){
if (node === this.node) {
this._updateVisibility();
this._cancelEventFromParent();
this._lastParent = this.node.parent;
}
}
private _updateVisibility () {
let parent = this.node;
// 获取被渲染相机的 visibility
while (parent) {
@@ -59,13 +89,12 @@ export class UIComponent extends Component {
}
}
public onDisable () {
private _cancelEventFromParent (){
if (this._lastParent) {
this._lastParent.off(SystemEventType.CHILD_REMOVED, this._parentChanged, this);
this._lastParent = null;
}
this._visibility = -1;
}
public updateAssembler (render: UI) {
}
public postUpdateAssembler (render: UI) {
}
}
@@ -234,7 +234,7 @@ export class UIRenderComponent extends UIComponent {
public onEnable () {
super.onEnable();
this.node.on(SystemEventType.ANCHOR_CHANGED, this._nodeStateChange, this);
this.node.on(SystemEventType.TRANSFORM_CHANGED, this._nodeStateChange, this);
// this.node.on(SystemEventType.TRANSFORM_CHANGED, this._nodeStateChange, this);
this.node.on(SystemEventType.SIZE_CHANGED, this._nodeStateChange, this);
// if (this.node._renderComponent) {
// this.node._renderComponent.enabled = false;
@@ -249,7 +249,7 @@ export class UIRenderComponent extends UIComponent {
// this.node._renderComponent = null;
// this.disableRender();
this.node.off(SystemEventType.ANCHOR_CHANGED, this._nodeStateChange, this);
this.node.off(SystemEventType.TRANSFORM_CHANGED, this._nodeStateChange, this);
// this.node.off(SystemEventType.TRANSFORM_CHANGED, this._nodeStateChange, this);
this.node.off(SystemEventType.SIZE_CHANGED, this._nodeStateChange, this);
}
@@ -328,10 +328,6 @@ export class UIRenderComponent extends UIComponent {
return false;
}
if (this.node.hasChanged && !this._renderDataDirty) {
this.markForUpdateRenderData();
}
this._checkAndUpdateRenderData();
return true;
}