本指南介绍如何使用 Unreal Engine 将应用内评价集成到您的应用中。如果您使用的是 Kotlin 或 Java、原生代码或 Unity,请参阅单独的集成指南。
Unreal Engine SDK 概览
Play 应用内评价 API 是 Play Core SDK 系列的一部分。适用于 Unreal Engine 的 API 提供了一个 UInAppReviewsManager 类,用于通过 RequestReviewFlow 和 LaunchReviewFlow 方法请求和启动该流程。发出请求后,您的应用可以使用 EInAppReviewErrorCode 检查请求的状态。
支持的虚幻引擎版本
该插件支持 Unreal Engine 5.0 及所有后续版本。
设置您的开发环境
从 GitHub 代码库下载 Play 虚幻引擎插件。
将
GooglePlay文件夹复制到 Unreal Engine 项目中的Plugins文件夹内。打开 Unreal Engine 项目,然后点击修改 → 插件。
搜索 Google Play,然后勾选已启用复选框。
重启游戏项目并触发构建。
打开项目的
Build.cs文件,并将PlayInAppReviews模块添加到PublicDependencyModuleNames:using UnrealBuildTool; public class MyGame : ModuleRules { public MyGame(ReadOnlyTargetRules Target) : base(Target) { // ... PublicDependencyModuleNames.Add("PlayInAppReviews"); // ... } }
请求应用内评价流程
请遵循有关何时请求应用内评价的指南,确定在应用的用户流的哪些阶段适合提示用户进行评价(例如,在用户关闭游戏关卡结束时的摘要界面后)。当您的应用接近其中某个时间点时,使用 UInAppReviewsManager 创建一个操作,如以下示例所示:
MyClass.h
void MyClass::OnReviewOperationCompleted(EInAppReviewErrorCode ErrorCode)
{
// ...
}
MyClass.cpp
void MyClass::RequestReviewFlow()
{
// Create a delegate to bind the callback function.
FReviewOperationCompletedDelegate Delegate;
// Bind the completion handler (OnReviewOperationCompleted) to the delegate.
Delegate.BindDynamic(this, &MyClass::OnReviewOperationCompleted);
// Initiate the review flow, passing the delegate to handle the result.
GetGameInstance()
->GetSubsystem<UInAppReviewsManager>()
->RequestReviewFlow(Delegate);
}
该方法会创建一个
FRreviewOperationCompletedDelegate来处理评价操作的完成。委托会绑定到
OnReviewOperationCompleted方法,该方法将在操作完成后调用。BindDynamic函数可确保委托正确关联到回调。RequestReviewFlow(Delegate)方法会启动评价流程,并传递委托来处理结果。评价操作以异步方式运行,因此应用中的其他任务可以在评价操作完成期间继续运行。
操作完成后,
OnReviewOperationCompleted回调会处理结果,包括成功或失败。
启动应用内评价流程
RequestReviewFlow 操作完成后,您就可以启动应用内评价流程。为此,需要绑定一个委托来处理完成事件,确保应用对评价请求的结果(成功或失败)做出响应。
MyClass.h
void MyClass::OnReviewOperationCompleted(EInAppReviewErrorCode ErrorCode)
{
// ...
}
MyClass.cpp
void MyClass::LaunchReviewFlow()
{
// Create a delegate to bind the callback function.
FReviewOperationCompletedDelegate Delegate;
// Bind the completion handler (OnReviewOperationCompleted) to the delegate.
Delegate.BindDynamic(this, &MyClass::OnReviewOperationCompleted);
// Launch the review flow, passing the delegate to handle the result.
GetGameInstance()
->GetSubsystem<UInAppReviewsManager>()
->LaunchReviewFlow(Delegate);
}
后续步骤
测试应用的应用内评价流程,以验证您的集成是否正常运行。