本指南介绍了如何使用 Unreal Engine 在应用中集成应用内评价。如果您使用的是 Kotlin 或 Java、原生代码或 Unity,请参阅单独的集成指南。
Unreal Engine SDK 概览
Play 应用内评价 API 是 Play Core SDK 系列的一部分。适用于 Unreal Engine 的 API 提供了 UInAppReviewsManager 类,以使用 RequestReviewFlow 和 LaunchReviewFlow 方法请求和启动流程。发出请求后,应用可以使用 EInAppReviewErrorCode 检查请求的状态。
支持的 Unreal Engine 版本
该插件支持 Unreal Engine 5.0 及所有后续版本。
设置您的开发环境
- 从 GitHub 代码库下载 Play Unreal Engine 插件。 
- 将 - GooglePlay文件夹复制到 Unreal Engine 项目的- Plugins文件夹中。
- 打开您的 Unreal Engine 项目,然后依次点击 Edit(修改)→ Plugins(插件)。 
- 搜索 Google Play,然后选中 Enabled(已启用)复选框。 
- 重新启动游戏项目并触发构建。 
- 打开项目的 - 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);
}
后续步骤
测试应用的应用内评价流程,以验证您的集成是否正常运行。
