Version: 2021.2
Method group is Obsolete

NetworkMatch

class in UnityEngine.Networking.Match

/

继承自:MonoBehaviour

切换到手册
Obsolete

描述

用于与 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 不可更新。
isActiveAndEnabledReports whether a GameObject and its associated Behaviour is active and enabled.
gameObject此组件附加到的游戏对象。始终将组件附加到游戏对象。
tag此游戏对象的标签。
transform附加到此 GameObject 的 Transform。
runInEditMode允许 MonoBehaviour 的特定实例在编辑模式下运行(仅可在 Editor 中使用)。
useGUILayout禁用该属性可跳过 GUI 布局阶段。
hideFlags该对象应该隐藏、随场景一起保存还是由用户修改?
name对象的名称。

公共函数

BroadcastMessage调用此游戏对象或其任何子项中的每个 MonoBehaviour 上名为 methodName 的方法。
CompareTagChecks the GameObject's tag against the defined tag.
GetComponentReturns the component of type if the GameObject has one attached.
GetComponentInChildrenReturns the Component of type in the GameObject or any of its children using depth first search.
GetComponentInParentReturns the Component of type in the GameObject or any of its parents.
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 的方法。
TryGetComponent获取指定类型的组件(如果存在)。
CancelInvoke取消该 MonoBehaviour 上的所有 Invoke 调用。
Invoke在 time 秒后调用 methodName 方法。
InvokeRepeating在 time 秒后调用 methodName 方法,然后每 repeatRate 秒调用一次。
IsInvoking是否有任何待处理的 methodName 调用?
StartCoroutine启动协程。
StopAllCoroutines停止在该行为上运行的所有协同程序。
StopCoroutine停止在该行为上运行的第一个名为 methodName 的协同程序或存储在 routine 中的协同程序。
GetInstanceIDGets the instance ID of the object.
ToString返回对象的名称。

静态函数

print将消息记录到 Unity 控制台(与 Debug.Log 相同)。
Destroy移除 GameObject、组件或资源。
DestroyImmediate立即销毁对象 /obj/。强烈建议您改用 Destroy。
DontDestroyOnLoad在加载新的 Scene 时,请勿销毁 Object。
FindObjectOfType返回第一个类型为 type 的已加载的激活对象。
FindObjectsOfTypeGets a list of all loaded objects of Type type.
Instantiate克隆 original 对象并返回克隆对象。

运算符

bool该对象是否存在?
operator !=比较两个对象是否引用不同的对象。
operator ==比较两个对象引用,判断它们是否引用同一个对象。

消息

AwakeAwake 在加载脚本实例时调用。
FixedUpdate用于物理计算且独立于帧率的 MonoBehaviour.FixedUpdate 消息。
LateUpdate如果启用了 Behaviour,则每帧调用 LateUpdate。
OnAnimatorIK用于设置动画 IK(反向运动学)的回调。
OnAnimatorMove用于处理动画移动以修改根运动的回调。
OnApplicationFocus当玩家获得或失去焦点时,发送给所有 GameObject。
OnApplicationPause当应用程序暂停时,发送给所有 GameObject。
OnApplicationQuitSent to all GameObjects before the application quits.
OnAudioFilterRead如果实现了 OnAudioFilterRead,Unity 将在音频 DSP 链中插入一个自定义滤波器。
OnBecameInvisibleOnBecameInvisible 在渲染器对任何摄像机都不可见时调用。
OnBecameVisibleOnBecameVisible 在渲染器变为对任意摄像机可见时调用。
OnCollisionEnter当该碰撞体/刚体已开始接触另一个刚体/碰撞体时,调用 OnCollisionEnter。
OnCollisionEnter2D当传入碰撞体与该对象的碰撞体接触时发送(仅限 2D 物理)。
OnCollisionExit当该碰撞体/刚体已停止接触另一个刚体/碰撞体时,调用 OnCollisionExit。
OnCollisionExit2D当另一个对象上的碰撞体停止接触该对象的碰撞体时发送(仅限 2D 物理)。
OnCollisionStayOnCollisionStay is called once per frame for every Collider or Rigidbody that touches another Collider or Rigidbody.
OnCollisionStay2D在另一个对象上的碰撞体正在接触该对象的碰撞体时发送每个帧(仅限 2D 物理)。
OnConnectedToServer成功连接到服务器后在客户端上调用。
OnControllerColliderHit当该控制器在执行 Move 时撞到碰撞体时调用 OnControllerColliderHit。
OnDestroy销毁附加的行为将导致游戏或场景收到 OnDestroy。
OnDisable该函数在行为被禁用时调用。
OnDisconnectedFromServer当连接丢失或与服务器断开连接时,在客户端上调用。
OnDrawGizmos如果您想绘制能够选择并且始终绘制的辅助图标,则可以实现 OnDrawGizmos。
OnDrawGizmosSelected如果选择了对象,则实现 OnDrawGizmosSelected 来绘制辅助图标。
OnEnable该函数在对象变为启用和激活状态时调用。
OnFailedToConnect出于某种原因连接尝试失败时,在客户端上调用。
OnFailedToConnectToMasterServer在连接到 MasterServer 时发生问题的情况下,在客户端或服务器上调用。
OnGUI系统调用 OnGUI 来渲染和处理 GUI 事件。
OnJointBreak在附加到相同游戏对象的关节断开时调用。
OnJointBreak2D在附加到相同游戏对象的 Joint2D 断开时调用。
OnMasterServerEvent在从 MasterServer 报告事件时,在客户端或服务器上调用。
OnMouseDown当用户在 Collider 上按下鼠标按钮时,将调用 OnMouseDown。
OnMouseDrag当用户单击 Collider 并仍然按住鼠标时,将调用 OnMouseDrag。
OnMouseEnter当鼠标进入 Collider 时调用。
OnMouseExit当鼠标不再处于 Collider 上方时调用。
OnMouseOver当鼠标悬停在 Collider 上时,每帧调用一次。
OnMouseUp当用户松开鼠标按钮时,将调用 OnMouseUp。
OnMouseUpAsButton松开鼠标时,仅当鼠标在按下时所在的 Collider 上时,才调用 OnMouseUpAsButton。
OnNetworkInstantiate在已通过 Network.Instantiate 进行网络实例化的对象上调用。
OnParticleCollision当粒子击中碰撞体时,将调用 OnParticleCollision。
OnParticleSystemStopped系统中的所有粒子都死亡时,便会调用 OnParticleSystemStopped,然后将不再产生新粒子。在调用 Stop 之后,或者超过非循环系统的 Duration 属性时,将停止产生新粒子。
OnParticleTrigger粒子系统中的任何粒子满足触发模块中的条件时,将调用 OnParticleTrigger。
OnParticleUpdateJobScheduled调度粒子系统的内置更新作业时,会调用 OnParticleUpdateJobScheduled。
OnPlayerConnected每当有新玩家成功连接,就在服务器上调用。
OnPlayerDisconnected每当有玩家与服务器断开连接,就在服务器上调用。
OnPostRender Event function that Unity calls after a Camera renders the scene.
OnPreCull Event function that Unity calls before a Camera culls the scene.
OnPreRender Event function that Unity calls before a Camera renders the scene.
OnRenderImage Event function that Unity calls after a Camera has finished rendering, that allows you to modify the Camera's final image.
OnRenderObject在摄像机渲染场景后,将调用 OnRenderObject。
OnSerializeNetworkView用于在网络视图监视的脚本中自定义变量同步。
OnServerInitialized每当调用 Network.InitializeServer 并且完成时,对该服务器调用该函数。
OnTransformChildrenChanged当 GameObject 的变换的子项列表发生更改时,将调用该函数。
OnTransformParentChangedThis function is called when a direct or indirect parent of the transform of the GameObject has changed.
OnTriggerEnter GameObject 与另一个 GameObject 碰撞时,Unity 会调用 OnTriggerEnter。
OnTriggerEnter2D当另一个对象进入附加到该对象的触发碰撞体时发送(仅限 2D 物理)。
OnTriggerExit当 Collider other 已停止接触该触发器时调用 OnTriggerExit。
OnTriggerExit2D当另一个对象离开附加到该对象的触发碰撞体时发送(仅限 2D 物理)。
OnTriggerStay对于接触触发器的每一个 Collider /other/,每次物理更新调用一次 OnTriggerStay。
OnTriggerStay2D在另一个对象位于附加到该对象的触发碰撞体之内时发送每个帧(仅限 2D 物理)。
OnValidateEditor-only function that Unity calls when the script is loaded or a value changes in the Inspector.
OnWillRenderObject如果对象可见并且不是 UI 元素,则为每个摄像机调用 OnWillRenderObject。
Reset重置为默认值。
Start在首次调用任何 Update 方法之前启用脚本时,在帧上调用 Start。
Update如果启用了 MonoBehaviour,则每帧调用 Update。