Regions
Photon Cloud 通過在多個地區託管服務器,在全球範圍內提供低延遲遊戲體驗。
客戶端從我們的 Photon 名稱服務器獲取區域列表。在項目的生命周期內,可能會添加新區域,也可能會放棄和移除舊區域。
每個區域都是完全獨立的,由主服務器(用於匹配)和遊戲服務器(託管房間)組成。
以下是客戶端工作流程的概述:
(1) 客戶端從 Photon 名稱服務器檢索可用區域列表。
(2) 客戶端選擇一個可用區域 —— 要麼根據最低延遲自動選擇,要麼通過手動選擇 —— 然後連接到該區域的主服務器。主服務器負責匹配以及在該區域內的遊戲服務器上創建或加入房間。
(3) 最後,客戶端連接到指定的遊戲服務器以加入房間。該遊戲服務器與步驟 (2) 中客戶端連接的主服務器位於同一區域。
通過區域允許列表,您可以為每個 AppId 定義哪些哪些區域可用(見下文)。
可用區域
Photon Cloud 由分佈在全球多個託管中心的服務器組成。
每個 Photon Cloud 區域都由一個 “區域代碼” 標識,這是一個不區分大小寫的短字符串。
例如,“EU” 或 “eu” 都會被接受,並且指代同一個歐洲區域。
以下列表標明了每個區域的託管中心位置和區域代碼。
遊戲用 Photon Cloud
Photon 產品 Quantum、Fusion、Voice、Realtime 和 PUN 在 遊戲用 Photon Cloud 的以下區域可用。
| 區域 | 託管位置 | 代碼 |
|---|---|---|
| 亞洲 | 新加坡 | asia |
| 澳大利亞 | 悉尼 | au |
| 加拿大東部 | 蒙特利爾 | cae |
| 中國大陸(參見說明) | 上海 | cn |
| 歐洲 | 阿姆斯特丹 | eu |
| 香港 | 香港 | hk |
| 印度 | 欽奈 | in |
| 日本 | 東京 | jp |
| 南非 | 約翰內斯堡 | za |
| 南美洲 | 聖保羅 | sa |
| 韓國 | 首爾 | kr |
| 土耳其 | 伊斯坦布爾 | tr |
| 阿拉伯聯合酋長國 | 迪拜 | uae |
| 美國東部 | 華盛頓特區 | us |
| 美國西部 | 聖何塞 | usw |
| 美國中南地區 | 達拉斯 | ussc |
Photon Chat 在以下區域可用:
| 區域 | 託管位置 | 代碼 |
|---|---|---|
| 亞洲 | 新加坡 | asia |
| 歐洲 | 阿姆斯特丹 | eu |
| 美國東部 | 華盛頓特區 | us |
| 中國大陸(參見說明) | 上海 | cn |
Photon Industries Premium Cloud
Photon 產品 Quantum、Fusion、Voice、Realtime 和 PUN 在 Photon Industries Premium Cloud 的以下區域可用。
| 區域 | 託管位置 | 代碼 |
|---|---|---|
| 亞洲 | 新加坡 | asia |
| 澳大利亞 | 悉尼 | au |
| 歐洲 | 阿姆斯特丹 | eu |
| 印度 | 欽奈 | in |
| 日本 | 東京 | jp |
| 南非 | 約翰內斯堡 | za |
| 南美洲 | 聖保羅 | sa |
| 韓國 | 首爾 | kr |
| 美國東部 | 華盛頓特區 | us |
| 美國西部 | 聖何塞 | usw |
Photon Chat 在以下區域可用:
| 區域 | 託管位置 | 代碼 |
|---|---|---|
| 美國東部 | 華盛頓特區 | us |
遊戲 / 行業用中國區域
使用 Photon Cloud 中國大陸區域有特殊條件:
- 必須解鎖訪問權限(見下文)
- Photon Voice 在中國不可用
- 開發用 20CCU 免費(非商業用途)
- Photon Cloud 上僅提供 500CCU 訂閱
- 大規模設置需要自定義協議
Photon 產品 Quantum、Fusion、Realtime、PUN 和 Chat 在 Photon Cloud 的以下區域可用:
| 區域 | 託管位置 | 代碼 |
|---|---|---|
| 中國大陸 | 上海 | cn |
區域允許列表
區域允許列表使您能夠直接從儀表板為每個應用程序自定義可用區域。使用最佳區域功能的客戶端將自動適應。
通過使用更多或更少的區域,您可以平衡服務質量(當有靠近玩家的區域時,往返時間會更好)與匹配體驗(更少的區域意味著每個區域有更多的玩家)。
要為每個應用程序定義區域,打開儀表板,單擊所選應用程序的 “管理”,然後單擊 “編輯允許列表”。
您會發現一個輸入字段,用於輸入允許的區域列表,如下所示:
- 每個 SDK 的可用區域在上面列出,有時針對行業圈單獨列出。
- 允許列表必須是由分號分隔的區域代碼字符串。例如,“eu;us”。
- 區域代碼不區分大小寫。
- 未定義或無法識別的區域代碼將從列表中忽略。
- 空字符串("")或格式錯誤的字符串(例如 “;;;”)意味著所有可用區域都被允許。
更改(確認並保存)後的 10 分鐘內,名稱服務器將把過濾後的列表發送給連接的客戶端。
為避免客戶端出現衝突,請通過延遲連接到 “最佳區域”,或者確保選擇從區域列表中收到的區域。
如何選擇區域
美國的用戶如果連接到 Photon Cloud 的美國區域,延遲最低。這很簡單。
但是如果您的用戶來自 世界各地 呢?
選項有...
- a) 讓遊戲客戶端對不同的 Photon Cloud 區域進行延遲測試,然後預選延遲最低的那個,閱讀我們的方法。
- b) 分發與特定區域綁定的客戶端構建版本,以便不同地區的用戶連接到不同的 Photon Cloud 區域,或者
- c) 讓用戶從遊戲的 UI 中選擇合適的區域。
- d) 如果更高的延遲對您的遊戲體驗來說是可接受的,讓所有用戶連接到同一個區域。
所有 Photon Cloud 應用程序在所有可用區域都能運行,無需額外收費。
Photon Cloud 的儀表板允許您監控遊戲在每個區域的使用情況,並輕鬆升級或降級您的訂閱計劃。
最佳區域注意事項
「最佳區域」選項並非確定性的。
有時由於微小差異或完全相同的延遲計算,它可能會是「隨機」的。
理論上,可能會出現以下情況:
- 同一設備 對多個區域的延遲相同。即使是連接到同一網路的用戶端,最終也可能連接到不同的區域。
- 連接到同一網路的不同設備(或同一設備的不同重試) 對同一區域 的延遲值不同。
例如,對於「us」和「usw」,您可以使用區域允許列表來選擇您想要的區域,或者讓用戶端連接到特定區域。
若要進行除錯,請將日誌等級設定為「Info」,並清除「當前最佳區域」(在 PUN 中:PhotonNetwork.BestRegionSummaryInPreferences = null)。查看詳細資訊,或透過郵件傳送日誌給我們。
How To Select A Region At Runtime
By default, if no Region is set in the PhotonAppSettings, Fusion connects to the Best Region.
This means that during the start-up process, it pings all available Regions and connects to the region with the lowest ping.
Keep in mind that Best Region is not deterministic and sometimes can be "random" due to little variations or exact same ping calculations.
If the Best Region feature is not desired, it is possible to let the player choose which Region to connect to at runtime.
This can help to lower the ping between players if they are connecting to a common Region or just want to join a Session with friends that are playing on a specific Region.
To get a list of available regions, Fusion provides the NetworkRunner.GetAvailableRegions() method.
It returns a list of Fusion.RegionInfo objects, which contain the region's name and ping value. This can be used to sort the list by the lowest ping or let the player choose the desired region.
The Region selection can only be done when the NetworkRunner is not running, as this can't be changed while it is already connected to a particular Region.
In the following snippet, it is shown how a NetworkRunner can use a custom Region in runtime:
C#
public class FusionInit : MonoBehaviour {
// ...
// Start a NetworkRunner with a Game Mode and connect to the specified Region
public Task<StartGameResult> StartSimulation(NetworkRunner runner, GameMode gameMode, string region) {
var appSettings = BuildCustomAppSetting(region);
return runner.StartGame(new StartGameArgs() {
// ...
GameMode = gameMode,
CustomPhotonAppSettings = appSettings
});
}
private FusionAppSettings BuildCustomAppSetting(string region, string customAppID = null, string appVersion = "1.0.0") {
var appSettings = PhotonAppSettings.Global.AppSettings.GetCopy();;
appSettings.UseNameServer = true;
appSettings.AppVersion = appVersion;
if (string.IsNullOrEmpty(customAppID) == false) {
appSettings.AppIdFusion = customAppID;
}
if (string.IsNullOrEmpty(region) == false) {
appSettings.FixedRegion = region.ToLower();
}
// If the Region is set to China (CN),
// the Name Server will be automatically changed to the right one
// appSettings.Server = "ns.photonengine.cn";
return appSettings;
}
}
Get Available Regions At Runtime
It is possible to get a list of available regions at runtime using and awaiting the static method NetworkRunner.GetAvailableRegions(),
An example of use is shown below.
C#
public Dropdown Dropdown;
private async void RefreshRegionDropdown() {
_tokenSource = new CancellationTokenSource();
var regions = await NetworkRunner.GetAvailableRegions(cancellationToken: _tokenSource.Token);
Dropdown.options.Clear();
Dropdown.AddOptions(regions.Select(reg => $"{reg.RegionCode} = {reg.RegionPing}").ToList());
}
NOTE: A NetworkRunner must exist in the scene.
使用中國大陸區域
Photon 名稱服務器必須位於中國本地,否則防火牆可能會阻止流量。
中國的 Photon 名稱服務器是 “ns.photonengine.cn”。
從中國大陸以外的客戶端進行連接很可能不會產生良好的結果。
此外,從 Photon 服務器連接到中國大陸以外的服務器(例如,用於自定義身份驗證、WebHooks、WebRPCs)可能不可靠。
出於法律原因,您需要為中國單獨構建版本,我們建議與其一起使用單獨的 AppId。
例如,使用編譯條件(您選擇的)根據構建版本更改 AppId 和 Photon 名稱服務器。
按照與您的客戶端 SDK 相對應的說明,為中國市場製作特殊的構建版本。
Fusion
Using PhotonAppSettings
Using Code
C#
public class FusionInit : MonoBehaviour {
// ...
async void ConnectToChina()
{
var runner = BuildNetworkRunnerInstance();
// Start new Runner with the Host Migration Token
var result = await StartSimulation(
runner,
GameMode.AutoHostOrClient, // Or any other GameMode
"cn" // Select China Region
);
// Check results as usual
if (result.Ok == false) {
Debug.LogWarning(result.ShutdownReason);
} else {
Debug.Log("Done");
}
}
}
Back to top