示例#1
0
        private void Fill(int beginFrameId, int endFrameId, com.unity.mgobe.Room room)
        {
            if (!room.IsInRoom())
            {
                return;
            }
            Action <ResponseEvent> callback = (eve) =>
            {
                this._beginFrameId = beginFrameId;
                this._endFrameId   = endFrameId;
                if (eve.Code != ErrCode.EcOk)
                {
                    this._autoReqFrameErrTimes++;
                    if (this._autoReqFrameErrTimes <= 5)
                    {
                        this.Fill(beginFrameId, endFrameId, room);
                    }
                    else
                    {
                        room.OnAutoRequestFrameError?.Invoke(new BroadcastEvent(eve, ""));
                    }
                }
                else
                {
                    this._beginFrameId = -1;
                    this._endFrameId   = -1;

                    this._autoReqFrameErrTimes = 0;
                    var rsp   = (RequestFrameRsp)eve.Data;
                    var cache = new FrameCache(endFrameId);
                    foreach (var item in rsp.Frames)
                    {
                        var frame = new Frame
                        {
                            Id       = item.Id,
                            Ext      = item.Ext,
                            Time     = item.Time,
                            RoomId   = room.RoomInfo.Id,
                            IsReplay = true
                        };
                        frame.Items.AddRange(item.Items);
                        cache.Add(frame);
                    }
                    this._fillCache.Add(beginFrameId, cache);
                    this.FillSend(beginFrameId);
                }
            };
            RequestFramePara frameParam = new RequestFramePara
            {
                BeginFrameId = beginFrameId + 0,
                EndFrameId   = endFrameId + 0,
            };

            room.RequestFrame(frameParam, callback);
        }
示例#2
0
        public void SetRoomInfo(RoomInfo roomInfo)
        {
            // if(roomInfo!=null) Debugger.Log("setRoomInfo {0}", roomInfo.PlayerList);
            if (roomInfo == null)
            {
                roomInfo = new RoomInfo();
            }
            var oldRoomInfo = _room.RoomInfo ?? new RoomInfo();

            _room.RoomInfo = roomInfo;

            // 更新玩家信息
            if (_room.IsInRoom())
            {
                foreach (var info in _room.RoomInfo.PlayerList.Where(info => info.Id == RequestHeader.PlayerId))
                {
                    GamePlayerInfo.SetInfo((PlayerInfo)info);
                    break;
                }
            }

            // 重置帧广播信息:
            // 1 切换房间
            // 2 不存在房间id
            // 3 不在房间中
            // 4 房间的开始帧同步时间发生变化
            if (!oldRoomInfo.Id.Equals(_room.RoomInfo.Id) || string.IsNullOrEmpty(_room.RoomInfo.Id) || !_room.IsInRoom() || oldRoomInfo.StartGameTime != this._room.RoomInfo.StartGameTime)
            {
                _room.RoomBroadcast?.FrameBroadcastFrameIdReset(0);
            }

            // 激活第二条链接
            if (_room.RoomInfo != null && _room.RoomInfo.PlayerList != null)
            {
                if (_room.RoomInfo.PlayerList.Any(info => Listener.IsMe(info.Id)))
                {
                    this.ActiveFrame();
                }
            }
            _room.OnUpdate(this._room);
        }
示例#3
0
 public static bool IsInRoom()
 {
     return(Room != null && Room.IsInRoom());
 }