2 Commits

Author SHA1 Message Date
walkpan
bcef8fbc64 perf(talent): 优化天赋系统的图集预加载与缓存逻辑
将天赋图集预加载从天赋界面初始化时提前至游戏公共资源加载阶段,新增全局单例缓存机制替换组件自身的静态缓存,移除冗余的异步加载代码与未使用的导入语句,修正TalentItemComp的初始默认天赋类型为Attack
2026-05-11 16:08:20 +08:00
walkpan
336d7d03db perf(天赋面板): 优化天赋面板加载性能,减少重复资源加载
调整天赋面板预制体的UI布局参数,优化间距、内边距与容器尺寸。将天赋子项的图集加载改为父组件统一预加载并缓存,避免重复加载同一资源。面板添加时先立即刷新UI以保证秒开,后续异步更新所有子项的图标。
2026-05-11 16:05:59 +08:00
6 changed files with 130 additions and 1655 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -286,7 +286,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": 666.634, "y": 706.696,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {
@@ -356,7 +356,7 @@
"_target": null, "_target": null,
"_left": 0, "_left": 0,
"_right": 0, "_right": 0,
"_top": -27.134000000000015, "_top": -67.19600000000003,
"_bottom": 0, "_bottom": 0,
"_horizontalCenter": 0, "_horizontalCenter": 0,
"_verticalCenter": 0, "_verticalCenter": 0,
@@ -426,7 +426,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": 5, "y": 15,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {
@@ -844,7 +844,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": -255, "y": -245,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {
@@ -945,7 +945,7 @@
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 720, "width": 720,
"height": 990 "height": 1010
}, },
"_anchorPoint": { "_anchorPoint": {
"__type__": "cc.Vec2", "__type__": "cc.Vec2",
@@ -1159,12 +1159,12 @@
"height": 40 "height": 40
}, },
"_startAxis": 0, "_startAxis": 0,
"_paddingLeft": 39.9, "_paddingLeft": 10,
"_paddingRight": 40, "_paddingRight": 10,
"_paddingTop": 50, "_paddingTop": 0,
"_paddingBottom": 0, "_paddingBottom": 0,
"_spacingX": 30, "_spacingX": 20,
"_spacingY": 30, "_spacingY": 20,
"_verticalDirection": 1, "_verticalDirection": 1,
"_horizontalDirection": 0, "_horizontalDirection": 0,
"_constraint": 2, "_constraint": 2,
@@ -1218,7 +1218,7 @@
"_contentSize": { "_contentSize": {
"__type__": "cc.Size", "__type__": "cc.Size",
"width": 720, "width": 720,
"height": 990 "height": 1010
}, },
"_anchorPoint": { "_anchorPoint": {
"__type__": "cc.Vec2", "__type__": "cc.Vec2",
@@ -1292,7 +1292,7 @@
"_target": null, "_target": null,
"_left": 0, "_left": 0,
"_right": 0, "_right": 0,
"_top": 140, "_top": 120,
"_bottom": 150, "_bottom": 150,
"_horizontalCenter": 0, "_horizontalCenter": 0,
"_verticalCenter": 0, "_verticalCenter": 0,
@@ -1371,7 +1371,7 @@
"_lpos": { "_lpos": {
"__type__": "cc.Vec3", "__type__": "cc.Vec3",
"x": 0, "x": 0,
"y": 540, "y": 632.047,
"z": 0 "z": 0
}, },
"_lrot": { "_lrot": {
@@ -1542,7 +1542,7 @@
"__id__": 60 "__id__": 60
}, },
"_children": [], "_children": [],
"_active": true, "_active": false,
"_components": [ "_components": [
{ {
"__id__": 68 "__id__": 68
@@ -1701,7 +1701,7 @@
"__id__": 60 "__id__": 60
}, },
"_children": [], "_children": [],
"_active": true, "_active": false,
"_components": [ "_components": [
{ {
"__id__": 74 "__id__": 74
@@ -1870,7 +1870,7 @@
"__id__": 94 "__id__": 94
} }
], ],
"_active": true, "_active": false,
"_components": [ "_components": [
{ {
"__id__": 102 "__id__": 102
@@ -2546,7 +2546,7 @@
"__id__": 60 "__id__": 60
}, },
"_children": [], "_children": [],
"_active": true, "_active": false,
"_components": [ "_components": [
{ {
"__id__": 110 "__id__": 110
@@ -2705,7 +2705,7 @@
"__id__": 60 "__id__": 60
}, },
"_children": [], "_children": [],
"_active": true, "_active": false,
"_components": [ "_components": [
{ {
"__id__": 116 "__id__": 116
@@ -2868,7 +2868,7 @@
"__id__": 122 "__id__": 122
} }
], ],
"_active": true, "_active": false,
"_components": [ "_components": [
{ {
"__id__": 128 "__id__": 128
@@ -3274,7 +3274,7 @@
"_target": null, "_target": null,
"_left": 0, "_left": 0,
"_right": 0, "_right": 0,
"_top": 0, "_top": -92.04700000000003,
"_bottom": 0, "_bottom": 0,
"_horizontalCenter": 0, "_horizontalCenter": 0,
"_verticalCenter": 0, "_verticalCenter": 0,

View File

@@ -1,4 +1,4 @@
import { sys } from "cc"; import { sys, resources, SpriteAtlas } from "cc";
import { VM } from "../../../../extensions/oops-plugin-framework/assets/libs/model-view/ViewModel"; import { VM } from "../../../../extensions/oops-plugin-framework/assets/libs/model-view/ViewModel";
import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS"; import { ecs } from "../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { Initialize } from "../initialize/Initialize"; import { Initialize } from "../initialize/Initialize";
@@ -39,6 +39,10 @@ export class SingletonModuleComp extends ecs.Comp {
initialize: Initialize = null!; initialize: Initialize = null!;
/** 游戏地图 */ /** 游戏地图 */
map: GameMap = null!; map: GameMap = null!;
/** 全局缓存的通用图集 */
uiconsAtlas: SpriteAtlas | null = null;
openid:string='' openid:string=''
mission:any={ mission:any={
status:0, //0:未开始 1:进行中 2:胜利 3:失败 status:0, //0:未开始 1:进行中 2:胜利 3:失败
@@ -282,6 +286,19 @@ export class SingletonModuleComp extends ecs.Comp {
oops.message.dispatchEvent(GameEvent.GOLD_UPDATE) oops.message.dispatchEvent(GameEvent.GOLD_UPDATE)
return true return true
} }
/**
* 在游戏载入早期调用,预加载常用图集
*/
preloadCommonAssets() {
resources.load("gui/uicons", SpriteAtlas, (err, atlas) => {
if (!err && atlas) {
this.uiconsAtlas = atlas;
} else {
mLogger.error(this.debugMode, 'SMC', "预加载 gui/uicons 图集失败:", err);
}
});
}
} }
export var smc: SingletonModuleComp = ecs.getSingleton(SingletonModuleComp); export var smc: SingletonModuleComp = ecs.getSingleton(SingletonModuleComp);

View File

@@ -83,6 +83,8 @@ export class Initialize extends ecs.Entity {
/** 加载公共资源(必备) */ /** 加载公共资源(必备) */
private loadCommon(queue: AsyncQueue) { private loadCommon(queue: AsyncQueue) {
queue.push((next: NextFunction, params: any, args: any) => { queue.push((next: NextFunction, params: any, args: any) => {
// 顺便在这里预加载 SMC 需要的公共图集
smc.preloadCommonAssets();
oops.res.loadDir("common", next); oops.res.loadDir("common", next);
}); });
} }

View File

@@ -42,6 +42,8 @@ export class TalentItemComp extends CCComp {
private _onClickCallback: ((talentId: TalentType, currentLevel: number) => void) | null = null; private _onClickCallback: ((talentId: TalentType, currentLevel: number) => void) | null = null;
private _currentLevel: number = 0; private _currentLevel: number = 0;
private _talentInfo: TalentInfo | null = null;
protected onLoad(): void { protected onLoad(): void {
if (this.btn_upgrade && this.btn_upgrade.node) { if (this.btn_upgrade && this.btn_upgrade.node) {
this.btn_upgrade.node.on(Button.EventType.CLICK, this.onUpgradeClicked, this); this.btn_upgrade.node.on(Button.EventType.CLICK, this.onUpgradeClicked, this);
@@ -55,6 +57,7 @@ export class TalentItemComp extends CCComp {
* @param onClickCallback 点击升级按钮的回调 * @param onClickCallback 点击升级按钮的回调
*/ */
public updateItem(talentInfo: TalentInfo, currentLevel: number, onClickCallback: (talentId: TalentType, currentLevel: number) => void) { public updateItem(talentInfo: TalentInfo, currentLevel: number, onClickCallback: (talentId: TalentType, currentLevel: number) => void) {
this._talentInfo = talentInfo;
this._talentId = talentInfo.id; this._talentId = talentInfo.id;
this._currentLevel = currentLevel; this._currentLevel = currentLevel;
this._onClickCallback = onClickCallback; this._onClickCallback = onClickCallback;
@@ -63,16 +66,8 @@ export class TalentItemComp extends CCComp {
this.lbl_name.string = talentInfo.name; this.lbl_name.string = talentInfo.name;
} }
if (this.icon_node && talentInfo.icon) { // 同步尝试刷新一次图标(如果图集已经缓存过,比如重新打开界面时)
resources.load("gui/uicons", SpriteAtlas, (err, atlas) => { this.refreshIcon();
if (err || !atlas) return;
const frame = atlas.getSpriteFrame(talentInfo.icon!);
if (frame && this.icon_node && this.icon_node.isValid) {
const sprite = this.icon_node.getComponent(Sprite) || this.icon_node.addComponent(Sprite);
sprite.spriteFrame = frame;
}
});
}
if (this.lbl_desc) { if (this.lbl_desc) {
let currentVal = currentLevel === 0 ? 0 : talentInfo.values[currentLevel - 1]; let currentVal = currentLevel === 0 ? 0 : talentInfo.values[currentLevel - 1];
@@ -96,6 +91,19 @@ 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 (frame && this.icon_node.isValid) {
const sprite = this.icon_node.getComponent(Sprite) || this.icon_node.addComponent(Sprite);
sprite.spriteFrame = frame;
}
}
}
private onUpgradeClicked() { private onUpgradeClicked() {
if (this._onClickCallback) { if (this._onClickCallback) {
this._onClickCallback(this._talentId, this._currentLevel); this._onClickCallback(this._talentId, this._currentLevel);

View File

@@ -88,6 +88,7 @@ export class TalentsComp extends CCComp {
} }
onAdded(args: any) { onAdded(args: any) {
// 直接刷新界面,因为图集已经在游戏启动时被 smc 预加载并缓存
this.refreshUI(); this.refreshUI();
} }