> ## 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.

# 使用 Azure Functions 的 Cloudscript 本機偵錯

> 新增 ExecuteFunction 實作並從 Unity、Unreal 或 C# 路由 SDK 呼叫，以使用 Azure Functions 在本機執行和偵錯 PlayFab CloudScript。

# 教學課程：使用 Azure Functions 的 Cloudscript 本機偵錯

透過 Azure Functions，您現在可以在本機測試和偵錯您的 CloudScript 程式碼。完成本教學課程後，您可以在偵錯工具 (例如 VS Code 或 Visual Studio) 下執行本機 Azure Functions 應用程式、設定中斷點，並執行您的遊戲用戶端。

在本教學課程中，您將了解如何：

<Note>
  \[!div class="checklist"] \* 將 ExecuteFunction 的實作新增至您的本機 Azure Functions 應用程式 \* 新增設定檔案，告知 PlayFab SDK 從您的遊戲呼叫該本機實作
</Note>

## 必要條件

* 目前下列 SDK 支援本機偵錯：
  * [PlayFab C# SDK](https://github.com/PlayFab/CSharpSDK)
  * [PlayFab Unity SDK](https://github.com/PlayFab/UnitySDK)
  * [PlayFab 的 Unreal 4 Marketplace 外掛程式](https://github.com/PlayFab/UnrealMarketplacePlugin)

## 新增 ExecuteFunction 的本機實作

### 針對 C# Azure Functions 應用程式

若要在 C# Azure Functions 應用程式中設定 ExecuteFunction 的本機實作，請將 [ExecuteFunction.cs](https://github.com/PlayFab/pf-af-devfuncs/blob/master/csharp/ExecuteFunction.cs) 檔案新增至您的本機 Azure Functions 應用程式。

### ExecuteFunction 本機實作所需的環境變數

將下列設定新增至您的 `local.settings.json` 檔案：

| 名稱 | 值 |
| - | - |
| PLAYFAB\_TITLE\_ID | 您的遊戲識別碼，以十六進位形式表示 |
| PLAYFAB\_DEV\_SECRET\_KEY | 您遊戲的秘密金鑰。您可以在 Game Manager 中按一下遊戲名稱右側的齒輪圖示，然後前往 **Title Settings** > **Secret Keys** 找到您的秘密金鑰。 |

例如：

```JSON theme={null}
{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "...",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet",
    "PLAYFAB_TITLE_ID": "B55D",
    "PLAYFAB_DEV_SECRET_KEY": "AAAABBBBCCCCDDDDEEEEFFFFGGGGHHHHIIIIJJJJKKKKLLLLMM"
  }
}
```

## 設定 PlayFab SDK 以呼叫本機 ExecuteFunction 實作

若要告知 PlayFab SDK 將 ExecuteFunction API 呼叫重新導向至您的本機實作，請將名為 `playfab.local.settings.json` 的檔案新增至下列兩個位置之一：

* 電腦上的暫存目錄
  * 在 Windows 上，這是 **TEMP** 環境變數
  * 在 Linux/Mac 上，這是 **TMPDIR** 環境變數
* 遊戲可執行檔的目錄

將檔案的內容設定如下：

```JSON theme={null}
{ "LocalApiServer": "http://localhost:<portNumber>/api/<functionName>" }
```

當您想要停止本機重新導向，並讓 ExecuteFunction 呼叫 PlayFab API 伺服器時，請刪除 `playfab.local.settings.json` 檔案。

## 其他資源

Azure Functions 有一份很棒的指南，說明如何在本機[測試和偵錯您的函式](https://learn.microsoft.com/en-us/azure/azure-functions/functions-develop-local)。

以下是上述文件中的一些重點。

* 確認已安裝 Azure Functions Core Tools
* 設定您的本機設定檔案。如需詳細資訊，請參閱[使用 Visual Studio Code 開發 Azure Functions](https://learn.microsoft.com/en-us/azure/azure-functions/functions-develop-vs-code?tabs=nodejs#local-settings-file)
* 在程式碼中設定中斷點
* 選取 **F5** 以開始偵錯


## Related topics

- [使用 Azure Functions 的 PlayFab CloudScript 快速入門指南](/zh-TW/services/playfab/live-service-management/service-gateway/automation/cloudscript-af/quickstart.md)
- [使用 Azure Functions 的 PlayFab CloudScript](/zh-TW/services/playfab/live-service-management/service-gateway/automation/cloudscript-af/index.md)
- [在 Visual Studio Code 中偵錯使用 Azure Functions 的 CloudScript](/zh-TW/services/playfab/live-service-management/service-gateway/automation/cloudscript-af/debugging-with-CloudScript-AF-VSCode.md)
- [使用 Visual Studio 偵錯 CloudScript Azure Functions](/zh-TW/services/playfab/live-service-management/service-gateway/automation/cloudscript-af/debugging-with-CloudScript-AF-VS.md)
- [在 Azure 入口網站中偵錯 CloudScript Azure Functions](/zh-TW/services/playfab/live-service-management/service-gateway/automation/cloudscript-af/debugging-with-CloudScript-AF-Azure.md)
