perf(天赋面板): 优化天赋面板加载性能,减少重复资源加载
调整天赋面板预制体的UI布局参数,优化间距、内边距与容器尺寸。将天赋子项的图集加载改为父组件统一预加载并缓存,避免重复加载同一资源。面板添加时先立即刷新UI以保证秒开,后续异步更新所有子项的图标。
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -286,7 +286,7 @@
|
||||
"_lpos": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 666.634,
|
||||
"y": 706.696,
|
||||
"z": 0
|
||||
},
|
||||
"_lrot": {
|
||||
@@ -356,7 +356,7 @@
|
||||
"_target": null,
|
||||
"_left": 0,
|
||||
"_right": 0,
|
||||
"_top": -27.134000000000015,
|
||||
"_top": -67.19600000000003,
|
||||
"_bottom": 0,
|
||||
"_horizontalCenter": 0,
|
||||
"_verticalCenter": 0,
|
||||
@@ -426,7 +426,7 @@
|
||||
"_lpos": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 5,
|
||||
"y": 15,
|
||||
"z": 0
|
||||
},
|
||||
"_lrot": {
|
||||
@@ -844,7 +844,7 @@
|
||||
"_lpos": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": -255,
|
||||
"y": -245,
|
||||
"z": 0
|
||||
},
|
||||
"_lrot": {
|
||||
@@ -945,7 +945,7 @@
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 720,
|
||||
"height": 990
|
||||
"height": 1010
|
||||
},
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
@@ -1159,12 +1159,12 @@
|
||||
"height": 40
|
||||
},
|
||||
"_startAxis": 0,
|
||||
"_paddingLeft": 39.9,
|
||||
"_paddingRight": 40,
|
||||
"_paddingTop": 50,
|
||||
"_paddingLeft": 10,
|
||||
"_paddingRight": 10,
|
||||
"_paddingTop": 0,
|
||||
"_paddingBottom": 0,
|
||||
"_spacingX": 30,
|
||||
"_spacingY": 30,
|
||||
"_spacingX": 20,
|
||||
"_spacingY": 20,
|
||||
"_verticalDirection": 1,
|
||||
"_horizontalDirection": 0,
|
||||
"_constraint": 2,
|
||||
@@ -1218,7 +1218,7 @@
|
||||
"_contentSize": {
|
||||
"__type__": "cc.Size",
|
||||
"width": 720,
|
||||
"height": 990
|
||||
"height": 1010
|
||||
},
|
||||
"_anchorPoint": {
|
||||
"__type__": "cc.Vec2",
|
||||
@@ -1292,7 +1292,7 @@
|
||||
"_target": null,
|
||||
"_left": 0,
|
||||
"_right": 0,
|
||||
"_top": 140,
|
||||
"_top": 120,
|
||||
"_bottom": 150,
|
||||
"_horizontalCenter": 0,
|
||||
"_verticalCenter": 0,
|
||||
@@ -1371,7 +1371,7 @@
|
||||
"_lpos": {
|
||||
"__type__": "cc.Vec3",
|
||||
"x": 0,
|
||||
"y": 540,
|
||||
"y": 632.047,
|
||||
"z": 0
|
||||
},
|
||||
"_lrot": {
|
||||
@@ -1542,7 +1542,7 @@
|
||||
"__id__": 60
|
||||
},
|
||||
"_children": [],
|
||||
"_active": true,
|
||||
"_active": false,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 68
|
||||
@@ -1701,7 +1701,7 @@
|
||||
"__id__": 60
|
||||
},
|
||||
"_children": [],
|
||||
"_active": true,
|
||||
"_active": false,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 74
|
||||
@@ -1870,7 +1870,7 @@
|
||||
"__id__": 94
|
||||
}
|
||||
],
|
||||
"_active": true,
|
||||
"_active": false,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 102
|
||||
@@ -2546,7 +2546,7 @@
|
||||
"__id__": 60
|
||||
},
|
||||
"_children": [],
|
||||
"_active": true,
|
||||
"_active": false,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 110
|
||||
@@ -2705,7 +2705,7 @@
|
||||
"__id__": 60
|
||||
},
|
||||
"_children": [],
|
||||
"_active": true,
|
||||
"_active": false,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 116
|
||||
@@ -2868,7 +2868,7 @@
|
||||
"__id__": 122
|
||||
}
|
||||
],
|
||||
"_active": true,
|
||||
"_active": false,
|
||||
"_components": [
|
||||
{
|
||||
"__id__": 128
|
||||
@@ -3274,7 +3274,7 @@
|
||||
"_target": null,
|
||||
"_left": 0,
|
||||
"_right": 0,
|
||||
"_top": 0,
|
||||
"_top": -92.04700000000003,
|
||||
"_bottom": 0,
|
||||
"_horizontalCenter": 0,
|
||||
"_verticalCenter": 0,
|
||||
|
||||
@@ -38,9 +38,17 @@ export class TalentItemComp extends CCComp {
|
||||
@property({ type: Node, tooltip: "图标背景" })
|
||||
icon_bg: Node = null!;
|
||||
|
||||
private _talentId: TalentType = TalentType.Attack;
|
||||
private _talentId: TalentType = TalentType.DeadTrigger;
|
||||
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;
|
||||
|
||||
protected onLoad(): void {
|
||||
if (this.btn_upgrade && this.btn_upgrade.node) {
|
||||
@@ -55,6 +63,7 @@ export class TalentItemComp extends CCComp {
|
||||
* @param onClickCallback 点击升级按钮的回调
|
||||
*/
|
||||
public updateItem(talentInfo: TalentInfo, currentLevel: number, onClickCallback: (talentId: TalentType, currentLevel: number) => void) {
|
||||
this._talentInfo = talentInfo;
|
||||
this._talentId = talentInfo.id;
|
||||
this._currentLevel = currentLevel;
|
||||
this._onClickCallback = onClickCallback;
|
||||
@@ -63,16 +72,8 @@ export class TalentItemComp extends CCComp {
|
||||
this.lbl_name.string = talentInfo.name;
|
||||
}
|
||||
|
||||
if (this.icon_node && talentInfo.icon) {
|
||||
resources.load("gui/uicons", SpriteAtlas, (err, atlas) => {
|
||||
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;
|
||||
}
|
||||
});
|
||||
}
|
||||
// 同步尝试刷新一次图标(如果图集已经缓存过,比如重新打开界面时)
|
||||
this.refreshIcon();
|
||||
|
||||
if (this.lbl_desc) {
|
||||
let currentVal = currentLevel === 0 ? 0 : talentInfo.values[currentLevel - 1];
|
||||
@@ -96,6 +97,19 @@ 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 (frame && this.icon_node.isValid) {
|
||||
const sprite = this.icon_node.getComponent(Sprite) || this.icon_node.addComponent(Sprite);
|
||||
sprite.spriteFrame = frame;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private onUpgradeClicked() {
|
||||
if (this._onClickCallback) {
|
||||
this._onClickCallback(this._talentId, this._currentLevel);
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
* - ScoreWeights(ScoreSet)—— 得分权重配置
|
||||
* - GameEvent.MissionEnd / MissionStart —— 游戏生命周期事件
|
||||
*/
|
||||
import { _decorator, Node, Label, Button, ProgressBar, instantiate, Prefab } from "cc";
|
||||
import { _decorator, Node, Label, Button, ProgressBar, instantiate, Prefab, resources, SpriteAtlas } 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,7 +88,20 @@ export class TalentsComp extends CCComp {
|
||||
}
|
||||
|
||||
onAdded(args: any) {
|
||||
// 先立刻刷新界面结构,保证面板秒开
|
||||
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();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/** 刷新整体界面 */
|
||||
|
||||
Reference in New Issue
Block a user