mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-01 07:42:38 +08:00
fix ui model bug (#4512)
This commit is contained in:
@@ -193,6 +193,7 @@ export class ModelComponent extends RenderableComponent {
|
||||
public recreateModel () {
|
||||
if (this._model) {
|
||||
this._model.destroy();
|
||||
this._model.scene.destroyModel(this._model);
|
||||
this._model = null;
|
||||
}
|
||||
this._updateModels();
|
||||
|
||||
@@ -172,11 +172,11 @@ export class CanvasComponent extends Component {
|
||||
}
|
||||
|
||||
public __preload () {
|
||||
const cameraNode = new cc.Node('UICamera' + this.node.name);
|
||||
const cameraNode = new cc.Node('UICamera_' + this.node.name);
|
||||
cameraNode.setPosition(0, 0, 900);
|
||||
if (!CC_EDITOR) {
|
||||
this._camera = cc.director.root.ui.renderScene.createCamera({
|
||||
name: 'ui' + this.node.name,
|
||||
name: 'ui_' + this.node.name,
|
||||
node: cameraNode,
|
||||
projection: cc.CameraComponent.ProjectionType.ORTHO,
|
||||
targetDisplay: 0,
|
||||
|
||||
@@ -20,11 +20,11 @@ export class DebugCanvasComponent extends CanvasComponent {
|
||||
}
|
||||
|
||||
public __preload (){
|
||||
const cameraNode = new cc.Node('UICamera');
|
||||
const cameraNode = new cc.Node('UICamera_Debug');
|
||||
cameraNode.setPosition(0, 0, 1000);
|
||||
|
||||
this._camera = cc.director.root.ui.renderScene.createCamera({
|
||||
name: 'ui',
|
||||
name: 'ui_Debug',
|
||||
node: cameraNode,
|
||||
projection: cc.CameraComponent.ProjectionType.ORTHO,
|
||||
targetDisplay: 0,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Component } from '../../../components';
|
||||
import { ccclass, executeInEditMode, executionOrder, property } from '../../../core/data/class-decorator';
|
||||
import { UI } from '../../../renderer/ui/ui';
|
||||
import { CanvasComponent } from './canvas-component';
|
||||
|
||||
/**
|
||||
* @zh
|
||||
@@ -41,6 +42,27 @@ export class UIComponent extends Component {
|
||||
|
||||
protected _visibility = -1;
|
||||
|
||||
public onEnable () {
|
||||
let parent = this.node;
|
||||
// 获取被渲染相机的 visibility
|
||||
while (parent) {
|
||||
if (parent) {
|
||||
const canvasComp = parent.getComponent(CanvasComponent);
|
||||
if (canvasComp) {
|
||||
this._visibility = canvasComp.visibility;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
parent = parent.parent;
|
||||
}
|
||||
}
|
||||
|
||||
public onDisable () {
|
||||
this._visibility = -1;
|
||||
}
|
||||
|
||||
public updateAssembler (render: UI) {
|
||||
}
|
||||
|
||||
|
||||
@@ -26,10 +26,6 @@ export class UIModelComponent extends UIComponent {
|
||||
this._modelComponent.recreateModel();
|
||||
}
|
||||
|
||||
public onEnable () {
|
||||
this._fitUIRenderQueue();
|
||||
}
|
||||
|
||||
public onDestroy () {
|
||||
this._modelComponent = this.getComponent(cc.RenderableComponent) as RenderableComponent;
|
||||
(this._modelComponent as any)._sceneGetter = null;
|
||||
@@ -56,6 +52,9 @@ export class UIModelComponent extends UIComponent {
|
||||
const matNum = this._modelComponent.sharedMaterials.length;
|
||||
for (let i = 0; i < matNum; i++) {
|
||||
const material = this._modelComponent.getMaterial(i, CC_EDITOR)! as any;
|
||||
if (material == null) {
|
||||
continue;
|
||||
}
|
||||
const passes = material.passes;
|
||||
const ea = material.effectAsset!;
|
||||
const techIdx = material.technique;
|
||||
@@ -74,7 +73,11 @@ export class UIModelComponent extends UIComponent {
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < matNum; i++) {
|
||||
const passes = this._modelComponent.getMaterial(i, CC_EDITOR)!.passes;
|
||||
const material = this._modelComponent.getMaterial(i, CC_EDITOR)!;
|
||||
if (material == null) {
|
||||
continue;
|
||||
}
|
||||
const passes = material.passes;
|
||||
for (const p of passes as any[]) {
|
||||
p._priority = RenderPriority.MAX - 11;
|
||||
}
|
||||
|
||||
@@ -232,21 +232,7 @@ export class UIRenderComponent extends UIComponent {
|
||||
}
|
||||
|
||||
public onEnable () {
|
||||
let parent = this.node;
|
||||
// 获取被渲染相机的 visibility
|
||||
while (parent) {
|
||||
if (parent) {
|
||||
const canvasComp = parent.getComponent(CanvasComponent);
|
||||
if (canvasComp) {
|
||||
this._visibility = canvasComp.visibility;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
parent = parent.parent;
|
||||
}
|
||||
|
||||
super.onEnable();
|
||||
this.node.on(SystemEventType.ANCHOR_CHANGED, this._nodeStateChange, this);
|
||||
this.node.on(SystemEventType.TRANSFORM_CHANGED, this._nodeStateChange, this);
|
||||
this.node.on(SystemEventType.SIZE_CHANGED, this._nodeStateChange, this);
|
||||
@@ -259,7 +245,7 @@ export class UIRenderComponent extends UIComponent {
|
||||
}
|
||||
|
||||
public onDisable () {
|
||||
this._visibility = -1;
|
||||
super.onDisable();
|
||||
// this.node._renderComponent = null;
|
||||
// this.disableRender();
|
||||
this.node.off(SystemEventType.ANCHOR_CHANGED, this._nodeStateChange, this);
|
||||
|
||||
Reference in New Issue
Block a user