import { _decorator, Component, Node, Animation } from 'cc'; import { BitmapFont } from '../../core/ui/BitmapFont'; import { HitData } from '../HitData'; const { ccclass, property } = _decorator; @ccclass('BloodLabel') export class BloodLabel extends Component { @property({ type: Node, tooltip: "暴击组" }) cri: Node; @property({ type: Node, tooltip: "普通组" }) normal: Node; @property({ type: Node, tooltip: "技能组" }) skill: Node; @property({ type: Node, tooltip: "闪避" }) miss: Node; @property({ type: Animation, tooltip: "动画组件" }) animation: Animation; start() { this.animation.on(Animation.EventType.FINISHED, () => { this.node.destroy(); }, this); } public setData(data: HitData): void { let hit = data.hit > 10000 ? (data.hit / 1000).toFixed(1) + "k" : data.hit + ""; if (data.isMiss) { this.miss.active = true; } else { if (data.isCri) { this.cri.getComponent(BitmapFont).string = "-" + hit; this.cri.active = true; } else if (data.isSkill) { this.skill.getComponent(BitmapFont).string = "-" + hit; this.skill.active = true; } else { this.normal.getComponent(BitmapFont).string = "-" + hit; this.normal.active = true; } } this.animation.play(); } }