mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 07:42:38 +08:00
fix render-twice (#4294)
This commit is contained in:
@@ -43,7 +43,7 @@ const _worldPos = new Vec3();
|
||||
* @extends Component
|
||||
*/
|
||||
@ccclass('cc.CanvasComponent')
|
||||
@executionOrder(100)
|
||||
@executionOrder(110)
|
||||
@requireComponent(UITransformComponent)
|
||||
@menu('UI/Canvas')
|
||||
@executeInEditMode
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import { Vec3 } from '../../../core/value-types';
|
||||
import { GFXClearFlag } from '../../../gfx/define';
|
||||
import { CameraComponent } from '../../framework';
|
||||
import { CanvasComponent } from './canvas-component';
|
||||
|
||||
const _worldPos = new Vec3();
|
||||
@@ -7,6 +9,34 @@ export class DebugCanvasComponent extends CanvasComponent{
|
||||
super();
|
||||
this._thisOnResized = this.alignWithScreen.bind(this);
|
||||
}
|
||||
public __preload (){
|
||||
const cameraNode = new cc.Node('UICamera');
|
||||
cameraNode.setPosition(0, 0, 1000);
|
||||
|
||||
this._camera = cc.director.root.ui.renderScene.createCamera({
|
||||
name: 'ui',
|
||||
node: cameraNode,
|
||||
projection: CameraComponent.ProjectionType.ORTHO,
|
||||
targetDisplay: 0,
|
||||
priority: this._priority,
|
||||
isUI: true,
|
||||
flows: ['UIFlow'],
|
||||
});
|
||||
|
||||
this._camera!.fov = 45;
|
||||
this._camera!.clearFlag = GFXClearFlag.COLOR | GFXClearFlag.DEPTH | GFXClearFlag.STENCIL;
|
||||
|
||||
const device = cc.director.root.device;
|
||||
this._camera!.resize(device.width, device.height);
|
||||
|
||||
cc.view.on('design-resolution-changed', this._thisOnResized);
|
||||
|
||||
this.alignWithScreen();
|
||||
|
||||
if (cc.director.root && cc.director.root.ui) {
|
||||
cc.director.root.ui.debugScreen = this;
|
||||
}
|
||||
}
|
||||
|
||||
// don't remove
|
||||
public onEnable (){
|
||||
@@ -16,12 +46,15 @@ export class DebugCanvasComponent extends CanvasComponent{
|
||||
public onDisable (){
|
||||
}
|
||||
|
||||
public onDestroy (){
|
||||
if (CC_EDITOR) {
|
||||
cc.director.off(cc.Director.EVENT_AFTER_UPDATE, this.alignWithScreen, this);
|
||||
public onDestroy () {
|
||||
if (this._camera) {
|
||||
this._getRenderScene().destroyCamera(this._camera);
|
||||
}
|
||||
|
||||
cc.view.off('design-resolution-changed', this._thisOnResized);
|
||||
if (cc.director.root && cc.director.root.ui) {
|
||||
cc.director.root.ui.debugScreen = null;
|
||||
}
|
||||
}
|
||||
|
||||
public alignWithScreen (){
|
||||
|
||||
@@ -172,7 +172,6 @@ function generateNode () {
|
||||
_rootNode = new Node('PROFILER-NODE');
|
||||
_rootNode.addComponent(UITransformComponent);
|
||||
const screen = _rootNode.addComponent(DebugCanvasComponent);
|
||||
cc.director.root.ui.debugScreen = screen;
|
||||
cc.game.addPersistRootNode(_rootNode);
|
||||
// const camera = cc.director.root.
|
||||
|
||||
|
||||
@@ -80,6 +80,9 @@ export class UI {
|
||||
|
||||
set debugScreen (value){
|
||||
this._debugScreen = value;
|
||||
if (this._debugScreen && this._debugScreen.camera ) {
|
||||
this._debugScreen.camera.view.visibility = this._screens.length + 1;
|
||||
}
|
||||
}
|
||||
|
||||
public device: GFXDevice;
|
||||
@@ -186,6 +189,10 @@ export class UI {
|
||||
comp.camera.view.visibility = this._screens.length;
|
||||
}
|
||||
|
||||
if (this._debugScreen && this._debugScreen.camera) {
|
||||
this._debugScreen.camera.view.visibility = this._screens.length + 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public getScreen (visibility: number) {
|
||||
@@ -197,6 +204,10 @@ export class UI {
|
||||
}
|
||||
}
|
||||
|
||||
if (this._debugScreen && this._debugScreen.camera && this._debugScreen.camera.visibility === visibility) {
|
||||
return this._debugScreen;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -207,6 +218,9 @@ export class UI {
|
||||
}
|
||||
|
||||
this._screens.splice(idx, 1);
|
||||
if (this._debugScreen && this._debugScreen.camera ) {
|
||||
this._debugScreen.camera.view.visibility = this._screens.length + 1;
|
||||
}
|
||||
|
||||
let camera: Camera | null;
|
||||
for (let i = idx; i < this._screens.length;) {
|
||||
|
||||
Reference in New Issue
Block a user