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 <guohua.qiu@cocos.com>
This commit is contained in:
qiuguohua
2024-03-14 09:24:38 +08:00
committed by GitHub
parent 2a60c6a96a
commit ed55413c26
+20
View File
@@ -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;
}