Note: UNet is deprecated, and will be removed from Unity in the future. A new system is under development. For more information and next steps see this blog post and the FAQ. |
Matchmaker 模式提供了一个简单的界面让玩家创建、查找和加入 Unity Multiplayer 服务上托管的比赛。
“比赛”(有时也称为游戏会话或游戏实例)是由 Unity Multiplayer 服务托管的游戏的独特实例。使用 Unity Multiplayer 服务,一定数量的玩家可以加入并一起玩游戏。如果有很多玩家玩游戏,可能会有多个比赛,每个比赛都有多个玩家一起玩。
In order to use Matchmaker mode, you must first enable Unity Multiplayer Service for your project. Once you have enabled Unity Multiplayer Service for your project, you can use the HUD in Matchmaker mode to create or connect to instances of your game (also sometimes referred to as “matches” or “sessions”) hosted on the internet.
单击 Create Internet Match 可开始新的比赛。Unity 的 Multiplayer 服务会创建一个新的游戏实例(“比赛”),然后其他玩家可以找到并加入该游戏实例。
Click Find Internet Match to send a request to the Unity Multiplayer Service. The Unity Multiplayer Service returns a list of all matches that currently exist for this game.
For example, if two separate players connect, and create a match each named “Match A” and “Match B” respectively, when a third player connects and presses the Find Internet Match button, Match A and Match B are listed as available matches to join.
In the Network manager HUD, the available matches appear as a series of buttons, with the text “Join Match: match name” (where match name is the name chosen by the player who created the match).
要加入其中一个可用的比赛,请单击该比赛的“Join Match: match name”按钮。或者,单击 Back to Match Menu 返回到 Matchmaker 菜单。
When you replace the HUD with your own UI, there are better ways to list the available matches. Many multiplayer games display available matches in a scrollable list. You might want to make each entry on the list show the match name, the current and maximum number of players, and other information such as the match mode type, if your decide to make your game have different match modes (such as “capture the flag”, “1 vs 1”, or “cooperative”).
注意:有一些特殊字符,如果在比赛名称中使用这些字符,Network Manager HUD 中的可用比赛列表中会修改这些字符。这些字符包括:
左方括号:[
百分比符号:%
下划线:_
If a match name contains these characters, they are surrounded by square braces in the list of available matches. So a match named “my_game” is listed as “my[_]game”.
This button is designed for internal use by Unity engineers (for testing the Multiplayer service). It reveals buttons which assign one of three pre-defined URLs to the MatchMaker Host URI field in the Network Manager - “local”, “staging” and “internet”. However, the “local” and “staging”** *options are only intended for internal use by Unity engineers, and not intended for general use*.
If you select the “local” or “staging” options, your game cannot connect to Unity’s Multiuser Service. Therefore you should always make sure this option is set to “internet” (which is the default).
此处显示当前的 Matchmaker URI(统一资源标识符,用于标识作用的字符串)。要在 Inspector 中查看 URI,请导航到 Network Manager 组件并查看 MatchMaker Host URI 字段。默认情况下,此字段指向全局 Unity Multiplayer 服务,用于使用 Unity Multiplayer 服务的普通多人游戏。不需要更改此字段。Unity Multiplayer 服务自动将游戏玩家分组到全球的区域服务器。这种分组方式确保了在多人游戏中同一地区的玩家之间实现快速响应,因此,来自欧洲、美国和亚洲的玩家通常最终会与来自同一区域的其他玩家一起玩游戏。
如果要显式控制游戏连接到的区域服务器,请通过编写脚本来重写此值。要了解更多信息和区域服务器 URI,请参阅有关 NetworkMatch.baseUri 的 API 参考文档。
For example, you might want to override the URI if you want to give your players the option of joining a server outside of their global region. If “Player A” in the US wants to connect to a match created via Matchmaker by “Player B” in Europe, they would need to be able to set their desired global region in your game. Therefore you would need to write a UI feature which allows them to select this.
注意:请记住,Network Manager HUD 功能是针对开发的临时辅助功能。此组件允许您快速运行多人游戏,但在准备就绪之后应将其替换为您自己的 UI 控件。