请尊重原作者的工作,转载时请务必注明转载自:www.xionggf.com
 

Network Manager callbacks

 
 
This section covers the Network Manager callbacks received depending on the type of connection you have to your game’s Host server.
 
See documentation on NetworkBehaviour callbacks for more information on networking callbacks.
 
Local connection callbacks
 
Different callbacks are received depending on your game’s state. Three states are available. These can be set in the Network Manager HUD. 依赖于你的游戏状态,会接受到不同的回调。有三种可选的游戏状态,可以在NetworkManager HUD处设置。
 
 
Host: To set your game up in Host mode, select LAN Host(H) or use the API function StartHost().

Client: To set your game up in Client mode, select LAN Client(C) and enter the server IP into the text field, or use the API function StartClient(). Note that your server IP must be in the same local network - or you can type “localhost” if you are connecting to the same machine.

Server: To set your game up in Server mode, select LAN Server Only(S) or use the API function StartServer().
Host: 当使用Host模式时,选择LAN Host(H)按钮,或者调用StartHost函数。

Client: 当使用Client模式时,选择LAN Client按钮,在输入框中输入服务器IP。或者使用StartClient函数。注意你的服务端IP必须是一个局域网IP。或者你连的就是本机的话,输入localhost即可。

Server:当使用Server模式时,选择LAN Server Only(S)按钮,或者使用StartServer函数。
 
During run time, the Network Manager HUD’s controls are also available in the Network Manager HUD component’s Inspector window. Click Runtime Controls to access these. 在运行时,Network Manager HUD控件依然有效。可以在Inspector面板中使用访问它们
 
 
This page details the callbacks received for each mode. To learn more about setting up game states, see Using the Network Manager: Game state management. 本章详细描述在每个模式下收到的回调。要更多学习如何去设置game state,参见这里
 
Some Network Manager callbacks require you to have multiple instances of the game running (for example, two Standalone instances, or one Standalone and one in the Editor). These instances can be on the same machine or on different machines, as long as those machines are connected through a local network. 有些Network Manager callbacks需要你在游戏运行时启动两个程序实例。例如一个是运行独立的游戏包,另一个是在编辑器中运行。这些实例可以运行在相同或者不同的机器上。只要这些机器是在同一个局域网内。
 
Host callbacks
 
To get these callbacks you need to have two instances of the game, one running in Host mode and the other running in Client mode. These callbacks are only called on instances that are running in Host mode. 要使用这些callback你也需要运行两个游戏程序实例,一个运行在HOST模式下,另一个运行在Client模式下。这些回调仅运行在运行于HOST模式的进程。
 
Follow the steps below to get the callbacks. To stop an instance, press Stop or use the API function StopHost(). 按一下步骤将会得到HOST callback。要停止这个程序实例,按下NetworkManager HUD的Stop按钮,或者调用StopHost
 
Step 1: Start Host instance 步骤1:开始HOST实例
 
(Start() function is called)
OnStartHost
OnStartServer
OnServerConnect
OnStartClient
OnClientConnect
OnServerSceneChanged
OnServerReady
OnServerAddPlayer
OnClientSceneChanged
 
Step 2: Start Client instance 步骤2:启动Client实例
 
OnServerConnect
OnServerReady
OnServerAddPlayer
 
Step 3: Stop Client instance 步骤3:停止Client实例
 
OnServerDisconnect
 
Step 4: Stop Host instance 步骤4:停止HOST实例。
 
OnStopHost
OnStopServer
OnStopClient
 
Client callbacks
 
To get these callbacks you need to have two instances of the game, one running in Server mode and the other running in Client mode. These callbacks are only called on instances that are running in Client mode. 要使用这些callback你也需要运行两个游戏程序实例,一个运行在SERVER模式下,另一个运行在Client模式下。这些回调仅运行在运行于Client模式的进程。
 
Launch the Server mode instance first, then follow the steps below to get the callbacks. To stop an instance, press Stop or use the API function StopHost() 首先要启动基于SERVER模式的实例,按一下步骤将会得到这些callback。要停止这个程序实例,按下NetworkManager HUD的Stop按钮,或者调用StopHost
 
Step 1: Start Client instance 第1步:开启Client模式程序实例
 
(Start() function is called)
OnStartClient
OnClientConnect
OnClientSceneChanged
 
Step 2: Stop Server instance 第2步:关闭Serever模式程序实例
 
OnStopClient
OnClientDisconnect
 
Server callback
 
To get these callbacks you need to have two instances of the game, one running in Server mode and the other running in Client mode. These callbacks are only called on instances that are running in Server mode. 要使用这些callback你也需要运行两个游戏程序实例,一个运行在SERVER模式下,另一个运行在Client模式下。这些回调仅运行在运行于Server模式的进程。
 
Follow the steps below to get the callbacks. To stop an instance, press Stop or use the API function StopHost(). 按一下步骤将会得到这些callback。要停止这个程序实例,按下NetworkManager HUD的Stop按钮,或者调用StopHost
 
Step 1: Start Server instance 第1步:启动Server模式的程序实例
 
(Start() function is called)
OnStartServer
OnServerSceneChanged
 
Step 2: Start Client instance 第2步:启动Client模式的程序实例
 
OnServerConnect
OnServerReady
OnServerAddPlayer
 
Step 3: Stop Client instance 第3步:停止Client模式的程序实例
 
OnServerDisconnect
 
Step 4: Stop Server instance 第4步:停止Server模式的程序实例
 
OnStopServer
 
Internet connection callbacks
 
Internet connections to the Host server take place through the Unity MatchMaker system, which connects you via a relay server. 当使用Unity MatchMaker system的时候,通过一个中继服务器(relay server)。一个HOST服务器将会连接到互联网上。
 
Different callbacks are received depending on your game’s state. Two states are available for MatchMaker: Host and Client. To use MatchMaker, run the game and select Enable Match Maker (M) from the Network Manager HUD menu: 当处于不同的游戏状态时将会收到不同的回调函数。MatchMaker有两种可用的state。HOST和Client。为了使用MatchMaker,启动游戏,在Network Manager HUD上启用Enable Match Maker
 
 
This opens the MatchMaker menu: 这将打开MatchMaker菜单
 
 
Host: To set your game up in Host Mode, select Enable Match Maker (M) > or use the API function CreateMatch() 要在HOST模式下设置游戏,选择【Enable Match Maker (M)】下的【Create Internet Match】,或者调用函数CreateMatch()
 
Client: To set your game up in Client mode, select Enable Match Maker (M) > Find Internet Match > Join Internet Match or use the API function JoinMatch() 要在HOST模式下设置游戏,选择【Enable Match Maker (M)|Find Internet Match|Join Internet Match】下,或者调用函数CreateMatch()
 
This page details the callbacks received for each mode. To learn more about setting up game states, see Using the Network Manager: Game state management. 这章将详细描述在每个模式下所收到的callback。要知道更多的如何设置游戏状态的细节,看这里
 
Some Network Manager callbacks require you to have multiple instances of the game running (for example, two Standalone instances, or one Standalone and one in the Editor). These instances can be on the same machine or on different machines, and on the same network or different networks, but all machines must have an Internet connection. MatchMaker allows you to connect instances of your game via the Internet, so machines with instances of your game could be situated in different parts of the world. 有些Network Manager callbacks需要你在游戏运行时启动两个程序实例。例如一个是运行独立的游戏包,另一个是在编辑器中运行。这些实例可以运行在相同或者不同的机器上。可以在相同或者不同的局域网内,但所有的游戏必须要连上internet。MatchMaker允许通过internet连上你的游戏示例。所以运行着你的游戏的机器可以分布在世界上了任何一个地方。
 
Host MatchMaker callbacks
 
To get these callbacks you need to have two instances of the game, one running in Host mode and the other running in Client mode. These callbacks are only called on instances that are running in Host mode. 要使用这些callback你也需要运行两个游戏程序实例,一个运行在HOST模式下,另一个运行在Client模式下。这些回调仅运行在运行于HOST模式的进程
 
Follow the steps below to get the callbacks. To stop an instance, press Stop or use the API function StopHost(). 按一下步骤将会得到HOST callback。要停止这个程序实例,按下NetworkManager HUD的Stop按钮,或者调用StopHost函数
 
Step 1: Start Host instance 步骤1:开始HOST实例
 
(Start() function is called)
OnStartHost
OnStartServer
OnServerConnect
OnStartClient
OnMatchCreate
OnClientConnect
OnServerSceneChanged
OnServerReady
OnServerAddPlayer
OnClientSceneChanged
 
Step 2: Start Client instance and select Join Internet Match or use the API function JoinMatch() 第2步:启动Client模式的程序实例,选择【Joint Internet Match】或者调用JoinMatch方法
 
OnServerConnect
OnServerReady
OnServerAddPlayer
 
Step 3: Stop Client instance 第3步:停止Client模式的程序实例
 
OnServerDisconnect
 
Client MatchMaker callbacks
 
To get these callbacks you need to have two instances of the game running, one in Host mode and the other running in Client mode. These callbacks are only called on instances that are running in Client mode. 要使用这些callback你也需要运行两个游戏程序实例,一个运行在HOST模式下,另一个运行在Client模式下。这些回调仅运行在运行于Clent模式的进程。
 
Launch the Host mode instance first, then the Client instance. Follow the steps below to get the callbacks. To stop an instance, press Stop or use the API function StopHost(). 首先要启动基于HOST模式的实例,按以下步骤将会得到这些callback。要停止这个程序实例,按下NetworkManager HUD的Stop按钮,或者调用StopHost
 
Step 1: On the Client instance, press Find Internet Match or use the API function ListMatches() to find a list of online games 第1步:在客户端中,按下【Find Internet Match】或者使用ListMatches函数,去找到当前的在线游戏
 
(Start() function is called)
OnMatchList
 
Step 2: On the Client instance, press Join Match or use the API function JoinMatch() to join an online game 第2步:在客户端进程中,按下【Joint Match】或者使用JointMatch方法,加入当前在线的游戏
 
OnStartClient
OnMatchJoined
OnClientConnect
OnClientSceneChanged
 
Step 3: Stop Host instance 第3步:停止HOST实例
 
OnStopClient
OnClientDisconnect