You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.4 KiB
50 lines
1.4 KiB
|
3 weeks ago
|
import { _decorator, Component, Node, Sprite } from 'cc';
|
||
|
|
const { ccclass } = _decorator;
|
||
|
|
|
||
|
|
/** 战斗技能格子:背景 + 图标 */
|
||
|
|
@ccclass('SkillGrid')
|
||
|
|
export class SkillGrid extends Component {
|
||
|
|
|
||
|
|
/** 格子背景 */
|
||
|
|
bg: Sprite = null;
|
||
|
|
/** 技能图标 */
|
||
|
|
icon: Sprite = null;
|
||
|
|
/** 绑定的技能配表行 */
|
||
|
|
skillData: ITableSkill = null;
|
||
|
|
|
||
|
|
protected onLoad(): void {
|
||
|
|
this.bg = this.resolveChildSprite('quality', 'q', 'bg');
|
||
|
|
this.icon = this.resolveChildSprite('icon');
|
||
|
|
}
|
||
|
|
|
||
|
|
protected onEnable(): void {
|
||
|
|
this.node.on(Node.EventType.TOUCH_END, this.onClick, this);
|
||
|
|
}
|
||
|
|
|
||
|
|
protected onDisable(): void {
|
||
|
|
this.node.off(Node.EventType.TOUCH_END, this.onClick, this);
|
||
|
|
}
|
||
|
|
|
||
|
|
/** 刷新格子展示数据 */
|
||
|
|
setData(data: ITableSkill): void {
|
||
|
|
this.skillData = data;
|
||
|
|
}
|
||
|
|
|
||
|
|
/** 点击技能格 */
|
||
|
|
onClick(): void {
|
||
|
|
console.log('onClickSkill', JSON.stringify(this.skillData));
|
||
|
|
}
|
||
|
|
|
||
|
|
/** 按候选节点名解析 Sprite,均未命中则 warn */
|
||
|
|
private resolveChildSprite(...names: string[]): Sprite | null {
|
||
|
|
for (const name of names) {
|
||
|
|
const child = this.node.getChildByName(name);
|
||
|
|
if (!child) continue;
|
||
|
|
const sprite = child.getComponent(Sprite);
|
||
|
|
if (sprite) return sprite;
|
||
|
|
}
|
||
|
|
console.log('[SkillGrid] 未找到 Sprite 子节点', this.node.name, names.join('|'));
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
}
|