金铉Unity插件库 Unity版本2018.4.32f 目前包含本地化存储功能(根据类名存储读写),TCP客户端监听类型功能
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.5 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using JXSoft;
public class TCPClientExample : MonoBehaviour,ITCPClient
{
// Start is called before the first frame update
void Start()
{
//注册接收到数据类型事件监听
this.RegisterMessageEvent<YourResponse>(e => {
Debug.Log("TestGetMsg:"+e.msg);
//应答
this.sendRequest(new StringRequest("Received!"));
//取消接收该数据
this.offReceive<YourResponse>();
});
//开启开数据类型接收
this.onReceive<YourResponse>();
}
}
#region ResReqData
public class YourResponse : AbstractJsonResponse
{
public string msg;
public YourResponse()
{
this.msg = "";
}
}
public struct YourNumberFilterResponse : IResponse
{
public string code;
private int codeNum;
private string exceptionMsg;
public string toProtocolData()
{
return "你想要打印的调试信息,无需打印返回空字符串即可";
}
public bool trySetData(string protocolData)
{
bool isNumber = int.TryParse(code, out codeNum);
if (!isNumber)
{
exceptionMsg = "这不是数字";
}
return isNumber;
}
public string getException()
{
return exceptionMsg;
}
}
public class YourRequest:IRequest {
public string toProtocolData()
{
return "要发的请求内容";
}
}
#endregion