Testing Multiplayer Movement
測試多人運(yùn)動
To test Multiplayer movement we must again have two instances of the game running simultaneously.
為了測試多人游戲,我們必須再次同時運(yùn)行兩個游戲?qū)嵗?/p>
The instance being run from the editor will be up-to-date with our changes, but the standalone build will be stale and needs to be updated with the most recent changes that we have made to the project.
從編輯器中運(yùn)行的實(shí)例將與我們的更改同步,但是獨(dú)立的構(gòu)建將會過時,需要更新我們對項(xiàng)目所做的最新更改。
Build and Run this scene as a standalone application.
構(gòu)建并運(yùn)行這個場景作為一個獨(dú)立的應(yīng)用程序。
The standalone player will now start and show the in-game UI from the NetworkManagerHUD.
獨(dú)立播放器現(xiàn)在將開始并顯示來自NetworkManagerHUD的游戲內(nèi)UI。
Click the LAN Host button from the in-game UI to start this game as a Host.
點(diǎn)擊游戲內(nèi)UI的局域網(wǎng)主機(jī)按鈕,作為主機(jī)開始游戲。
We should see the game running with one player GameObject in the scene.
我們應(yīng)該在場景中看到一個玩家在游戲中運(yùn)行的游戲。
Return to Unity.
回到Unity。
Enter Play Mode
進(jìn)入播放模式
The game will now run in the editor and show the in-game UI from the NetworkManagerHUD.
游戲?qū)⒃诰庉嬈髦羞\(yùn)行,并從NetworkManagerHUD顯示游戲內(nèi)UI。
Click the LAN Client button from the in-game UI to connect to the Host as a Client.
單擊游戲內(nèi)UI中的LAN客戶端按鈕以連接到主機(jī)作為客戶端。
There should be two player GameObjects;
應(yīng)該有兩個玩家的游戲?qū)ο?
one for the local player on the Host and one for the remote player for this Client.
一個用于本地播放器,另一個用于該客戶端的遠(yuǎn)程播放器。
Currently, they will be in the exact same position, so it may appear that there is only one player GameObject in the scene.
目前,他們將處于完全相同的位置,所以可能出現(xiàn)在場景中只有一個玩家的游戲?qū)ο蟆?/p>
By checking the Hierarchy Window, there should be two Player(clone)’s.
通過檢查層次結(jié)構(gòu)窗口,應(yīng)該有兩個播放器(克隆)。

To test moving the Client’s player GameObject in the scene:
在場景中測試客戶的播放器游戲?qū)ο?
Press the WASD or arrow keys to move and turn the Client's player
按下WASD或箭頭鍵移動并旋轉(zhuǎn)客戶端的播放器。
Note how the player GameObjects now move independently of each other.
注意玩家的游戲?qū)ο蟋F(xiàn)在是如何彼此獨(dú)立移動的。
Switch back to the Stand Alone player.
切換回獨(dú)立球員。
To test moving the Host’s player GameObject in the scene:
測試在場景中移動主機(jī)的玩家游戲?qū)ο?
Press the WASD or arrow keys to move and turn the Host’s player.
按下WASD或箭頭鍵移動并旋轉(zhuǎn)主機(jī)的播放器。
The two Player GameObjects should now be completely independent of each other and be in sync on both instances of the game.
這兩個游戲?qū)ο蟋F(xiàn)在應(yīng)該是完全獨(dú)立的,并且在游戲的兩個實(shí)例上都是同步的。
When running two instances of the project, the remote player GameObject may not appear to be moving smoothly on the local client.
在運(yùn)行項(xiàng)目的兩個實(shí)例時,遠(yuǎn)程player GameObject可能不會在本地客戶機(jī)上順利地移動。
There may be a “steppy” feel to the movement of the remote Player's GameObject.
對于遠(yuǎn)程玩家的游戲?qū)ο蟮囊苿?,可能會有一種“steppy”的感覺。
It is worth keeping in mind that all networked applications will be affected to some degree by latency and, more often, the limitations to the speed in which data can be moved moved between the Clients and Server.
值得記住的是,所有的網(wǎng)絡(luò)應(yīng)用程序都會受到延遲的影響,而且更常見的是,在客戶機(jī)和服務(wù)器之間移動數(shù)據(jù)的速度會受到限制。
There are many ways that latency and data transfers can be optimized.
有許多方法可以優(yōu)化延遲和數(shù)據(jù)傳輸。
For example, the NetworkTransform has a Network Send Rate setting which can be used to set how often the NetworkTransform sends synchronization data.
例如,NetworkTransform有一個網(wǎng)絡(luò)發(fā)送速率設(shè)置,可以用來設(shè)置網(wǎng)絡(luò)轉(zhuǎn)換發(fā)送同步數(shù)據(jù)的頻率。
The frequency of updates over a network between Clients and Server can have a heavy impact on how a Networked Multiplayer game feels.
客戶端和服務(wù)器之間的網(wǎng)絡(luò)更新頻率對網(wǎng)絡(luò)多人游戲的感覺有很大的影響。

More importantly, however, there are many ways that a Networked application can cover for discrepancies in synchronization, whether these discrepancies are from sheer latency or due to the frequency of synchronizational updates.
然而,更重要的是,網(wǎng)絡(luò)應(yīng)用程序有許多方法可以彌補(bǔ)同步上的差異,這些差異是由于純粹的延遲,還是由于同步更新的頻率造成的。
These solutions can include interpolation, extrapolation and many other forms of smoothing and prediction.
這些解決方案可以包括插值、外推和許多其他形式的平滑和預(yù)測。
None of these will be covered in this lesson.
這節(jié)課不會涉及這些內(nèi)容。
At this point, it is worth bearing in mind a few key points.
在這一點(diǎn)上,值得考慮幾個關(guān)鍵點(diǎn)。
A balance will need to be struck between how often state synchronization happens and the performance of the game.
需要在狀態(tài)同步發(fā)生的頻率和游戲的性能之間找到平衡。
If a game tries to synchronize too much data too often over a network, the performance of the game will suffer.
如果一個游戲試圖通過網(wǎng)絡(luò)同步過多的數(shù)據(jù),那么游戲的性能就會受到影響。
If a game does not synchronize data often enough, then the feel of the game and game-play could suffer.
如果一個游戲不經(jīng)常同步數(shù)據(jù),那么游戲和游戲的感覺就會受到影響。
In all cases there will need to be some form of interpretation of the synchronized GameObjects to keep all Clients feeling smooth and in sync while playing.
在所有的情況下,需要對同步的游戲?qū)ο筮M(jìn)行某種形式的解釋,以使所有的客戶在玩的時候感到平滑和同步。
All Multiplayer Networked games are never in perfect synchronization, as this is not physically possible.
所有的多人網(wǎng)絡(luò)游戲都不可能完全同步,因?yàn)檫@在物理上是不可能的。
Two or more remote Clients cannot be in the exact same state at the same time due simply to the time it takes to transfer the data between them.
兩個或多個遠(yuǎn)程客戶端不能在同一時間處于完全相同的狀態(tài),原因是它們之間傳輸數(shù)據(jù)所需的時間。
Games, however, need to feel as if they are in proper synchronization for the best player experience, even if the separate instances are slightly different in their exact state.
然而,游戲需要感覺就好像它們是最佳玩家體驗(yàn)的適當(dāng)同步,即使個別的實(shí)例在它們的確切狀態(tài)稍有不同。
How to do this will be covered in detail in other lessons.
如何做到這一點(diǎn),將在其他課程中詳細(xì)介紹。
Close the Stand Alone player.
關(guān)閉獨(dú)立球員。
Return to Unity.
回到Unity。
Exit Play Mode.
退出播放模式。