1. 程式人生 > >【UNET自學日誌】Part19 第一次嘗試匹配系統

【UNET自學日誌】Part19 第一次嘗試匹配系統

寫在開頭,需要說清楚的是,這個匹配系統是指一個玩家,可以建立一個自己隨意命名的房間,然後其他玩家可以通過聯網去搜索房間,然後加入房間一起遊戲

我先講講怎麼使用這個匹配系統:

在運行遊戲後,因為添加了Network Manager HUD元件,所以有系統自帶的UI介面,如何進行匹配呢?

點選最下方的Enable Match Maker按鈕,有一個可以輸入的文字框,前面的laber寫著"Room Name:",所以在這文字框中輸入的即是房間的名稱,然後點選上面的Create Internet Match 即可建立房間。

在 "Room Name:"下方有一個Find Internet Match即可尋找房間,找到自己想加入的房間,點選即可加入房間進行遊戲。

接下來讓我們進入正題,這種東西還是得看使用者手冊:

Setting up the Multiplayer service

Before you can use the Matchmaker or the internet services you need to register the project first. See the Services Window (cloud icon in upper right corner, or go to Window->Unity Services in the application menu) where the Multiplayer panel should appear. In there you’ll find a link to the cloud Multiplayer website (you can also visit 

https://multiplayer.unity3d.com directly). Find your project name there and set up the Multiplayer configuration.

Note about Unity 5.1.x: The project ID is set up manually in this version of Unity, you can find the field for it in the Player settings (Edit -> Project Settings -> Player). Visit 

https://multiplayer.unity3d.com and set up your project manually and create a Multiplayer configuration for it. When viewing the configuration you’ll be able to see the ID (it’s called UPID right now in a 12345678–1234–1234–1234–123456789ABC format).

這是unity5.3的使用者手冊,可以發現5.3和5.1的操作是不一樣的,其他的版本會不會也不一樣我就不大清楚了,還請各位觀眾老爺自行查查手冊

在這我就簡單說說5.3和5.1的設定方法,具體的詳見上面的英文版。

5.3版本:第一步需要先註冊你的專案,在unity的選單欄上找到Windows->Services,在彈出的面板中可以找到多人玩家的網址(或者直接訪問https://multiplayer.unity3d.com),找到你的專案,並設定多人遊戲的配置(主要就是設定下每個房間最多的玩家數量)

5.1版本:同5.3,訪問https://multiplayer.unity3d.com,找到你的專案然後設定其配置,然後在配置中你可以看到你專案的ID(一個類似於12345678–1234–1234–1234–123456789ABC這樣的格式的叫做UPID的東西),複製這一ID,在Edit -> Project Settings -> Player中填入此ID即可。

至此就可以使用簡單的匹配功能了,目前的問題就是延遲和丟包率,後續看看能不能有好的解決方法。