mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 07:42:38 +08:00
fix ui performance (#4511)
1. label ui drawcall too much high 2. switch visibility when parent changed
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user