Version: 2020.3
Method group is Obsolete


class in UnityEngine.Networking.Match





用于与 Unity Multiplayer 配对服务通信的组件。

该类将所有支持的 JSON 调用聚合为可针对 希望与 MatchMaker 服务交互的游戏调用的函数。

以下示例代码介绍如何使用 NetworkMatch API。

using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.Networking.Match;
using System.Collections.Generic;

public class SimpleMatchMaker : MonoBehaviour { void Start() { NetworkManager.singleton.StartMatchMaker(); }

//call this method to request a match to be created on the server public void CreateInternetMatch(string matchName) { NetworkManager.singleton.matchMaker.CreateMatch(matchName, 4, true, "", "", "", 0, 0, OnInternetMatchCreate); }

//this method is called when your request for creating a match is returned private void OnInternetMatchCreate(bool success, string extendedInfo, MatchInfo matchInfo) { if (success) { //Debug.Log("Create match succeeded");

MatchInfo hostInfo = matchInfo; NetworkServer.Listen(hostInfo, 9000);

NetworkManager.singleton.StartHost(hostInfo); } else { Debug.LogError("Create match failed"); } }

//call this method to find a match through the matchmaker public void FindInternetMatch(string matchName) { NetworkManager.singleton.matchMaker.ListMatches(0, 10, matchName, true, 0, 0, OnInternetMatchList); }

//this method is called when a list of matches is returned private void OnInternetMatchList(bool success, string extendedInfo, List<MatchInfoSnapshot> matches) { if (success) { if (matches.Count != 0) { //Debug.Log("A list of matches was returned");

//join the last server (just in case there are two...) NetworkManager.singleton.matchMaker.JoinMatch(matches[matches.Count - 1].networkId, "", "", "", 0, 0, OnJoinInternetMatch); } else { Debug.Log("No matches in requested room!"); } } else { Debug.LogError("Couldn't connect to match maker"); } }

//this method is called when your request to join a match is returned private void OnJoinInternetMatch(bool success, string extendedInfo, MatchInfo matchInfo) { if (success) { //Debug.Log("Able to join a match");

MatchInfo hostInfo = matchInfo; NetworkManager.singleton.StartClient(hostInfo); } else { Debug.LogError("Join match failed"); } } }



enabled启用的 Behaviour 可更新,禁用的 Behaviour 不可更新。
isActiveAndEnabled是否已激活并启用 Behaviour?
transform附加到此 GameObject 的 Transform。


BroadcastMessage调用此游戏对象或其任何子项中的每个 MonoBehaviour 上名为 methodName 的方法。
CompareTag此游戏对象是否使用 tag 进行了标记?
GetComponentReturns the component of Type type if the GameObject has one attached, null if it doesn't. Will also return disabled components.
GetComponentInChildren使用深度首次搜索返回 GameObject 或其任何子项中类型为 type 的组件。
GetComponentInParent返回 GameObject 或其任何父项中类型为 type 的组件。
GetComponents返回 GameObject 中类型为 type 的所有组件。
GetComponentsInChildrenReturns all components of Type type in the GameObject or any of its children. Works recursively.
GetComponentsInParent返回 GameObject 或其任何父项中类型为 type 的所有组件。
SendMessage调用此游戏对象中的每个 MonoBehaviour 上名为 methodName 的方法。
SendMessageUpwards调用此游戏对象中的每个 MonoBehaviour 上或此行为的每个父级上名为 methodName 的方法。