This document is about: FUSION 2
SWITCH TO

Regions

Photon Cloud 通過在多個地區託管服務器,在全球範圍內提供低延遲遊戲體驗。

客戶端從我們的 Photon 名稱服務器獲取區域列表。在項目的生命周期內,可能會添加新區域,也可能會放棄和移除舊區域。

每個區域都是完全獨立的,由主服務器(用於匹配)和遊戲服務器(託管房間)組成。

以下是客戶端工作流程的概述:

(1) 客戶端從 Photon 名稱服務器檢索可用區域列表。

(2) 客戶端選擇一個可用區域 —— 要麼根據最低延遲自動選擇,要麼通過手動選擇 —— 然後連接到該區域的主服務器。主服務器負責匹配以及在該區域內的遊戲服務器上創建或加入房間。

(3) 最後,客戶端連接到指定的遊戲服務器以加入房間。該遊戲服務器與步驟 (2) 中客戶端連接的主服務器位於同一區域。

Photon Cloud Regions' Connect Flows
連接到 Photon Cloud 區域

通過區域允許列表,您可以為每個 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 分鐘內,名稱服務器將把過濾後的列表發送給連接的客戶端。
為避免客戶端出現衝突,請通過延遲連接到 “最佳區域”,或者確保選擇從區域列表中收到的區域。

注意:為受歡迎的應用程序更改可用區域會影響多個區域的峰值 CCU,這是訂閱費用的依據。根據需要調整訂閱計劃,以避免更昂貴的超量費用。當切換穩定下來後,降低訂閱是完全可以的。

如何選擇區域

美國的用戶如果連接到 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 應用程序請求訪問中國大陸區域。給我們發送電子郵件,我們可以為您的 AppID 解鎖它。
在我們的儀表板上,您不能訂閱用於中國大陸地區的付費計劃。 通過電子郵件與我們聯繫,以獲取任何訂閱的報價:hello@photonengine.com。

Photon 名稱服務器必須位於中國本地,否則防火牆可能會阻止流量。
中國的 Photon 名稱服務器是 “ns.photonengine.cn”。

從中國大陸以外的客戶端進行連接很可能不會產生良好的結果。
此外,從 Photon 服務器連接到中國大陸以外的服務器(例如,用於自定義身份驗證、WebHooks、WebRPCs)可能不可靠。

重要:在當前階段,您通過儀表板對應用程序所做的更改不會自動反映在中國的應用程序緩存中。 如果您在那裡有更新請求,請通過電子郵件通知我們。

出於法律原因,您需要為中國單獨構建版本,我們建議與其一起使用單獨的 AppId。
例如,使用編譯條件(您選擇的)根據構建版本更改 AppId 和 Photon 名稱服務器。

按照與您的客戶端 SDK 相對應的說明,為中國市場製作特殊的構建版本。

Fusion

Using PhotonAppSettings

Fusion: PhotonAppSettings for China
Fusion: PhotonAppSettings for China

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