Matchmaking & Room Properties 匹配和房间属性
Getting into a room to play with (or against!) someone else is very easy with Photon. The workflow described here gets players into rooms without asking them to pick one (randomly) from a long list of rooms.
在Photon上加入一个多人的房间是非常容易的。下面的工作流描述了玩家随机的进入房间,而不是在房间的长列表中选择。
Random Matchmaking 随机匹配
If you just want to get some players into a room quickly, do the following:
如果你仅仅想快速加入一个多人房间:
- Try “Join Random”. This is an operation (named OpJoinRandom or JoinRandomRoom, depending on the API / platform).
-
- In best case, that’s it. Your client will join a room successfully.
-
- In worst case, no room is existing or no space is left in any room.
-
- If this doesn’t find a room instantly, create one!
-
- If you never show room names (and why should you), don’t make up a name. Let the server do this! Set null or “” as “room name” when calling OpCreateRoom. The room gets a guid which is unique.
-
- 如果你从不显示房间的名称,不要生成一个名字,让服务器去做这个,当调用OpCreateRoom时设置null或者“”作为你房间的名字,只有房间的guid是唯一的。
- Apply a value for “max players”. This way, the server eventually stops adding players.
-
- 应用一个值为 “max players”。这样,服务器将停止添加玩家。
- If your client is alone in the room (players == 1): Wait. Show a screen you’re waiting for opponents.
-
- 如果你的客户端是房间里唯一的玩家,请等待,屏幕上显示等待。
- When enough players are in the room, you might “start” the game. To keep new players out, “close” the room. The server stops filling up the room, even if it’s not full yet.
-
- 当有足够的玩家时,你可以开始游戏。保持房间关闭,新玩家无法再加入,服务器停止添加玩家到房间,即使房间是未满的。
- Note: When you close the room, there is a short time where players maybe are already on the way in. Don’t be surprised if someone joins even after closing.
-
- 注意:当你关闭房间时,有一个短暂的时间,玩家也许已经加入了。不要惊讶,即使是有人在关闭后加入。
Not so random matchmaking 非随机配对
Totally random matchmaking is not always something players will enjoy. Sometimes you just want to play a certain map or mode (two versus two, etc.).In Photon Cloud and Loadbalancing, you can set arbitrary room properties and filter for those in
JoinRandom.
完全随机配对并不总是一些玩家想要的。有时候你只是想玩一个特定的地图或模式(两个与两个,等等)。在Photon云和Loadbalancing中,你可以为JoinRandom设置任意的房间属性和过滤器。
Room Properties and the Lobby 房间属性和大厅
Room properties are synced to all players in the room and can be useful to keep track of the current map, round, starttime, etc. They are handled as Hashtable with string keys. Preferably short keys.You can forward selected properties to the lobby, too. This makes them available for listing them and for random matchmaking, too. Not all room properties are interesting in the lobby, so you define the set of properties for the lobby on room creation.
房间属性是同步到所有房间中的玩家,可能是有用的去跟踪当前的地图、圆形、starttime等等。他们正在处理字符串键值的散列表,最好是短键。你可以为大厅提供属性。这使它们可提供房间清单和随机配对。并不是所有的房间属性都适合于大厅,所以你需要为大厅定义属性集合。
string
[] roomPropsInLobby = {
"map"
,
"ai"
};
Hashtable customRoomProperties =
new
Hashtable() { {
"map"
, 1 } };
CreateRoom(roomName,
true
,
true
, 4, customRoomProperties, roomPropsInLobby);
Note that “ai” has no value yet. It won’t show up in the lobby until it’s set in the game via
Room.SetCustomProperties. When you change the values for “map” or “ai”, they will be updated in the lobby with a short delay, too.Keep the list short to make sure your clients performance doesn’t suffer from loading the list.
注意:“AI”还没有价值。它不会出现在大厅,直到它的设置在游戏大厅中通过 Room.SetCustomProperties 。当你改变值为“map”或“AI”,他们将被更新在大厅,略有短延迟。保持短列表来确保你的客户端性能不受来自加载列表的影响。
Filtering Room Properties in Join Random 在随机加入时过滤房间的属性
In
JoinRandom, you could pass a Hashtable with expected room properties and max player value. These work as filters when the server selects a “fitting” room for you.
在 JoinRandom 时,你可以传递一个Hashtable,包括了已知的房间属性和最大玩家的值。当服务器选择一个“装配”房间给你时这些工作即为过滤器。
Hashtable expectedCustomRoomProperties =
new
Hashtable() { {
"map"
, 1 } };
JoinRandomRoom(expectedCustomRoomProperties, 4);
If you pass more filter properties, chances are lower that a room matches them. Better limit the options.Make sure you never filter for properties that are not known to the lobby (see above).
如果你传递更多的过滤器属性,房间匹配的选择更少。更好的限制这个选项,可确保你永远不会通过未知大厅的过滤器。