Exemplo n.º 1
0
        /// <summary>
        /// Evento que obtém dados relativos aos Frames disponibilizados pelo Sensor Kinect
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void KinectFramesReady(object sender, AllFramesReadyEventArgs e)
        {
            byte[] imagem = Util.ObterImagemSensorRGB(e.OpenColorImageFrame());

            if (imagem != null)
            {
                FrameChanged?.Invoke(GetImage(imagem), e.OpenSkeletonFrame().Validation());
            }

            GameFrames?.Invoke(this, e);
        }
Exemplo n.º 2
0
 //当场景以及物件全部加载完成,重新开局时
 public void OnBattleStart()
 {
     currentFrame    = null;
     Started         = true;
     LogicTurnIndex  = 0;
     LogicFrameIndex = 0;
     playRecord      = false;
     firstFrame      = true;
     actions.Clear();
     Main.Ins.FrameSync.Reset();
     if (Main.Ins.CombatData.GRecord != null)
     {
         Main.Ins.FrameSync.OnReceiveCommands(Main.Ins.CombatData.GRecord.frames);
     }
 }
    //套接口消息.
    public static void Update()
    {
        //处理网络消息
        for (int i = 0; i < packets.Count; i++)
        {
            Dictionary <int, byte[]> pack = packets[i];
            lock (pack)
            {
                MemoryStream ms = null;
                try
                {
                    foreach (var each in pack)
                    {
                        //UnityEngine.Debug.LogError(string.Format("收到:{0}", each.Key));
                        switch (each.Key)
                        {
                        case (int)MeteorMsg.MsgType.ProtocolVerifyRsp:
                            ms = new MemoryStream(each.Value);
                            ProtocolVerifyRsp rspVer = ProtoBuf.Serializer.Deserialize <ProtocolVerifyRsp>(ms);
                            OnVerifyResult(rspVer);
                            break;

                        case (int)MeteorMsg.MsgType.GetRoomRsp:
                            ms = new MemoryStream(each.Value);
                            GetRoomRsp rspG = ProtoBuf.Serializer.Deserialize <GetRoomRsp>(ms);
                            OnGetRoomRsp(rspG);
                            break;

                        case (int)MeteorMsg.MsgType.JoinRoomRsp:
                            ms = new MemoryStream(each.Value);
                            JoinRoomRsp rspJ = ProtoBuf.Serializer.Deserialize <JoinRoomRsp>(ms);
                            ClientJoinRoomRsp(rspJ);
                            break;

                        //case (int)MeteorMsg.MsgType.OnJoinRoomRsp:
                        //    ms = new MemoryStream(each.Value);
                        //    OnEnterRoomRsp rspE = ProtoBuf.Serializer.Deserialize<OnEnterRoomRsp>(ms);
                        //    OnEnterRoomRsp_(rspE);
                        //    break;
                        case (int)MeteorMsg.MsgType.CreateRoomRsp:
                            ms = new MemoryStream(each.Value);
                            CreateRoomRsp rspC = ProtoBuf.Serializer.Deserialize <CreateRoomRsp>(ms);
                            OnCreateRoomRsp(rspC);
                            break;

                        //case (int)MeteorMsg.MsgType.EnterLevelRsp:
                        //    ms = new MemoryStream(each.Value);
                        //    EnterLevelRsp rspER = ProtoBuf.Serializer.Deserialize<EnterLevelRsp>(ms);
                        //    EnterLevelRsp_(rspER);
                        //    break;
                        //case (int)MeteorMsg.MsgType.OnEnterLevelRsp:
                        //    ms = new MemoryStream(each.Value);
                        //    OnEnterLevelRsp rspOE = ProtoBuf.Serializer.Deserialize<OnEnterLevelRsp>(ms);
                        //    OnEnterLevelRsp_(rspOE);
                        //    break;
                        //case (int)MeteorMsg.MsgType.UserRebornSB2C:
                        //    ms = new MemoryStream(each.Value);
                        //    OnEnterLevelRsp rspReborn = ProtoBuf.Serializer.Deserialize<OnEnterLevelRsp>(ms);
                        //    OnUserRebornRsp_(rspReborn);
                        //    break;
                        //case (int)MeteorMsg.MsgType.OnLeaveRoomRsp:
                        //    ms = new MemoryStream(each.Value);
                        //    OnLeaveRoomRsp rspL = ProtoBuf.Serializer.Deserialize<OnLeaveRoomRsp>(ms);
                        //    OnLeaveRoomRsp_(rspL);
                        //    break;
                        case (int)MeteorMsg.MsgType.ChatInRoomRsp:
                            ms = new MemoryStream(each.Value);
                            ChatMsg chatRsp = ProtoBuf.Serializer.Deserialize <ChatMsg>(ms);
                            OnReceiveChatMsg(chatRsp);
                            break;

                        case (int)MeteorMsg.MsgType.AudioChat:
                            ms = new MemoryStream(each.Value);
                            AudioChatMsg audioRsp = ProtoBuf.Serializer.Deserialize <AudioChatMsg>(ms);
                            OnReceiveAudioMsg(audioRsp);
                            break;
                        //case (int)MeteorMsg.MsgType.UserDeadSB2C:
                        //    //Debug.LogError("OnUserDead");
                        //    ms = new MemoryStream(each.Value);
                        //    UserId userDeadRsp = ProtoBuf.Serializer.Deserialize<UserId>(ms);
                        //    OnUserDead(userDeadRsp);
                        //    break;

                        //case (int)MeteorMsg.MsgType.ExitQueueRsp:
                        //    OnExitQueue();
                        //    break;
                        case (int)MeteorMsg.MsgType.EnterQueueRsp:
                            OnEnterQueue();
                            break;

                        //帧同步信息-UDP
                        //收到服务器的帧同步信息.
                        case (int)MeteorMsg.MsgType.SyncCommand:
                            ms = new MemoryStream(each.Value);
                            GameFrames t = ProtoBuf.Serializer.Deserialize <GameFrames>(ms);
                            Main.Ins.FrameSync.OnReceiveCommand(t);
                            break;
                        }
                    }
                }
                catch (Exception exp)
                {
                    UnityEngine.Debug.LogError(exp.Message + exp.StackTrace);
                }
                finally
                {
                    pack.Clear();
                }
            }
        }

        lock (messageQueue)
        {
            int length = messageQueue.Count;
            for (int i = 0; i < length; i++)
            {
                switch (messageQueue[i].Message)
                {
                case (short)LocalMsgType.Connect: OnConnect(messageQueue[i].Result, messageQueue[i].message); break;

                case (short)LocalMsgType.DisConnect: OnDisconnect(); break;

                case (short)LocalMsgType.SendFTPLogComplete: OnSendComplete(messageQueue[i].Result, messageQueue[i].Param); break;

                case (short)LocalMsgType.GameStart: OnGameStart(); break;

                case (short)LocalMsgType.SaveRecord: OnSaveRecord(messageQueue[i]); break;

                case (short)LocalMsgType.PathCalcFinished: OnPathCalcFinished(messageQueue[i]); break;
                }
            }
            messageQueue.Clear();
        }
    }
    //看是自己挂了还是其他人挂了
    //static void OnUserDead(UserId id)
    //{
    //    if (id.Player != null)
    //    {
    //        for (int i = 0; i < id.Player.Count; i++)
    //        {
    //            MeteorUnit unit = U3D.GetUnit((int)id.Player[i]);
    //            if (unit == null)
    //                continue;
    //            if (unit != MeteorManager.Instance.LocalPlayer)
    //            {
    //                MeteorManager.Instance.OnNetRemoveUnit(unit);
    //            }
    //            else
    //            {
    //                //摄像机先禁用跟随.禁用
    //                //if (MeteorManager.Instance.LocalPlayer == null)
    //                //    return;
    //                MeteorManager.Instance.OnNetRemoveUnit(unit);
    //                if (CameraFollow.Ins != null)
    //                    CameraFollow.Ins.FreeCamera = true;
    //                MeteorManager.Instance.LocalPlayer = null;
    //                //向服务器发送复活请求.由服务器返回位置,然后在该位置创建角色
    //                ClientProxy.ReqReborn(NetWorkBattle.Ins.PlayerId);
    //            }
    //        }
    //    }
    //}

    //同步关键帧,全部角色的属性,都设置一次
    //在进入房间后开始接收此消息,有可能玩家还没进入战场,因为要选择角色和武器.
    //static void OnSyncKeyFrame(KeyFrame frame)
    //{
    //    if (NetWorkBattle.Ins.RoomId == -1)
    //    {
    //        Debug.LogError("退出房间后仍收到同步消息");
    //        return;
    //    }
    //    if (!NetWorkBattle.Ins.bSync && NetWorkBattle.Ins.TurnStarted)
    //    {
    //        NetWorkBattle.Ins.bSync = true;
    //        if (ReconnectWnd.Exist)
    //            ReconnectWnd.Instance.Close();
    //        if (GameBattleEx.Instance)
    //            GameBattleEx.Instance.Resume();
    //    }

    //    if (NetWorkBattle.Ins.TurnStarted && MeteorManager.Instance.LocalPlayer != null)
    //    {
    //        //在战场更新中,更新其他角色信息,自己的只上传.
    //        for (int i = 0; i < frame.Players.Count; i++)
    //        {
    //            MeteorUnit unit = NetWorkBattle.Ins.GetNetPlayer((int)frame.Players[i].id);
    //            if (unit != null && unit.InstanceId != MeteorManager.Instance.LocalPlayer.InstanceId)
    //            {
    //                //玩家同步所有属性
    //                NetWorkBattle.Ins.ApplyAttribute(unit, frame.Players[i]);
    //            }
    //        }
    //    }
    //    NetWorkBattle.Ins.OnPlayerUpdate((int)frame.frameIndex);
    //}

    //同步服务端发来的其他玩家的按键
    static void OnSyncRsp(GameFrames rsp)
    {
    }
Exemplo n.º 5
0
 //从服务器收到一个
 public void OnReceiveCommand(GameFrames frame)
 {
     frames.Add(frame);
 }
Exemplo n.º 6
0
    private void LogicFrame()
    {
        //得到当前逻辑帧数据,对普通事件数据,调用对应的事件函数,对按键,在更新每个对象使,应用到每个对象上.
        if (currentFrame == null)
        {
            //等待从服务器收到接下来一帧的信息.
            currentFrame = GetNextTurn(LogicTurnIndex);
            if (currentFrame == null)
            {
                //如果没有取得下一个回合的指令.能否继续
                //如果是联机或者回放-那么拿不到后面的操作指令是无法继续播放的
                if (Main.Ins.CombatData.GLevelMode == LevelMode.MultiplyPlayer || Main.Ins.CombatData.Replay)
                {
                    return;
                }
            }
        }
        else
        {
        }

        //update game-物理引擎更新.
        //SceneManager.Manager.TwoDPhysics.Update(GameFramesPerSecond);
        actions.Clear();
        if (currentFrame != null)
        {
            actions = GetAction(currentFrame.commands, LogicFrameIndex);
            for (int i = 0; i < actions.Count; i++)
            {
                switch (actions[i].command)
                {
                case MeteorMsg.Command.SyncRandomSeed:
                    SyncInitData seed = ProtoBuf.Serializer.Deserialize <SyncInitData>(new System.IO.MemoryStream(actions[i].data));
                    UnityEngine.Random.InitState((int)seed.randomSeed);
                    break;

                case MeteorMsg.Command.SpawnPlayer:
                    System.IO.MemoryStream ms  = new System.IO.MemoryStream(actions[i].data);
                    PlayerEventData        evt = ProtoBuf.Serializer.Deserialize <PlayerEventData>(ms);
                    Main.Ins.GameBattleEx.OnCreateNetPlayer(evt);
                    break;
                }
            }
        }

        NetUpdate();
        NetLateUpdate();
        LogicFrameIndex++;
        if (LogicFrameIndex % TurnFrameMax == 0)
        {
            Main.Ins.FrameSync.SyncTurn();
            LogicTurnIndex++;
            currentFrame    = null;
            LogicFrameIndex = 0;
        }
        if (firstFrame)
        {
            Main.Ins.DialogStateManager.ChangeState(null);//关闭loading条
            firstFrame = false;
        }
    }