netId | 要加入的匹配的 NetworkID。该 ID 可通过调用 NetworkMatch.ListMatches 并从返回的匹配列表中选取结果找到。 |
matchPassword | 匹配的密码。如果匹配没有密码,则保留空白;如果匹配配置了 NetworkMatch.CreateMatch 请求之一,则提供文本字符串密码。 |
publicClientAddress | 可选的公用客户端地址。此值将存储在配对上,并提供给列出匹配的其他客户端。如果您希望玩家能够通过 Internet 直接相互连接,则应发送此值。或者,您可以传递一个空字符串,这将不会影响与配对连接或使用 Relay Server 的能力。 |
privateClientAddress | 可选的专用客户端地址。此值将存储在配对上,并提供给列出匹配的其他客户端。如果您希望玩家能够通过局域网直接相互连接,则应发送此值。或者,您可以传递一个空字符串,这将不会影响与配对连接或使用 Relay Server 的能力。 |
eloScoreForClient | 加入正在创建的匹配的客户端的 Elo 得分。如果已在所有客户端上设置此数值以指示相对技能等级,则此数值用于返回匹配并按对游戏(已提供所列玩家的技能等级)的适合程度由高到低排序。可以在所有客户端上将此值设置为 0,这会禁用 MatchMaker 中的任何 Elo 计算。 |
requestDomain | 此请求的请求域。只有同一域中的请求可以相互连接。例如,如果使用域 1 创建 NetworkMatch.CreateMatch,则只有也指定了域 1 的 ListMatches 才能找到该匹配。使用此值来接收不同(可能不兼容)的客户端版本。 |
callback | 将在此调用完成时调用的回调。 |
Coroutine 这是一个异步函数,将在未来某个时刻(即协程结束与服务后端的通信时)完成。
该函数用于告知 MatchMaker,当前客户端想要加入一个指定匹配。
从对 NetworkMatch.ListMatches 的调用获得结果并选择要加入的匹配后,应调用此函数。收到此请求后,MatchMaker 将在该匹配正在对话的 Relay Server 上保留一个席位,并获取该客户端连接至 Relay Server 所需的信息。一旦回调完成,该客户端将有必要继续连接至选择的匹配。为此,您应该使用传入的 MatchInfo 调用 StartClient()。
using UnityEngine; using UnityEngine.Networking; using UnityEngine.Networking.Match; using UnityEngine.Networking.Types;
public class ExampleScript : MonoBehaviour { public NetworkID netId;
void Start() { NetworkManager.singleton.StartMatchMaker(); NetworkManager.singleton.matchMaker.JoinMatch(netId, "" , "", "", 0, 0, OnMatchJoined); }
public void OnMatchJoined(bool success, string extendedInfo, MatchInfo matchInfo) { // ... } }
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.