import { _decorator, Component, Node } from 'cc'; import ChatData from '../../../data/ChatData'; import { GUIChatMessageDTO } from '../../../consts/GActionType'; import { Label } from 'cc'; const { ccclass, property } = _decorator; @ccclass('MainChatIcon') export class MainChatIcon extends Component { @property(Label) text:Label; onLoad(){ //监听消息 ChatData.getIns().on(this.onMessage.bind(this),this); } protected onDestroy(): void { ChatData.getIns().off(this.onMessage.bind(this),this); } onMessage(info:GUIChatMessageDTO){ this.text.string = `${info.playerName} : ${info.message.message}` } }