using System.Threading; using UnityEngine; using UnityEngine.UI; using QFrameworkCP; namespace JXSoft { public class UDPPrinter : MonoBehaviour, IController { 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(); } // Update is called once per frame void Update() { if (udpUtil != null && !"".Equals(udpUtil.getReceivedValue())) { GameObject item = Instantiate(udpMsgItem, udpMsgContent); item.GetComponentInChildren().text = udpUtil.receivedData; this.GetModel().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().sendData(InputSendMsg.text); } public IArchitecture GetArchitecture() { return UDPMangerArchitecture.Interface; } } }