import { _decorator, CCBoolean, Component, Label, TTFFont } from 'cc'; import { getLanguage } from '../comm'; const { ccclass, property } = _decorator; @ccclass('LocalizedLabel2') export class LocalizedLabel2 extends Component { private label: Label | null = null; // 加入是否是加粗的属性 @property({ type: CCBoolean, tooltip: '是否是加粗的' }) public isBold: boolean = false; // ========== 除了中日韩其他所有语言字体 ========== @property({ type: TTFFont, tooltip: '其他语言字体' }) public fontOther: TTFFont | null = null; @property({ type: TTFFont, tooltip: '加粗字体' }) public fontOtherBold: TTFFont | null = null; // ========== 泰语字体 (th),越南语字体 (vi) ========== @property({ type: TTFFont, tooltip: '泰语越南字体' }) public fontThVi: TTFFont | null = null; @property({ type: TTFFont, tooltip: '泰语越南加粗字体' }) public fontThViBold: TTFFont | null = null; // ========== 缅甸语字体 (my) ========== @property({ type: TTFFont, tooltip: '缅甸语字体' }) public fontMy: TTFFont | null = null; @property({ type: TTFFont, tooltip: '缅甸语加粗字体' }) public fontMyBold: TTFFont | null = null; start() { this.label = this.getComponent(Label); this.updateLabel(); } public updateLabel() { if (!this.label) return; this.applyFont(); } private applyFont() { const currentLang = getLanguage(); let targetFont: TTFFont | null = null; switch (currentLang) { case 'zh': case 'ja': case 'ko': targetFont = null; break; case 'th': targetFont = this.isBold ? this.fontThViBold : this.fontThVi; break; case 'vi': targetFont = this.isBold ? this.fontThViBold : this.fontThVi; break; case 'my': targetFont = this.isBold ? this.fontMyBold : this.fontMy; break; default: targetFont = this.isBold ? this.fontOtherBold : this.fontOther; break; } if (targetFont) { this.label.useSystemFont = false; this.label.font = targetFont; } else { this.label.useSystemFont = true; } this.label.isBold = this.isBold; this.label.updateRenderData(); console.log(currentLang, 'targetFont', targetFont); } }