mirror of
https://gitee.com/ruanwujing/green-pack-cocos
synced 2025-10-09 08:36:33 +00:00
圆角矩形grayscale修复
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import { _decorator, ccenum, CCFloat, CCInteger, cclegacy, Component, InstanceMaterialType, Material, Node, NodeEventType, RenderTexture, serializeTag, Sprite, SpriteAtlas, SpriteFrame, UIRenderer, Vec2} from 'cc';
|
||||
import { _decorator, CCBoolean, CCFloat, CCInteger, cclegacy, InstanceMaterialType, Material, Node, NodeEventType, RenderTexture, Sprite, SpriteAtlas, SpriteFrame, UIRenderer} from 'cc';
|
||||
import { BUILD, EDITOR } from 'cc/env';
|
||||
import { GPRoundBoxAssembler } from './GPRoundBoxAssembler';
|
||||
|
||||
const { ccclass, property,type} = _decorator;
|
||||
|
||||
enum EventType {
|
||||
SPRITE_FRAME_CHANGED = 'spriteframe-changed',
|
||||
}
|
||||
@@ -26,6 +27,27 @@ export class GPRoundBoxSprite extends UIRenderer {
|
||||
this._applySpriteSize();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @en Grayscale mode.
|
||||
* @zh 是否以灰度模式渲染。
|
||||
*/
|
||||
|
||||
@property({serializable:true})
|
||||
protected _useGrayscale = false;
|
||||
|
||||
@property({type:CCBoolean})
|
||||
get grayscale (): boolean {
|
||||
return this._useGrayscale;
|
||||
}
|
||||
set grayscale (value) {
|
||||
if (this._useGrayscale === value) {
|
||||
return;
|
||||
}
|
||||
this._useGrayscale = value;
|
||||
this.changeMaterialForDefine();
|
||||
this["updateMaterial"]();
|
||||
}
|
||||
|
||||
// 图集
|
||||
@property({serializable:true})
|
||||
protected _atlas: SpriteAtlas | null = null;
|
||||
@@ -188,8 +210,12 @@ export class GPRoundBoxSprite extends UIRenderer {
|
||||
value = (format === cclegacy.TextureBase.PixelFormat.RGBA_ETC1 || format === cclegacy.TextureBase.PixelFormat.RGB_A_PVRTC_4BPPV1 || format === cclegacy.TextureBase.PixelFormat.RGB_A_PVRTC_2BPPV1);
|
||||
}
|
||||
|
||||
if (value) {
|
||||
if (value && this.grayscale) {
|
||||
this._instanceMaterialType = InstanceMaterialType.USE_ALPHA_SEPARATED_AND_GRAY;
|
||||
} else if (value) {
|
||||
this._instanceMaterialType = InstanceMaterialType.USE_ALPHA_SEPARATED;
|
||||
} else if (this.grayscale) {
|
||||
this._instanceMaterialType = InstanceMaterialType.GRAYSCALE;
|
||||
} else {
|
||||
this._instanceMaterialType = InstanceMaterialType.ADD_COLOR_AND_TEXTURE;
|
||||
}
|
||||
@@ -333,4 +359,4 @@ export class GPRoundBoxSprite extends UIRenderer {
|
||||
this._applySpriteSize();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user