using System.Collections; using System.Collections.Generic; using UnityEngine; public class Monitor : MonoBehaviour {//挂在游戏场景的一个空物体上 //public ServerScript serverScript; public GameObject gameObj; void Start() { // gameObj = serverScript.gameObj; } // Update is called once per frame void Update() { if (Tcp_Server.isClient && !gameObj.activeSelf)//客户端是否连接跟游戏物体隐藏状态 { //客户端连接后显示游戏物体 gameObj.SetActive(true); } else if (!Tcp_Server.isClient && gameObj.activeSelf) { //客户端断开隐藏游戏物体 gameObj.SetActive(false); } //获取客户端消息 byte[] receiveMsg = TcpReceiveManager.getMsg(); if (receiveMsg != null) { MessageData msg = Tcp_Util.BufferToMessage(receiveMsg); MonitorEvent(msg); } } private void MonitorEvent(MessageData mag) { TextData td = (TextData)mag; if (td.id == "Madd") { gameObj.GetComponent().ClickButton(td.text); } else if (td.id == "Bint") { gameObj.GetComponent().ScanJunshi(td.text); } } }