PhotonNetwork.GetCustomRoomList使用方法

看到很多博客说PhotonNetwork.GetCustomRoomList()的第二个参数给null,但实际这个方法内部存在null判断,会进行报错。

public static bool GetCustomRoomList(TypedLobby typedLobby, string sqlLobbyFilter)

查看官方文档可知,第二个参数sqlLobbyFilter是一个SQL。

示例:

public class GameProperties
{
        public const string CustomRoomProperties0="C0";
        public const string CustomRoomProperties1="C1";
        public const string CustomRoomProperties2="C2";
        public const string CustomRoomProperties3="C3";
        public const string CustomRoomProperties4="C4";
        public const string CustomRoomProperties5="C5";
        public const string CustomRoomProperties6="C6";
        public const string CustomRoomProperties7="C7";
        public const string CustomRoomProperties8="C8";
        public const string CustomRoomProperties9="C9";

        public const string TypedLoabbyName = "XXX_SqlLobby";
        public const string SqlLobbyFilter = "XXX_Room";
} 

public void CreateRoom()
{
        //创建房间
        RoomOptions options = new RoomOptions { MaxPlayers = CONST_MAXPLAYERS };
        //Only integer-typed and string-typed values are allowed and once a value was assigned to any column in a specific lobby
        //只允许使用整数类型和字符串类型的值,一旦将值分配给特定大厅中的任何列,此列就会锁定为该类型的值。
        //所以在这里给需要使用的SQL过滤属性进行赋值
        options.CustomRoomProperties = new Hashtable() { { GameProperties.CustomRoomProperties0, GameProperties.SqlLobbyFilter } };
        //列出所需要使用的SQL filtering properties
        options.CustomRoomPropertiesForLobby = new string[] { GameProperties.CustomRoomProperties0 };
        PhotonNetwork.CreateRoom(roomName, options, new TypedLobby(GameProperties.TypedLoabbyName, LobbyType.SqlLobby));
}

public void RefreshRoomList()
{
        //调用刷新房间列表
        PhotonNetwork.GetCustomRoomList(new TypedLobby(GameProperties.TypedLoabbyName, LobbyType.SqlLobby), $"{GameProperties.CustomRoomProperties0}='{GameProperties.SqlLobbyFilter}'");
}

调用虽然成功了,但有可能因为LobbyType.SqlLobby类型的房间是不会自动触发public override void OnRoomListUpdate(List<RoomInfo> roomList)回调的。需要调用RefreshRoomList()后才会触发。

并且很关键的一点,当有玩家从房间退出后的短时间内,无论时自动还是通过调用PhotonNetwork.GetCustomRoomList来刷新房间列表,都不会获取到房间人数减少。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值