Monitor.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class Monitor : MonoBehaviour
  5. {//挂在游戏场景的一个空物体上
  6. //public ServerScript serverScript;
  7. public GameObject gameObj;
  8. void Start()
  9. {
  10. // gameObj = serverScript.gameObj;
  11. }
  12. // Update is called once per frame
  13. void Update()
  14. {
  15. if (Tcp_Server.isClient && !gameObj.activeSelf)//客户端是否连接跟游戏物体隐藏状态
  16. {
  17. //客户端连接后显示游戏物体
  18. gameObj.SetActive(true);
  19. }
  20. else if (!Tcp_Server.isClient && gameObj.activeSelf)
  21. {
  22. //客户端断开隐藏游戏物体
  23. gameObj.SetActive(false);
  24. }
  25. //获取客户端消息
  26. byte[] receiveMsg = TcpReceiveManager.getMsg();
  27. if (receiveMsg != null)
  28. {
  29. MessageData msg = Tcp_Util.BufferToMessage(receiveMsg);
  30. MonitorEvent(msg);
  31. }
  32. }
  33. private void MonitorEvent(MessageData mag)
  34. {
  35. TextData td = (TextData)mag;
  36. if (td.id == "Madd")
  37. {
  38. gameObj.GetComponent<GameObjectManagerServer>().ClickButton(td.text);
  39. }
  40. else if (td.id == "Bint")
  41. {
  42. gameObj.GetComponent<GameObjectManagerServer>().ScanJunshi(td.text);
  43. }
  44. }
  45. }