Exemple #1
0
        public void TestJson()
        {
//            SyncPosRotate syncPosRotateS = new SyncPosRotate();
//            syncPosRotateS.id = "ddddd";
//            syncPosRotateS.px = 1.0f;
//            syncPosRotateS.py = 1.0f;
//            syncPosRotateS.pz = 1.0f;
//            syncPosRotateS.rx = 1.0f;
//            syncPosRotateS.ry = 1.0f;
//            syncPosRotateS.rz = 1.0f;
//            syncPosRotateS.type = SyncType.VirtualMan;
//            syncPosRotateS.time = TimeHelper.GetTimestamp();
//
//
//            int structSize = Marshal.SizeOf(typeof(SyncPosRotate));
//            byte[] buffer = EncodeStruct<SyncPosRotate>(syncPosRotateS);
//
//            SyncPosRotate rs = DecodeStruct<SyncPosRotate>(buffer);



            JoinRoom join = new JoinRoom();

            join.id        = (int)NetCmdId.JoinRoom;
            join.data      = new JoinRoom.ResultBean();
            join.data.uid  = "";
            join.data.rid  = "";
            join.data.role = (int)ClientType.Hololens;

            string json = JsonConvert.SerializeObject(join);


            join = JsonConvert.DeserializeObject <JoinRoom>(json);


            JoinRoomRes joinRes = new JoinRoomRes();

            joinRes.id             = (int)NetCmdId.JoinRoomRes;
            joinRes.data           = new JoinRoomRes.ResultBean();
            joinRes.data.isCreator = 1;
            joinRes.data.roomCache = new Dictionary <string, string[]>();
            string[] values = { "anchor1", "anchor2" };
            joinRes.data.roomCache.Add(RoomCacheKey.RoomCacheKeyAnchor, values);

            json = JsonConvert.SerializeObject(joinRes);



            Debug.Log("");
        }
Exemple #2
0
        private void Mqtt_OnReceiveMsg(MqttHelper mqtt, string msg)
        {
            Debug.Log("Mqtt_OnReceiveMsg:" + msg);
            string roomId = "";

            if (mqtt == spectatorViewMqtt)
            {
                roomId = spectatorViewRid;
            }
            else
            {
                roomId = virtualManRid;
            }
            CmdHeader header = JsonConvert.DeserializeObject <CmdHeader>(msg);

            switch ((NetCmdId)header.id)
            {
            case NetCmdId.None:
                break;

            case NetCmdId.JoinRoom:     //加入房间请求
                break;

            case NetCmdId.JoinRoomRes:     //加入房间应答
                if (mqtt == spectatorViewMqtt)
                {
                    IsInSpectatorViewRoom = true;
                }
                else
                {
                    IsInVirtualManRoom = true;
                }
                JoinRoomRes joinRoomRes = JsonConvert.DeserializeObject <JoinRoomRes>(msg);
                onJoinRoom?.Invoke(roomId, true, joinRoomRes.data.isCreator == (int)YesOrNot.YES,
                                   joinRoomRes.data.roomCache, joinRoomRes.data.uids);

                break;

            case NetCmdId.LeaveRoom:     //离开房间请求
                break;

            case NetCmdId.UserEnterRoom:     //用户加入房间通知
                UserEnterRoom userEnterRoom = JsonConvert.DeserializeObject <UserEnterRoom>(msg);
                onUserEnter?.Invoke(roomId, userEnterRoom.data.uid);
                break;

            case NetCmdId.UserLeaveRoom:     //用户离开房间通知
                UserLeaveRoom userLeaveRoom = JsonConvert.DeserializeObject <UserLeaveRoom>(msg);
                onUserLeave?.Invoke(roomId, userLeaveRoom.data.uid);

                break;

            case NetCmdId.SendCmmond:     //发送命令
                //SendCommend sendCommend = JsonConvert.DeserializeObject<SendCommend>(msg);
                //onReceiveCmdFunc(roomId, sendCommend.data.cmd);
                break;

            case NetCmdId.SaveRoomCache:     //锚点数据上传完成
                break;

            case NetCmdId.GetRoomCacheRes:
                GetRoomCacheRes cmd = JsonConvert.DeserializeObject <GetRoomCacheRes> (msg);
                onRoomCache?.Invoke(cmd.data.rid, cmd.data.roomCache);
                break;
            }
        }