Пример #1
0
        /// <summary>
        /// 点击创建房间按钮
        /// </summary>
        private void OnCreateBtnClick()
        {
            var roomOptions = new RoomOptions
            {
                Visible              = true,
                MaxPlayerCount       = 8,
                EmptyRoomTtl         = 0, //房间人数为0,即刻销毁
                CustomRoomProperties = new PlayObject()
                {
                    ["PetName"]  = _petName,
                    ["RoomName"] = _nameInput.text
                },
                CustoRoomPropertyKeysForLobby = new List <string> {
                    "PetName", "RoomName"
                }
            };

            _netComponent.WebClient.CreateRoom(null, roomOptions).ContinueToForeground(t =>
            {
                if (t.IsFaulted)
                {
                    Debug.LogError($"创建房间失败,原因:{t.Exception}");
                    return;
                }

                _uiComponent.CloseView <CreateRoomView>();
                _uiComponent.CloseView <GameLobbyView>();
                _uiComponent.SyncOpenView <RoomView>();
            });
        }
Пример #2
0
        public IEnumerator JoinRandomWithMatchProperties()
        {
            var f        = false;
            var roomName = "jrt7_r";
            var c0       = Utils.NewClient("jrt7_0");
            var c1       = Utils.NewClient("jrt7_1");
            var c2       = Utils.NewClient("jrt7_2");
            var c3       = Utils.NewClient("jrt7_3");
            var c4       = Utils.NewClient("jrt7_2");

            var props = new PlayObject {
                { "lv", 2 }
            };

            c0.Connect().OnSuccess(_ => {
                var roomOptions = new RoomOptions {
                    MaxPlayerCount                 = 3,
                    CustomRoomProperties           = props,
                    CustomRoomPropertyKeysForLobby = new List <string> {
                        "lv"
                    }
                };
                return(c0.CreateRoom(roomName, roomOptions));
            }, TaskScheduler.FromCurrentSynchronizationContext()).Unwrap().OnSuccess(_ => {
                return(c1.Connect());
            }, TaskScheduler.FromCurrentSynchronizationContext()).Unwrap().OnSuccess(_ => {
                return(c1.JoinRandomRoom(props, new List <string> {
                    "jrt7_2"
                }));
            }, TaskScheduler.FromCurrentSynchronizationContext()).Unwrap().OnSuccess(_ => {
                return(c2.Connect());
            }, TaskScheduler.FromCurrentSynchronizationContext()).Unwrap().OnSuccess(_ => {
                return(c2.JoinRandomRoom(new PlayObject {
                    { "lv", 3 }
                }));
            }, TaskScheduler.FromCurrentSynchronizationContext()).Unwrap().ContinueWith(async t => {
                PlayException e = (PlayException)t.Exception.InnerException;
                Assert.AreEqual(e.Code, 4301);
                await c2.Close();
                return(c3.Connect());
            }, TaskScheduler.FromCurrentSynchronizationContext()).Unwrap().OnSuccess(t => {
                return(c3.JoinRandomRoom(props));
            }, TaskScheduler.FromCurrentSynchronizationContext()).Unwrap().ContinueWith(async t => {
                PlayException e = (PlayException)t.Exception.InnerException;
                Assert.AreEqual(e.Code, 4301);
                await c3.Close();
                return(c4.Connect());
            }, TaskScheduler.FromCurrentSynchronizationContext()).Unwrap().OnSuccess(_ => {
                return(c4.JoinRandomRoom(props));
            }, TaskScheduler.FromCurrentSynchronizationContext()).Unwrap().OnSuccess(async _ => {
                await c0.Close();
                await c1.Close();
                await c4.Close();
                f = true;
            }, TaskScheduler.FromCurrentSynchronizationContext());

            while (!f)
            {
                yield return(null);
            }
        }