Exemplo n.º 1
0
    void Message_Battle_Start(UdpBattleStartMessage msg)
    {
        if (isBattleStart)
        {
            return;
        }

        isBattleStart = true;
        this.CancelInvoke(nameof(Send_BattleReady));

        float _time = ClientGlobal.FrameTime * 0.001f;              // 66ms

        this.InvokeRepeating(nameof(Send_Operation), _time, _time); // 循环调用Send_Operation方法

        StartCoroutine(WaitForFirstMessage());
    }
Exemplo n.º 2
0
    private void Thread_SendFrameData()
    {
        //向玩家发送战斗开始
        bool isFinishBS = false;

        while (!isFinishBS)
        {
            UdpBattleStartMessage _bt = new UdpBattleStartMessage();
            Protocol protocol         = new Protocol(_bt);
            foreach (var item in dic_udp.Values)
            {
                item.SendMessage(protocol);
            }

            bool _allData = true;
            for (int i = 0; i < frameOperation.Length; i++)
            {
                if (frameOperation[i] == null)
                {
                    _allData = false;  //   有一个玩家没有发送上来操作,则判断为false
                    break;
                }
            }

            if (_allData)
            {
                Debug.Log("战斗服务器:收到全部玩家的第一次操作数据");
                frameNum = 1;

                isFinishBS = true;
            }

            Thread.Sleep(500);
        }

        Debug.Log("开始发送帧数据");

        while (isRun)
        {
            UdpDownFrameOperations _ops = new UdpDownFrameOperations();
            //Debug.Log("服务器转发帧数据");
            if (oneGameOver)
            {
                _ops.FrameID = lastFrame;
                _ops.Ops     = dic_gameOperation[lastFrame];
            }
            else
            {
                _ops.Ops.Operations.AddRange(frameOperation);
                _ops.FrameID = frameNum;
                dic_gameOperation[frameNum] = _ops.Ops;
                lastFrame = frameNum;
                frameNum++;

                Protocol protocol = new Protocol(_ops);
                foreach (var item in dic_udp)
                {
                    int _index = item.Key - 1;
                    if (!playerGameOver[_index])
                    {
                        item.Value.SendMessage(protocol);
                    }
                }
            }

            Thread.Sleep(ServerConfig.FRAME_TIME);
        }

        Debug.Log("帧数据发送线程结束.....................");
    }