2022-06-15 10:56:22 +00:00
|
|
|
|
|
|
|
const { ccclass, property } = cc._decorator;
|
|
|
|
|
|
|
|
@ccclass
|
|
|
|
export default class MultiBatcher extends cc.Component {
|
|
|
|
|
2022-06-17 06:34:45 +00:00
|
|
|
@property(cc.Node)
|
|
|
|
batchBtn: cc.Node = null;
|
|
|
|
|
|
|
|
@property(cc.Node)
|
|
|
|
cancelBtn: cc.Node = null;
|
|
|
|
|
|
|
|
@property(cc.Node)
|
|
|
|
textures: cc.Node = null;
|
|
|
|
|
2022-06-15 10:56:22 +00:00
|
|
|
|
|
|
|
protected onLoad(): void {
|
2022-06-17 06:34:45 +00:00
|
|
|
this.batchBtn.on('click', () => {
|
|
|
|
const batcher = new cc.sp.MultiBatcher();
|
|
|
|
batcher.init();
|
|
|
|
this.textures.children.forEach(v => {
|
|
|
|
const sprite = v.getComponent(cc.Sprite);
|
|
|
|
batcher.requsetMaterial(sprite.spriteFrame.getTexture());
|
|
|
|
sprite.setVertsDirty();
|
|
|
|
});
|
|
|
|
});
|
2022-06-15 10:56:22 +00:00
|
|
|
|
2022-06-17 06:34:45 +00:00
|
|
|
this.cancelBtn.on('click', () => {
|
|
|
|
this.textures.children.forEach(v => {
|
|
|
|
const sprite = v.getComponent(cc.Sprite);
|
|
|
|
sprite.spriteFrame.getTexture().unlinkMaterial();
|
|
|
|
sprite.setMaterial(0, cc.Material.getBuiltinMaterial('2d-sprite'));
|
|
|
|
sprite.setVertsDirty();
|
|
|
|
});
|
|
|
|
});
|
2022-06-15 10:56:22 +00:00
|
|
|
}
|
2022-06-17 06:34:45 +00:00
|
|
|
|
2022-06-15 10:56:22 +00:00
|
|
|
}
|