fix tiled bug for GPU Mode (#9456)

This commit is contained in:
ChiaNing
2021-10-11 13:46:19 +08:00
committed by GitHub
parent 8d916b9816
commit f54c8f5844
2 changed files with 29 additions and 5 deletions
+20 -5
View File
@@ -29,7 +29,7 @@
* @module ui
*/
import { ccclass, help, executionOrder, menu, tooltip, displayOrder, type, range, editable, serializable } from 'cc.decorator';
import { ccclass, help, executionOrder, menu, tooltip, displayOrder, type, range, editable, serializable, override, displayName } from 'cc.decorator';
import { EDITOR, UI_GPU_DRIVEN } from 'internal:constants';
import { SpriteAtlas } from '../assets/sprite-atlas';
import { SpriteFrame } from '../assets/sprite-frame';
@@ -179,6 +179,25 @@ enum EventType {
@executionOrder(110)
@menu('2D/Sprite')
export class Sprite extends Renderable2D {
/**
* @en The customMaterial
* @zh 用户自定材质
*/
@type(Material)
@displayOrder(0)
@displayName('CustomMaterial')
@override
get customMaterial () {
return this._customMaterial;
}
set customMaterial (val) {
this._customMaterial = val;
this.updateMaterial();
if (UI_GPU_DRIVEN && !val) {
this._canDrawByFourVertex = true;
}
}
/**
* @en
* The sprite atlas where the sprite is.
@@ -570,10 +589,6 @@ export class Sprite extends Renderable2D {
}
protected _updateBuiltinMaterial () {
// macro.UI_GPU_DRIVEN
if (UI_GPU_DRIVEN) {
this._canDrawByFourVertex = true;
}
let mat = super._updateBuiltinMaterial();
if (this.spriteFrame && this.spriteFrame.texture instanceof RenderTexture) {
const defines = { SAMPLE_FROM_RT: true, ...mat.passes[0].defines };
+9
View File
@@ -30,6 +30,7 @@
*/
import { ccclass, help, type, requireComponent } from 'cc.decorator';
import { UI_GPU_DRIVEN } from 'internal:constants';
import { Component } from '../core/components';
import { Sprite } from '../2d/components/sprite';
import { Label } from '../2d/components/label';
@@ -274,6 +275,10 @@ export class TiledObjectGroup extends Component {
label.horizontalAlign = object.halign;
label.verticalAlign = object.valign;
label.fontSize = object.pixelsize;
if (UI_GPU_DRIVEN) {
// @ts-expect-error HACK for Tiled
label._canDrawByFourVertex = false;
}
textTransComp.setContentSize(object.width, object.height);
} else if (objType === TMXObjectType.IMAGE) {
@@ -365,6 +370,10 @@ export class TiledObjectGroup extends Component {
spf.rotated = grid._rotated!;
spf.rect = grid._rect!;
sprite.spriteFrame = spf;
if (UI_GPU_DRIVEN) {
// @ts-expect-error HACK for Tiled
sprite._canDrawByFourVertex = false;
}
imgTrans.setContentSize(object.width, object.height);