// Learn TypeScript: // - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html // Learn Attribute: // - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html import EventName from "../EventName/EventName"; import MyComponent from "../Template/MyComponent"; const { ccclass, property } = cc._decorator; @ccclass export default class GameTips extends MyComponent { @property(cc.Label) Hight: cc.Label = null; @property(cc.Label) History: cc.Label = null; @property(cc.Label) Now: cc.Label = null; // LIFE-CYCLE CALLBACKS: onLoad() { super.onLoad() } start() { this.regEvent(EventName.Update_CurrentHight, this.Update_CurrentHight, this) this.regEvent(EventName.YaoGanEnd, this.YaoGanEnd, this) this.regEvent(EventName.YaoGanMove, this.YaoGanMove, this) } Update_CurrentHight(hightNum: number) { this.Hight.string = hightNum.toString() } YaoGanEnd(dir: cc.Vec3, power: number) { const result = parseFloat((power * 100).toFixed(2)); this.History.string = `历史:${this.GetAngle(dir)}° , ${result}%` } YaoGanMove(dir: cc.Vec3, power: number) { const result = parseFloat((power * 100).toFixed(2)); this.Now.string = `${this.GetAngle(dir)}° , ${result}%` } GetAngle(dir: cc.Vec3) { //根据朝向计算出夹角弧度 var angle = dir.signAngle(cc.v2(0, 1)); //将弧度转换为欧拉角 return (angle / Math.PI * 180).toFixed(0); } onDestroy(): void { super.onDestroy() } }