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;

View File

@@ -18,7 +18,7 @@
* - ScoreWeightsScoreSet—— 得分权重配置
* - GameEvent.MissionEnd / MissionStart —— 游戏生命周期事件
*/
import { _decorator, Node, Label, Button, ProgressBar, instantiate, Prefab, resources, SpriteAtlas } from "cc";
import { _decorator, Node, Label, Button, ProgressBar, instantiate, Prefab } from "cc";
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { CCComp } from "../../../../extensions/oops-plugin-framework/assets/module/common/CCComp";
import { mLogger } from "../common/Logger";
@@ -88,20 +88,8 @@ export class TalentsComp extends CCComp {
}
onAdded(args: any) {
// 先立刻刷新界面结构,保证面板秒开
// 直接刷新界面,因为图集已经在游戏启动时被 smc 预加载并缓存
this.refreshUI();
// 异步预加载图集,不阻塞主界面的生成
resources.load("gui/uicons", SpriteAtlas, (err, atlas) => {
if (!err && atlas) {
TalentItemComp.setAtlas(atlas);
// 图集加载完毕后,让所有的子组件只刷新一下自己的图标
this.talents_content.children.forEach(child => {
let comp = child.getComponent(TalentItemComp);
if (comp) comp.refreshIcon();
});
}
});
}
/** 刷新整体界面 */