集成应用内评价(虚幻引擎)

本指南介绍了如何使用虚幻引擎在应用中集成应用内评价。如果您使用 Kotlin 或 Java原生代码Unity,则有单独的集成指南。

虚幻引擎 SDK 概览

Play 应用内评价 API 是 Play Core SDK 系列的一部分。适用于虚幻引擎的 API 提供了 UInAppReviewsManager 类,可使用 RequestReviewFlowLaunchReviewFlow 方法请求和启动流程。发出请求后,您的应用可以使用 EInAppReviewErrorCode 检查请求的状态。

支持的虚幻引擎版本

该插件支持 Unreal Engine 5.0 及所有后续版本。

设置开发环境

  1. 从 GitHub 仓库下载 Play 虚幻引擎插件

  2. GooglePlay 文件夹复制到您的虚幻引擎项目中的 Plugins 文件夹内。

  3. 打开您的虚幻引擎项目,然后点击 Edit → Plugins

  4. 搜索 Google Play 并勾选 Enabled 复选框。

  5. 重启游戏项目并触发构建。

  6. 打开您项目的 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);
}
  1. 此方法创建了一个 FRreviewOperationCompletedDelegate 以处理评价操作的完成。

  2. 该委托绑定到 OnReviewOperationCompleted 方法,此方法将在操作完成后调用。

  3. BindDynamic 函数确保委托正确链接到回调。

  4. RequestReviewFlow(Delegate) 方法启动评价流程,并传递委托以处理结果。

  5. 评价操作异步运行,允许应用中的其他任务在操作完成时继续进行。

  6. 操作完成后,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);
}

后续步骤

测试您应用的应用内评价流程以验证集成是否正常工作。