matchName | 描述此匹配的名称的文本字符串。 |
matchSize | 创建匹配时,配对将使用此值或者您在 https://multiplayer.unity3d.com, 中在线配置的最大大小(以较低者为准)。这样,您就可以为特定游戏指定不同的匹配大小,但仍在在线控制面板中保持总体大小限制。 |
matchAdvertise | 指示此匹配是否应在 NetworkMatch.ListMatches 结果中可用的布尔值。 |
matchPassword | 指示此匹配是否受密码保护的文本字符串。如果是,则尝试加入此匹配的所有客户端都必须提供正确的匹配密码。 |
publicClientAddress | 可选的公用客户端地址。该值存储在配对上并会提供给列出匹配的客户端。该地址应为用于直接通过 Internet 连接到此客户端的网络地址。只有在已知公用地址且配对支持直接连接时,此值才会存在。 |
privateClientAddress | 可选的专用客户端地址。该值存储在配对上并会提供给列出匹配的客户端。该地址应为用于通过局域网直接连接到该客户端的网络地址。只有在配对支持直接连接时,此值才会存在。这可能是一个空字符串,并且不会影响与配对连接或使用 Relay Server 的能力。 |
eloScoreForMatch | 托管所创建匹配的客户端的 Elo 得分。如果已在所有客户端上设置此数值以指示相对技能等级,则此数值用于返回匹配并按对游戏(已提供所列玩家的技能等级)的适合程度由高到低排序。可以在所有客户端上将此值设置为 0,这会禁用 MatchMaker 中的任何 Elo 计算。 |
requestDomain | 此请求的请求域。只有同一域中的请求可以相互连接。例如,如果使用域 1 创建 NetworkMatch.CreateMatch,则只有也指定了域 1 的 ListMatches 才能找到该匹配。使用此值来接收不同(可能不兼容)的客户端版本。 |
callback | 将在此函数完成时调用的回调。无论函数执行成功还是失败,都会进行调用。 |
Coroutine 这是一个异步函数,将在未来某个时刻(即协程结束与服务后端的通信时)完成。
使用此函数创建一个新匹配。调用此函数的客户端会成为匹配的主机。
创建匹配时,您应该调用此函数并等待调用回调,然后再继续操作。回调将指示调用是否成功,并针对失败情况提供扩展信息。收到响应回调后,您应该使用传入的 MatchInfo 调用 StartHost()。
using UnityEngine; using UnityEngine.Networking; using UnityEngine.Networking.Match;
public class ExampleScript : MonoBehaviour { void Start() { NetworkManager.singleton.StartMatchMaker(); NetworkManager.singleton.matchMaker.CreateMatch("roomName", 4, true, "", "", "", 0, 0, OnMatchCreate); }
public void OnMatchCreate(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.