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.
57 lines
1.6 KiB
57 lines
1.6 KiB
using System; |
|
using System.Collections; |
|
using System.Collections.Generic; |
|
using System.Net; |
|
using System.Net.Sockets; |
|
using System.Text; |
|
using System.Threading; |
|
using UnityEngine; |
|
using UnityEngine.UI; |
|
using QFramework; |
|
|
|
public class UDPPrinter : MonoBehaviour, IController, ICanSendEvent, ICanGetUtility |
|
{ |
|
private UDPUtility udpUtil; |
|
public Transform udpMsgContent; |
|
public GameObject udpMsgItem; |
|
|
|
public InputField InputSendMsg; |
|
private bool isUDPInit; |
|
// Start is called before the first frame update |
|
void Start() |
|
{ |
|
udpUtil = GetArchitecture().GetUtility<UDPUtility>(); |
|
} |
|
|
|
// Update is called once per frame |
|
void Update() |
|
{ |
|
if (udpUtil != null && !"".Equals(udpUtil.getReceivedValue())) |
|
{ |
|
GameObject item = Instantiate(udpMsgItem, udpMsgContent); |
|
item.GetComponentInChildren<Text>().text = udpUtil.receivedData; |
|
this.GetModel<UDPEventModel>().onDataRecived.Invoke(udpUtil.receivedData); |
|
} |
|
|
|
if (udpUtil.getTimeOutState() && udpUtil.isOpenUDP) |
|
{ |
|
this.SendEvent(new onUDPLinkException(udpUtil.exceptionData)); |
|
udpUtil.isOpenUDP = false; |
|
} |
|
} |
|
private void OnDestroy() |
|
{ |
|
if (udpUtil.reciveT != null && udpUtil.reciveT.ThreadState == ThreadState.Running) |
|
{ |
|
udpUtil.reciveT.Abort(); |
|
} |
|
} |
|
public void sendMsg() |
|
{ |
|
this.GetUtility<UDPUtility>().sendData(InputSendMsg.text); |
|
} |
|
public IArchitecture GetArchitecture() |
|
{ |
|
return UDPMangerArchitecture.Interface; |
|
} |
|
} |