From ed55413c266b194e95aa8569a00cbb94dcdb9da9 Mon Sep 17 00:00:00 2001 From: qiuguohua Date: Thu, 14 Mar 2024 09:24:38 +0800 Subject: [PATCH] Supplementing spriteframe's clone function (#16771) * Supplementing spriteframe's clone function * Remove identical variables and reorder variables * Deep copy mesh objects during clone * Call createMesh directly to avoid duplication of work --------- Co-authored-by: qiuguohua --- cocos/2d/assets/sprite-frame.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/cocos/2d/assets/sprite-frame.ts b/cocos/2d/assets/sprite-frame.ts index 4f9394aaa4..598484f695 100644 --- a/cocos/2d/assets/sprite-frame.ts +++ b/cocos/2d/assets/sprite-frame.ts @@ -1430,6 +1430,7 @@ export class SpriteFrame extends Asset { sp.unbiasUV.splice(0, sp.unbiasUV.length, ...this.unbiasUV); sp.uvSliced.splice(0, sp.uvSliced.length, ...this.uvSliced); sp._rect.set(this._rect); + sp._trimmedBorder.set(this._trimmedBorder); sp._offset.set(this._offset); sp._originalSize.set(this._originalSize); sp._rotated = this._rotated; @@ -1438,9 +1439,28 @@ export class SpriteFrame extends Asset { sp._texture = this._texture; sp._isFlipUVX = this._isFlipUVX; sp._isFlipUVY = this._isFlipUVY; + if (this._original) { + sp._original = { + _texture: this._original._texture, + _x: this._original._x, + _y: this._original._y, + }; + } else { + sp._original = null; + } + sp._packable = this._packable; sp._pixelsToUnit = this._pixelsToUnit; sp._pivot.set(this._pivot); sp._meshType = this._meshType; + sp._extrude = this._extrude; + sp._customOutLine.splice(0, sp._customOutLine.length, ...this._customOutLine); + sp._minPos = this._minPos; + sp._maxPos = this._maxPos; + if (this._mesh) { + // Creates a new mesh, and 'this' creates the mesh in the same way. So we can make a copy like this. + // It must be placed last because the mesh will depend on some of its members when it is created. + sp._createMesh(); + } return sp; }