如何使用 Azure 函数访问读取/写入/修改/删除 Playfab 数据?
问问题
283 次
1 回答
0
以下步骤将帮助您使用 Playfab 访问 azure 功能
- 在 VS Code 中创建 Azure 函数
- 将 azure 函数部署到门户并使用云脚本注册您的函数
- 下面是使用 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 上下文、变量和服务器 SDK
您将需要通过包管理器安装 PlayFab SDK。为此,请在 Visual Studio Code 中打开终端或 CMD 控制台,然后键入:
dotnet add package PlayFabAllSDK
我们创建了一些随 cSharpSDK 一起提供的帮助程序。
<DefineConstants>NETCOREAPP2_0</DefineConstants>
如果您使用的是最新版本,则需要编辑 .csproj 文件并包含 在默认 PropertyGroup 或 NETCOREAPP3_1 中。可以通过多种方法(API、计划任务、PlayStream Event、Segment Entering 和 Exit 方法)执行脚本。执行的上下文对于实现 CloudScript 很重要。有关如何使用脚本上下文的详细信息,请参阅 使用 CloudScript 上下文模型教程 。
有关更多信息,请查看使用 Azure 函数的云脚本 和Playfab 云脚本
于 2021-12-17T04:19:50.017 回答