金铉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.
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.Events;
|
|
|
|
using UnityEngine.UI;
|
|
|
|
using QFramework;
|
|
|
|
using System.Threading;
|
|
|
|
|
|
|
|
namespace TCPClientTools
|
|
|
|
{
|
|
|
|
public class TCPPrinter : MonoBehaviour,IController,ICanSendEvent
|
|
|
|
{
|
|
|
|
private TCPUtility tcpUtil;
|
|
|
|
public Transform tcpMsgContent;
|
|
|
|
public GameObject tcpMsgItem;
|
|
|
|
|
|
|
|
void Awake()
|
|
|
|
{
|
|
|
|
tcpUtil = GetArchitecture().GetUtility<TCPUtility>();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
//Debug.Log(tcpUtil.Read_TCPClient());
|
|
|
|
if (tcpUtil != null && !"".Equals(tcpUtil.getReceivedValue())) {
|
|
|
|
GameObject item = Instantiate(tcpMsgItem, tcpMsgContent);
|
|
|
|
item.GetComponentInChildren<Text>().text = tcpUtil.receivedData;
|
|
|
|
this.GetModel<TCPEventModel>().onDataRecived.Invoke(tcpUtil.receivedData);
|
|
|
|
}
|
|
|
|
if (tcpUtil.getTimeOutState() && tcpUtil.isOpenTCP) {
|
|
|
|
this.SendEvent(new onLinkException(tcpUtil.exceptionData));
|
|
|
|
tcpUtil.isOpenTCP = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private void OnDestroy()
|
|
|
|
{
|
|
|
|
if (tcpUtil.reciveT != null && tcpUtil.reciveT.ThreadState == ThreadState.Running) {
|
|
|
|
tcpUtil.reciveT.Abort();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public IArchitecture GetArchitecture()
|
|
|
|
{
|
|
|
|
return TCPMangerArchitecture.Interface;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|