perf(talent): 优化天赋系统的图集预加载与缓存逻辑

将天赋图集预加载从天赋界面初始化时提前至游戏公共资源加载阶段,新增全局单例缓存机制替换组件自身的静态缓存,移除冗余的异步加载代码与未使用的导入语句,修正TalentItemComp的初始默认天赋类型为Attack
This commit is contained in:
walkpan
2026-05-11 16:08:20 +08:00
parent 336d7d03db
commit bcef8fbc64
4 changed files with 26 additions and 25 deletions

View File

@@ -38,15 +38,9 @@ export class TalentItemComp extends CCComp {
@property({ type: Node, tooltip: "图标背景" })
icon_bg: Node = null!;
private _talentId: TalentType = TalentType.DeadTrigger;
private _talentId: TalentType = TalentType.Attack;
private _onClickCallback: ((talentId: TalentType, currentLevel: number) => void) | null = null;
private _currentLevel: number = 0;
private static _cachedAtlas: SpriteAtlas | null = null;
public static setAtlas(atlas: SpriteAtlas) {
TalentItemComp._cachedAtlas = atlas;
}
private _talentInfo: TalentInfo | null = null;
@@ -97,12 +91,12 @@ export class TalentItemComp extends CCComp {
}
}
/** 单独更新图标,供父节点加载完图集后回调 */
/** 单独更新图标,供父节点加载完图集后回调或自身更新时调用 */
public refreshIcon() {
if (!this._talentInfo || !this.icon_node || !this._talentInfo.icon) return;
if (TalentItemComp._cachedAtlas) {
const frame = TalentItemComp._cachedAtlas.getSpriteFrame(this._talentInfo.icon);
if (smc.uiconsAtlas) {
const frame = smc.uiconsAtlas.getSpriteFrame(this._talentInfo.icon);
if (frame && this.icon_node.isValid) {
const sprite = this.icon_node.getComponent(Sprite) || this.icon_node.addComponent(Sprite);
sprite.spriteFrame = frame;