1、Panel端。 //监听WEB服务器返回的消息。 ShowMessage((string)((tmpMsg as MsgObject).value)); /// 向服务器发送获取客流量消息。 private void SendKeLiu() { SendMsg(new MsgString((ushort)NetEvent.UI.GetExhibish, “getNum”)); } /// 解析web服务器返回的信息. private void ShowMessage(string value) { GameObject KeLiuLiangText = UIManager.Instance.GetGameObject(“KeLiuLiangText”); KeLiuLiangText.GetComponent ().text = value; StartCoroutine(Open(5f,()=> { SendMsg(new MsgString((ushort)NetEvent.UI.GetExhibish, “getNum”));
}));
}
private IEnumerator Open(float tiem,Action ac)
{
yield return new WaitForSeconds(5f);
ac();
}
2、NetBehaviour.CS端
/// /获取客流量。
private IEnumerator GetExhibish(string value)
{
UnityWebRequest www = UnityWebRequest.Get(ServerAPI.serverAddress + ServerAPI.getExhibish);
yield return www.SendWebRequest();
if (www.isNetworkError || www.isHttpError)
{
Debug.Log(www.error + "___错误码:" + www.responseCode);
}
else
{
string getExhibish = www.downloadHandler.text;
if (!string.IsNullOrEmpty(getExhibish))
{
MsgObject KeLiuInfo = new MsgObject((ushort)UIEvent.Net.ShowExhibish, getExhibish);
SendMsg(KeLiuInfo);
}
else
{
Debug.Log("获取文字失败");
}
}
}
3、注意部分: 3.1ShowMessage((string)((tmpMsg as MsgObject).value));类型转换部分。 3.2 java数据不为map的,不需要json解析。
4、Java后台 private static Integer i = 0;
@GetMapping("getNum")
public String getNum(){
i += 5;
return i.toString();
}