【发布时间】:2022-01-19 06:18:18
【问题描述】:
如何使用 Azure 函数访问读取/写入/修改/删除 Playfab 数据?
【问题讨论】:
-
但是,我使用的是 Azure 门户,所以我在那里创建了 HTTP 函数。如何添加或引用这些文件?我没有走运。
标签: azure azure-functions playfab
如何使用 Azure 函数访问读取/写入/修改/删除 Playfab 数据?
【问题讨论】:
标签: azure azure-functions playfab
以下步骤将帮助您使用 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
您需要通过包管理器安装 PlayFab SDK。为此,请在 Visual Studio Code 中打开终端或 CMD 控制台并输入:dotnet add package PlayFabAllSDK
我们创建了一些随 cSharpSDK 一起提供的帮助程序。
您需要编辑您的 .csproj 文件,并在您的默认 PropertyGroup 或 NETCOREAPP3_1 中包含 <DefineConstants>NETCOREAPP2_0</DefineConstants>(如果您使用的是最新版本)。
可以通过多种方法(API、计划任务、PlayStream 事件、Segment Entering 和 Exit 方法)执行脚本。执行的上下文对于实现 CloudScript 很重要。有关如何使用脚本上下文的详细信息,请参阅Using CloudScript context models tutorial。
更多信息请查看Cloud Script Using Azure Functions和Playfab Cloud Script
【讨论】: