> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 將 GDK 整合到 4.26 版之前的 Unreal Engine 專案

> 透過編輯 Build.cs、手動新增 include 和程式庫路徑，以及使用 wdapp 啟動，將 XBOX GDK 接入 4.26 之前的 Unreal Engine 組建。

如果您正在準備將遊戲發佈到 PC 上的 Microsoft Store，且遊戲使用的是 4.26 之前的 Unreal Engine 版本，請參考本主題。

## 使用舊版 Unreal Engine (4.26 版之前)

如果您使用的是 Unreal Engine 4.26 版或更新版本，請參閱 [在 PC 上開始使用 Unreal](/zh-TW/build/gdk-and-engines/unreal/unreal)。

如果您使用的是 Unreal Engine 4.25 版或更早版本，且無法升級到 4.26 版或更新版本，您仍然可以使用 Gaming Runtime 和 XBOX Services API (XSAPI) 的匯入程式庫，整合主要的 XBOX 生態系統體驗。

這些匯入程式庫可讓遊戲直接呼叫 Gaming Runtime API 和 XSAPI，而不需要將 GDK 平台目標新增至遊戲專案。

### 新增 Gaming Runtime 和 XSAPI 的標頭與匯入程式庫

1. 找到 Unreal 專案的組建檔案：/Source/(ProjectName)/(ProjectName).Build.cs
2. 新增下列這一行以定義 **\_GAMING\_DESKTOP** 巨集
   ```csharp theme={null}
       PublicDefinitions.Add("_GAMING_DESKTOP");  // For Unreal 4.12 or earlier, use "Definitions.Add()" instead
   ```
3. 新增下列 include 路徑
   ```csharp theme={null}
       // Add the include path for Gaming Runtime
       PublicIncludePaths.Add(@"C:\Program Files (x86)\Microsoft GDK\241000\GRDK\GameKit\Include");
       // Add the include path for XSAPI
       PublicIncludePaths.Add(@"C:\Program Files (x86)\Microsoft GDK\241000\GRDK\ExtensionLibraries\Xbox.Services.API.C\Include");
   ```

> 若為 Microsoft GDK (2024 年 6 月) 或更早版本，請使用：*C:\Program Files (x86)\Microsoft GDK\230300\GRDK\ExtensionLibraries\Xbox.Services.API.C\DesignTime\CommonConfiguration\Neutral\Include*

1. 為匯入程式庫新增下列程式庫路徑
   ```csharp theme={null}
       // Add the import library for Gaming Runtime
       PublicAdditionalLibraries.Add(@"C:\Program Files (x86)\Microsoft GDK\241000\GRDK\GameKit\Lib\amd64\xgameruntime.lib");
       // Add the import library for XSAPI
       PublicAdditionalLibraries.Add(@"C:\Program Files (x86)\Microsoft GDK\241000\GRDK\ExtensionLibraries\Xbox.Services.API.C\Lib\Release\Microsoft.Xbox.Services.142.GDK.C.Thunks.lib");
   ```

> 若為 Microsoft GDK (2024 年 6 月) 或更早版本，請使用：*C:\Program Files (x86)\Microsoft GDK\230300\GRDK\ExtensionLibraries\Xbox.Services.API.C\DesignTime\CommonConfiguration\Neutral\Lib\Release\Microsoft.Xbox.Services.141.GDK.C.Thunks.lib*

<Note>
  根據 GDK 版本和安裝位置，您電腦上的 include 路徑和程式庫路徑可能會有所不同。
</Note>

### 從 C++ 程式碼檔案存取 Gaming Runtime 和 XSAPI

1. 決定您要在何處新增登入和解除鎖定成就等功能的整合
2. 新增 Gaming Runtime 和 XSAPI 的標頭
   ```cpp theme={null}
       // When using Unreal Engine 4.15 or later
       THIRD_PARTY_INCLUDES_START
       
       #include "XGameRuntimeInit.h" // For Gaming Runtime 
       #include "xsapi-c\services_c.h"  // For XSAPI
       // When using Unreal Engine 4.15 or later
       THIRD_PARTY_INCLUDES_END
   ```
3. 整合服務呼叫。請參閱下列範例：

* 操作說明：登入使用者的最佳做法
* 更新遊戲管理的成就

### 在 Partner Center 中建立產品

在測試 XBOX services 功能或將遊戲發佈到 Microsoft Store 之前，您必須在 Partner Center 中建立已啟用 XBOX services 的產品。如需 Partner Center 的詳細資訊，請參閱「在 Partner Center 中設定應用程式或遊戲 (適用於受管理的合作夥伴)」。

### 為遊戲建立 MicrosoftGame.config 檔案

若要讓遊戲登入 XBOX services，您必須在遊戲套件中包含 **MicrosoftGame.config** 檔案，並在 "MSAAppId" 和 "TitleId" 欄位中填入您在上一個步驟中建立之 Partner Center 專案的值。建立設定檔最簡單的方式是使用 [MicrosoftGame.config 編輯器](/zh-TW/build/core-features/common/game-config/MicrosoftGameConfig-Editor)。如需 MicrosoftGame.config 檔案的詳細資訊，請參閱 [MicrosoftGame.config 概觀](/zh-TW/build/core-features/common/game-config/MicrosoftGameConfig-Overview)。

<Note>
  請確定 MicrosoftGame.config 檔案位於包含遊戲主要可執行檔的相同目錄中。
</Note>

### 建立並註冊遊戲套件

若要從遊戲登入 XBOX services 並測試服務整合，您必須建立套件並註冊它。

1. 選取 **\[File]** > **\[Package Project]** > **\[Windows]** > **\[Windows (64-bit)]** 以開啟封裝對話方塊。
2. 從 **\[檔案總管]** 對話方塊中選擇組建輸出的資料夾，然後選取 **\[選擇資料夾]**。
3. 使用 wdapp 啟動遊戲。
   ```cpp theme={null}
       wdapp launch {full path to the game's executable in the same directory containing the MicrosoftGame.Config file}
   ```
4. 或者，您也可以使用 wdapp 註冊套件，然後從 \[開始] 功能表啟動遊戲。
   ```cpp theme={null}
       wdapp register {full path to the directory containing the MicrosoftGame.Config file}
   ```

<Note>
  直接按兩下可執行檔將無法登入 XBOX services。
</Note>

## 另請參閱

[針對登入和沙箱進行疑難排解](/zh-TW/services/xbox-services/develop/troubleshooting/live-troubleshoot-sandboxes)


## Related topics

- [整合 PlayFab Unreal Engine Marketplace 外掛程式](/zh-TW/services/playfab/multiplayer/networking/party-unreal-engine-oss-playfab-plugin-integration.md)
- [搭配 Unreal Engine 使用 GDK](/zh-TW/build/gdk-and-engines/unreal/unreal.md)
- [PlayFab Unreal GSDK 外掛程式概觀](/zh-TW/services/playfab/multiplayer/servers/server-sdks/unreal-gsdk/index.md)
- [搭配 Unity、Unreal 和其他引擎使用 GDK](/zh-TW/build/gdk-and-engines/gdk-and-engines.md)
- [搭配 Unity 使用 GDK](/zh-TW/build/gdk-and-engines/unity/unity.md)
