Esempio n. 1
0
 public void HandleLoadingProcess()
 {
     if (!m_bRunning)
     {
         return;
     }
     if (m_bSendLoaded)
     {
         return;
     }
     // 进度完成,直接再发送一次
     if (SceneManager.Inst.GetMapLoadProcess().fPercent >= 1.0f)
     {
         m_bSendLoaded      = true;
         m_sendProgressTime = 1;
         // 进度加载完成,发送可以控制
         FspMsgStartControl msg = (FspMsgStartControl)NetManager.Inst.GetMessage(eNetMessageID.FspMsgStartControl);
         FspNetRunTime.Inst.SendMessage(msg);
         return;
     }
     // 场景加载进度不用帧指令,间隔发送
     m_sendProgressTime += Time.deltaTime;
     if (m_sendProgressTime >= 1)
     {
         m_sendProgressTime = 0;
         FspMsgLoadProgress msg = (FspMsgLoadProgress)NetManager.Inst.GetMessage(eNetMessageID.FspMsgLoadProgress);
         msg.m_progress = SceneManager.Inst.GetMapLoadProcess().fPercent;
         FspNetRunTime.Inst.SendMessage(msg);
     }
 }
Esempio n. 2
0
        private void HandleState()
        {
            switch (m_state)
            {
            case FspGameState.None:
                // 清空所有数据
                break;

            case FspGameState.Create:
                m_state = FspGameState.SelectRole;
                break;

            case FspGameState.SelectRole:
                // 时间到,或者都准备了,开始下一个状态
                foreach (Player item in m_listPlayer)
                {
                    if (!item.tempData.bReady)
                    {
                        return;
                    }
                }
                // 组合要发送的玩家信息
                int[] sendData = new int[m_listPlayer.Count];
                for (int i = 0; i < m_listPlayer.Count; i++)
                {
                    sendData[i] = (int)m_listPlayer[i].id;
                }
                // 通知客户端开始加载游戏
                foreach (Player item in m_listPlayer)
                {
                    FspMsgPlayerData msg = (FspMsgPlayerData)NetManager.Inst.GetMessage(eNetMessageID.FspMsgPlayerData);
                    msg.m_sendData = sendData;
                    FspNetRunTime.Inst.Send(item.conn, msg);
                }
                m_state = FspGameState.StartLoad;
                break;

            case FspGameState.StartLoad:
                if (m_listPlayer.Count == 0)
                {
                    return;
                }
                // 临时组合要发送的玩家进度
                float[] progress = new float[m_listPlayer.Count];
                for (int i = 0; i < m_listPlayer.Count; i++)
                {
                    progress[i] = (int)m_listPlayer[i].tempData.m_loadProgress;
                }
                foreach (Player item in m_listPlayer)
                {
                    FspMsgLoadProgress msg = (FspMsgLoadProgress)NetManager.Inst.GetMessage(eNetMessageID.FspMsgLoadProgress);
                    msg.m_sendProgress = progress;
                    FspNetRunTime.Inst.Send(item.conn, msg);
                }
                foreach (Player item in m_listPlayer)
                {
                    if (!item.tempData.bLoaded)
                    {
                        return;
                    }
                }
                Console.WriteLine("接受玩家全部加载完成 发送开始控制");
                // 如果都加载完成,就发送开始控制,正式时可附带信息
                foreach (Player item in m_listPlayer)
                {
                    FspMsgStartControl msg = (FspMsgStartControl)NetManager.Inst.GetMessage(eNetMessageID.FspMsgStartControl);
                    FspNetRunTime.Inst.Send(item.conn, msg);
                }
                m_state = FspGameState.StartControl;
                break;

            case FspGameState.StartControl:

                break;
            }
        }