fix: 修复图集GC回收和天赋图标加载异常问题
1. 为uicons图集增加引用计数防止被GC回收导致spriteFrames为空 2. 增加图集spriteFrames存在性校验,避免空引用报错 3. 将天赋图标配置转为字符串类型,防止纯数字配置导致获取失败
This commit is contained in:
@@ -95,8 +95,10 @@ export class TalentItemComp extends CCComp {
|
||||
public refreshIcon() {
|
||||
if (!this._talentInfo || !this.icon_node || !this._talentInfo.icon) return;
|
||||
|
||||
if (smc.uiconsAtlas) {
|
||||
const frame = smc.uiconsAtlas.getSpriteFrame(this._talentInfo.icon);
|
||||
if (smc.uiconsAtlas && smc.uiconsAtlas.spriteFrames) {
|
||||
// 确保 icon 是字符串类型,防止配置写成纯数字导致底层 getSpriteFrame 报错
|
||||
const iconStr = String(this._talentInfo.icon);
|
||||
const frame = smc.uiconsAtlas.getSpriteFrame(iconStr);
|
||||
if (frame && this.icon_node.isValid) {
|
||||
const sprite = this.icon_node.getComponent(Sprite) || this.icon_node.addComponent(Sprite);
|
||||
sprite.spriteFrame = frame;
|
||||
|
||||
Reference in New Issue
Block a user