【问题标题】:Access Playfab data with Azure functions使用 Azure 函数访问 Playfab 数据
【发布时间】:2022-01-19 06:18:18
【问题描述】:

如何使用 Azure 函数访问读取/写入/修改/删除 Playfab 数据?

【问题讨论】:

  • 但是,我使用的是 Azure 门户,所以我在那里创建了 HTTP 函数。如何添加或引用这些文件?我没有走运。

标签: azure azure-functions playfab


【解决方案1】:

以下步骤将帮助您使用 Playfab 访问 azure 功能

  1. 在 VS Code 中创建 Azure 函数
  2. 将 azure 函数部署到门户并使用云脚本注册您的函数
  3. 以下是使用 playfab 中的 azure 函数调用云脚本的示例代码。

//This snippet assumes that your game client is already logged into PlayFab.

using PlayFab;
using PlayFab.CloudScriptModels;

private void CallCSharpExecuteFunction()
{
    PlayFabCloudScriptAPI.ExecuteFunction(new ExecuteFunctionRequest()
    {
        Entity = new PlayFab.CloudScriptModels.EntityKey()
        {
            Id = PlayFabSettings.staticPlayer.EntityId, //Get this from when you logged in,
            Type = PlayFabSettings.staticPlayer.EntityType, //Get this from when you logged in
        },
        FunctionName = "HelloWorld", //This should be the name of your Azure Function that you created.
        FunctionParameter = new Dictionary<string, object>() { { "inputValue", "Test" } }, //This is the data that you would want to pass into your function.
        GeneratePlayStreamEvent = false //Set this to true if you would like this call to show up in PlayStream
    }, (ExecuteFunctionResult result) =>
    {
        if (result.FunctionResultTooLarge ?? false)
        {
            Debug.Log("This can happen if you exceed the limit that can be returned from an Azure Function, See PlayFab Limits Page for details.");
            return;
        }
        Debug.Log($"The {result.FunctionName} function took {result.ExecutionTimeMilliseconds} to complete");
        Debug.Log($"Result: {result.FunctionResult.ToString()}");
    }, (PlayFabError error) =>
    {
        Debug.Log($"Opps Something went wrong: {error.GenerateErrorReport()}");
    });
}

PlayFab CloudScript Context, Variables and Server SDKs

  1. 您需要通过包管理器安装 PlayFab SDK。为此,请在 Visual Studio Code 中打开终端或 CMD 控制台并输入:dotnet add package PlayFabAllSDK

  2. 我们创建了一些随 cSharpSDK 一起提供的帮助程序。

  3. 您需要编辑您的 .csproj 文件,并在您的默认 PropertyGroup 或 NETCOREAPP3_1 中包含 &lt;DefineConstants&gt;NETCOREAPP2_0&lt;/DefineConstants&gt;(如果您使用的是最新版本)。

  4. 可以通过多种方法(API、计划任务、PlayStream 事件、Segment Entering 和 Exit 方法)执行脚本。执行的上下文对于实现 CloudScript 很重要。有关如何使用脚本上下文的详细信息,请参阅Using CloudScript context models tutorial

更多信息请查看Cloud Script Using Azure FunctionsPlayfab Cloud Script

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-31
    • 2021-09-17
    • 2021-10-08
    • 1970-01-01
    • 1970-01-01
    • 2019-10-28
    • 1970-01-01
    • 2019-02-26
    相关资源
    最近更新 更多