import { _decorator, Component, Node, Label, director, RichText } from 'cc'; import { GEvent } from '../event/GEvent'; const { ccclass, property } = _decorator; @ccclass('LangTxt') export class LangTxt extends Component { @property key: string = ``; _lb: Label; _str: string = ``; _rt: RichText; onLoad() { this._lb = this.node.getComponent(Label); this._rt = this.node.getComponent(RichText); if (this._lb) this._str = this._lb.string; if (this._rt) this._str = this._rt.string; if (this.key == "") this.key = this._str; if (this.key == "") this.key = this.node.name; } onEnable() { this.updateLang(); GEvent.Ins.on(GEvent.EVENT_LANG_CHANGE, this.updateLang, this); } onDisable() { GEvent.Ins.off(GEvent.EVENT_LANG_CHANGE, this.updateLang, this); } async updateLang() { await gg.lang.whenReady(); let str = gg.lang.get(this.key); //console.log("更新 LangTxt 组件", this.key, str); if (str == "") str = this._str; if (this._lb) this._lb.string = str; if (this._rt) this._rt.string = str; } setKey(key: string) { this.key = key; this.updateLang(); } }