refactor(HeroBoxComp): 优化属性栏配置与实时刷新逻辑
1. 将静态高度常量改为可编辑器配置的序列化属性 2. 添加帧更新实现属性降频刷新功能,同步实时属性 3. 调整变量声明顺序优化代码可读性
This commit is contained in:
1011
assets/resources/gui/auie/title.prefab
Normal file
1011
assets/resources/gui/auie/title.prefab
Normal file
File diff suppressed because it is too large
Load Diff
13
assets/resources/gui/auie/title.prefab.meta
Normal file
13
assets/resources/gui/auie/title.prefab.meta
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"ver": "1.1.50",
|
||||||
|
"importer": "prefab",
|
||||||
|
"imported": true,
|
||||||
|
"uuid": "6acdaa53-68e4-40fa-958b-da77aeaa3760",
|
||||||
|
"files": [
|
||||||
|
".json"
|
||||||
|
],
|
||||||
|
"subMetas": {},
|
||||||
|
"userData": {
|
||||||
|
"syncNodeName": "title"
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -134,12 +134,13 @@ export class HeroBoxComp extends CCComp {
|
|||||||
@property(Node)
|
@property(Node)
|
||||||
private wfuny_row: Node = null;
|
private wfuny_row: Node = null;
|
||||||
|
|
||||||
|
/** 属性栏收起高度 */
|
||||||
|
private attrBoxHeightCollapsed: number = 100;
|
||||||
|
/** 属性栏展开高度 */
|
||||||
|
private attrBoxHeightExpanded: number = 210;
|
||||||
|
|
||||||
/** 次级属性栏是否展开 */
|
/** 次级属性栏是否展开 */
|
||||||
private moreExpanded: boolean = false;
|
private moreExpanded: boolean = false;
|
||||||
/** 属性栏收起高度 */
|
|
||||||
private static readonly ATTR_BOX_HEIGHT_COLLAPSED = 125;
|
|
||||||
/** 属性栏展开高度 */
|
|
||||||
private static readonly ATTR_BOX_HEIGHT_EXPANDED = 210;
|
|
||||||
|
|
||||||
// ======================== 运行时状态 ========================
|
// ======================== 运行时状态 ========================
|
||||||
|
|
||||||
@@ -166,6 +167,24 @@ export class HeroBoxComp extends CCComp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 刷新计时累计(降频刷新实时属性) */
|
||||||
|
private refreshElapsed: number = 0;
|
||||||
|
/** 实时刷新间隔(秒) */
|
||||||
|
private static readonly REFRESH_INTERVAL = 0.25;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 帧更新:绑定英雄后按固定间隔实时刷新面板信息。
|
||||||
|
* Why: AP/HP/暴击等属性受 buff/光环影响实时变化,需降频轮询同步;
|
||||||
|
* 实体失效时 refresh 会自动切换为空状态。
|
||||||
|
*/
|
||||||
|
update(dt: number) {
|
||||||
|
if (!this.model) return;
|
||||||
|
this.refreshElapsed += dt;
|
||||||
|
if (this.refreshElapsed < HeroBoxComp.REFRESH_INTERVAL) return;
|
||||||
|
this.refreshElapsed = 0;
|
||||||
|
this.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
/** 更多按钮点击:切换次级属性栏显示/隐藏 */
|
/** 更多按钮点击:切换次级属性栏显示/隐藏 */
|
||||||
private onMoreBtnClick() {
|
private onMoreBtnClick() {
|
||||||
oops.audio.playEffect("music/button");
|
oops.audio.playEffect("music/button");
|
||||||
@@ -181,10 +200,10 @@ export class HeroBoxComp extends CCComp {
|
|||||||
row.active = visible;
|
row.active = visible;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 展开/收起时切换属性栏高度(125 ↔ 210)
|
// 展开/收起时切换属性栏高度(默认 125 ↔ 210,可在编辑器自定义)
|
||||||
if (this.attr_box && this.attr_box.isValid) {
|
if (this.attr_box && this.attr_box.isValid) {
|
||||||
const transform = this.attr_box.getComponent(UITransform) || this.attr_box.addComponent(UITransform);
|
const transform = this.attr_box.getComponent(UITransform) || this.attr_box.addComponent(UITransform);
|
||||||
const height = visible ? HeroBoxComp.ATTR_BOX_HEIGHT_EXPANDED : HeroBoxComp.ATTR_BOX_HEIGHT_COLLAPSED;
|
const height = visible ? this.attrBoxHeightExpanded : this.attrBoxHeightCollapsed;
|
||||||
transform.setContentSize(transform.width, height);
|
transform.setContentSize(transform.width, height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user