diff --git a/assets/Scene/main.fire b/assets/Scene/main.fire index 549fa4f..4293438 100755 --- a/assets/Scene/main.fire +++ b/assets/Scene/main.fire @@ -93,16 +93,19 @@ }, { "__id__": 64 + }, + { + "__id__": 72 } ], "_active": true, "_level": 0, "_components": [ { - "__id__": 72 + "__id__": 74 }, { - "__id__": 73 + "__id__": 75 } ], "_prefab": null, @@ -3249,6 +3252,86 @@ "handler": "onDisconnectClick", "customEventData": "" }, + { + "__type__": "cc.Node", + "_name": "richtext", + "_objFlags": 0, + "_parent": { + "__id__": 2 + }, + "_children": [], + "_active": true, + "_level": 1, + "_components": [ + { + "__id__": 73 + } + ], + "_prefab": null, + "_opacity": 255, + "_color": { + "__type__": "cc.Color", + "r": 255, + "g": 255, + "b": 255, + "a": 255 + }, + "_contentSize": { + "__type__": "cc.Size", + "width": 0, + "height": 63 + }, + "_anchorPoint": { + "__type__": "cc.Vec2", + "x": 0, + "y": 1 + }, + "_position": { + "__type__": "cc.Vec3", + "x": -201.574, + "y": 86.929, + "z": 0 + }, + "_scale": { + "__type__": "cc.Vec3", + "x": 1, + "y": 1, + "z": 1 + }, + "_eulerAngles": { + "__type__": "cc.Vec3", + "x": 0, + "y": 0, + "z": 0 + }, + "_skewX": 0, + "_skewY": 0, + "_is3DNode": false, + "groupIndex": 0, + "_rotationX": 0, + "_rotationY": 0, + "_id": "6dqncKq5VIYI1GPBiYJZED" + }, + { + "__type__": "cc.RichText", + "_name": "", + "_objFlags": 0, + "node": { + "__id__": 72 + }, + "_enabled": true, + "_fontFamily": "Arial", + "_isSystemFontUsed": true, + "_N$string": "", + "_N$horizontalAlign": 0, + "_N$fontSize": 30, + "_N$font": null, + "_N$maxWidth": 0, + "_N$lineHeight": 50, + "_N$imageAtlas": null, + "_N$handleTouchEvent": false, + "_id": "d0TZoJx5FO/7jFqKoHzO+v" + }, { "__type__": "cc.Canvas", "_name": "", @@ -3274,13 +3357,15 @@ "__id__": 2 }, "_enabled": true, - "text": "hello", "textLabel": { "__id__": 58 }, "urlLabel": { "__id__": 11 }, + "msgLabel": { + "__id__": 73 + }, "_id": "0bpgf5DdFHd43ZDy0vkFUX" } ] \ No newline at end of file diff --git a/assets/Script/example/NetExample.ts b/assets/Script/example/NetExample.ts index 14b2a0f..6bd19c0 100644 --- a/assets/Script/example/NetExample.ts +++ b/assets/Script/example/NetExample.ts @@ -9,21 +9,26 @@ const { ccclass, property } = cc._decorator; @ccclass export default class NewClass extends cc.Component { - @property - text: string = 'hello'; @property(cc.Label) textLabel: cc.Label = null; @property(cc.Label) urlLabel: cc.Label = null; + @property(cc.RichText) + msgLabel: cc.RichText = null; + private lineCount: number = 0; onLoad() { let Node = new NetNode(); Node.init(new WebSock(), new DefStringProtocol()); - Node.setResponeHandler(0, (cmd: number, data: NetData) => { - console.log(`${data}`); + Node.setResponeHandler(0, (cmd: number, data: NetData) => { + if (this.lineCount > 5) { + let idx = this.msgLabel.string.search("\n"); + this.msgLabel.string = this.msgLabel.string.substr(idx + 1); + } + this.msgLabel.string += `${data}\n`; + ++this.lineCount; }); NetManager.getInstance().setNetNode(Node); - } onConnectClick() {