コード例 #1
0
 public void Update()
 {
     //消息
     msgDist.Update();
     //心跳
     if (status == Status.Connected)
     {
         if (Time.time - lastTickTime > HEART_BEAT_TIME)
         {
             Protocol.ProtocolBytes protocol = new Protocol.ProtocolBytes();
             protocol.AddString("HeartBeat");
             //ProtocolBase protocol = NetMgr.GetHeatBeatProtocol();
             Send(protocol);
             lastTickTime = Time.time;
         }
     }
 }
コード例 #2
0
 private void Init()
 {
     isBattleReady = false;
     conn.msgDist.AddListener("MatchCreate", (res) => {
         if (onMatchCreate != null)
         {
             onMatchCreate();
         }
     });
     conn.msgDist.AddListener("GameStart", (res) =>
     {
         isBattleReady = true;
         if (onGameStart != null)
         {
             onGameStart();
         }
     });
     conn.msgDist.AddListener("GameUpdate", (res) =>
     {
         if (onGameUpdate != null)
         {
             Protocol.ProtocolBytes protocol = (Protocol.ProtocolBytes)res;
             int start        = 0;
             string protoName = protocol.GetString(start, ref start);
             int frameNo      = protocol.GetInt(start, ref start);
             int input1       = protocol.GetInt(start, ref start);
             int input2       = protocol.GetInt(start, ref start);
             onGameUpdate(frameNo, new int[] { input1, input2 });
         }
     });
     conn.msgDist.AddListener("GameEnd", (res) => {
         isBattleReady = false;
         if (onGameEnd != null)
         {
             onGameEnd();
         }
     });
 }