[engine] 修复 Spine 动态合图未判断 attachment 是否存在 region 对象报错的问题

This commit is contained in:
SmallMain 2022-07-12 11:44:01 +08:00
parent a2404dae86
commit 5c72a79a02

View File

@ -325,41 +325,43 @@ export default class SpineAssembler extends Assembler {
} }
} else { } else {
const region = attachment.region; const region = attachment.region;
const alreadyInAtlas = !!region._original; if (region) {
const alreadyInAtlas = !!region._original;
if (alreadyInAtlas) { if (alreadyInAtlas) {
// 可能出现多个 attachment 共用同一个 region // 可能出现多个 attachment 共用同一个 region
if (_packedRegions.includes(region)) { if (_packedRegions.includes(region)) {
this.updatePackedAttachment(attachment, false); this.updatePackedAttachment(attachment, false);
} }
} else if (region.texture && region.texture._texture.packable) { } else if (region.texture && region.texture._texture.packable) {
if (region._spriteFrame) { if (region._spriteFrame) {
const spriteFrame = region._spriteFrame; const spriteFrame = region._spriteFrame;
region._spriteFrame = null; region._spriteFrame = null;
spriteFrame.destroy(); spriteFrame.destroy();
} }
_tmpRegionData.initWithAttachment(attachment); _tmpRegionData.initWithAttachment(attachment);
const frame = _tmpRegionData.toSpriteFrame(); const frame = _tmpRegionData.toSpriteFrame();
const packedFrame = cc.dynamicAtlasManager.insertSpriteFrame(frame); const packedFrame = cc.dynamicAtlasManager.insertSpriteFrame(frame);
if (packedFrame) { if (packedFrame) {
frame._setDynamicAtlasFrame(packedFrame); frame._setDynamicAtlasFrame(packedFrame);
region._original = {
_texture: region.texture,
_x: region.x,
_y: region.y,
_ref: 0,
};
region._spriteFrame = frame; region._original = {
_texture: region.texture,
_x: region.x,
_y: region.y,
_ref: 0,
};
_tmpRegionData.updateWithPackedFrame(packedFrame); region._spriteFrame = frame;
this.updatePackedAttachment(attachment); _tmpRegionData.updateWithPackedFrame(packedFrame);
_packedRegions.push(region); this.updatePackedAttachment(attachment);
} else {
frame.destroy(); _packedRegions.push(region);
} else {
frame.destroy();
}
} }
} }
} }