集成应用内评价 (Unity)
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本指南介绍了如何使用 Unity 在应用中集成应用内评价。如果您使用的是 Kotlin 或 Java、原生代码或 Unreal Engine,请参阅单独的集成指南。
Unity SDK 概览
Play 应用内评价 API 是 Play Core SDK 系列的一部分。适用于 Unity 的 API 提供了 ReviewManager
类,用于使用 RequestReviewFlow
和 LaunchReviewFlow
方法请求和启动流程。发出请求后,应用可以使用 ReviewErrorCode
检查请求的状态。
设置您的开发环境
OpenUPM-CLI
如果您已安装 OpenUPM CLI,则可以使用以下命令安装 OpenUPM 注册表:
openupm add com.google.play.review
OpenUPM
依次选择 Unity 菜单选项 Edit > Project Settings > Package Manager,打开软件包管理器设置。
将 OpenUPM 作为受限注册表添加到 Package Manager 窗口:
Name: package.openupm.com
URL: https://package.openupm.com
Scopes: com.google.external-dependency-manager
com.google.play.common
com.google.play.core
com.google.play.review
依次选择 Unity 菜单选项 Window > Package Manager,打开软件包管理器菜单。
将经理账号范围下拉菜单设置为选择我的注册库。
从软件包列表中选择 Google Play Integrity plugin for Unity 软件包,然后按 Install。
从 GitHub 导入
从 GitHub 下载最新的 .unitypackage
版本。
导入 .unitypackage
文件,方法是依次选择 Unity 菜单选项 Assets > Import package > Custom Package,然后导入所有项目。
创建 ReviewManager
创建负责处理应用与 Google Play API 之间通信的 ReviewManager
实例。
using Google.Play.Review;
// Create instance of ReviewManager
private ReviewManager _reviewManager;
// ...
_reviewManager = new ReviewManager();
请求 ReviewInfo 对象
请遵循有关何时请求应用内评价的指南,确定在应用的用户流的哪些阶段适合提示用户进行评价(例如,在用户关闭游戏关卡结束时的摘要屏幕之后)。当应用即将到达其中一个阶段时,请使用 ReviewManager
实例创建异步操作,如以下示例所示:
var requestFlowOperation = _reviewManager.RequestReviewFlow();
yield return requestFlowOperation;
if (requestFlowOperation.Error != ReviewErrorCode.NoError)
{
// Log error. For example, using requestFlowOperation.Error.ToString().
yield break;
}
_playReviewInfo = requestFlowOperation.GetResult();
如果调用成功,API 将返回应用启动应用内评价流程所需的 PlayReviewInfo
对象。示例中是在协程内发出调用以执行异步操作(这样就不会屏蔽主线程)。由于调用是异步发出的,最多可能只需要几秒钟的时间,因此应用应该在到达用户流中要显示应用内评价的阶段前发出调用。
启动应用内评价流程
应用收到 PlayReviewInfo
实例后,就可以启动应用内评价流程。请注意,PlayReviewInfo
对象仅在有限的时间内有效,因此,不应该让应用等待过长时间后再启动流程。
var launchFlowOperation = _reviewManager.LaunchReviewFlow(_playReviewInfo);
yield return launchFlowOperation;
_playReviewInfo = null; // Reset the object
if (launchFlowOperation.Error != ReviewErrorCode.NoError)
{
// Log error. For example, using launchFlowOperation.Error.ToString().
yield break;
}
// The flow has finished. The API does not indicate whether the user
// reviewed or not, or even whether the review dialog was shown. Thus, no
// matter the result, we continue our app flow.
后续步骤
测试应用的应用内评价流程,以验证您的集成是否正常运行。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Integrate in-app reviews (Unity)\n\nThis guide describes how to integrate in-app reviews in your app using Unity.\nThere are separate integration guides for if you are using [Kotlin or Java](/guide/playcore/in-app-review/kotlin-java),\n[native code](/guide/playcore/in-app-review/native) or [Unreal Engine](/guide/playcore/in-app-review/unreal-engine).\n\nUnity SDK overview\n------------------\n\nThe Play In-App Review API is part of [Play Core SDK](/reference/com/google/android/play/core/release-notes) family. The API for\nUnity offers a [`ReviewManager`](/reference/unity/class/Google/Play/Review/ReviewManager) class to request and launch the flow using\nthe [`RequestReviewFlow`](/reference/unity/class/Google/Play/Review/ReviewManager#requestreviewflow) and [`LaunchReviewFlow`](/reference/unity/class/Google/Play/Review/ReviewManager#launchreviewflow) methods. After a\nrequest is made, your app can check the status of the request using\n[`ReviewErrorCode`](/reference/unity/namespace/Google/Play/Review#reviewerrorcode).\n\nSet up your development environment\n-----------------------------------\n\n### OpenUPM-CLI\n\nIf you have the [OpenUPM CLI](https://github.com/openupm/openupm-cli#installation)\ninstalled you can install the OpenUPM registry with the following command: \n\n openupm add com.google.play.review\n\n### OpenUPM\n\n1. Open the [package manager settings](https://docs.unity3d.com/Manual/class-PackageManager.html)\n by selecting the Unity menu option\n **Edit \\\u003e Project Settings \\\u003e Package Manager**.\n\n2. Add OpenUPM as a scoped registry to the Package Manager window:\n\n Name: package.openupm.com\n URL: https://package.openupm.com\n Scopes: com.google.external-dependency-manager\n com.google.play.common\n com.google.play.core\n com.google.play.review\n\n3. Open the [package manager menu](//docs.unity3d.com/Manual/upm-ui-install.html) by selecting the Unity\n menu option **Window \\\u003e Package Manager**.\n\n4. Set the manager scope drop-down to select **My Registries**.\n\n5. Select the **Google Play Integrity plugin for Unity** package from the\n package list and press **Install**.\n\n### Import from GitHub\n\n1. Download the latest [`.unitypackage`](//github.com/google/play-in-app-reviews-unity/releases/latest)\n release from GitHub.\n\n2. Import the `.unitypackage` file by selecting the Unity menu option\n **Assets \\\u003e Import package \\\u003e Custom Package** and importing all items.\n\n| **Note:** By downloading and using Google Play Unity Plugins, you agree to the [Play Core Software Development Kit Terms of Service](/guide/playcore#license).\n\nCreate the ReviewManager\n------------------------\n\nCreate an instance of [`ReviewManager`](/reference/unity/class/Google/Play/Review/ReviewManager) that handles communication between\nyour app and the Google Play API. \n\n using Google.Play.Review;\n\n // Create instance of ReviewManager\n private ReviewManager _reviewManager;\n // ...\n _reviewManager = new ReviewManager();\n\nRequest a ReviewInfo object\n---------------------------\n\nFollow the guidance about [when to request in-app reviews](/guide/playcore/in-app-review#when-to-request) to determine good\npoints in your app's user flow to prompt the user for a review (for example,\nafter a user dismisses the summary screen at the end of a level in a game). When\nyour app gets close one of these points, use the [`ReviewManager`](/reference/unity/class/Google/Play/Review/ReviewManager) instance\nto create an async operation, as shown in the following example: \n\n var requestFlowOperation = _reviewManager.RequestReviewFlow();\n yield return requestFlowOperation;\n if (requestFlowOperation.Error != ReviewErrorCode.NoError)\n {\n // Log error. For example, using requestFlowOperation.Error.ToString().\n yield break;\n }\n _playReviewInfo = requestFlowOperation.GetResult();\n\nIf the call is successful, the API returns the [`PlayReviewInfo`](/reference/unity/class/Google/Play/Review/PlayReviewInfo) object\nthat your app needs to launch the in-app review flow. In the example, the call\nis made inside a [coroutine](https://docs.unity3d.com/Manual/Coroutines.html)\nto perform the async operation (this does not block the Main thread). Because\nthe call is made asynchronously, it might take up to a couple of seconds, so\nyour app should make the call before your app reaches the point in your user\nflow where you want to show the in-app review.\n\nLaunch the in-app review flow\n-----------------------------\n\nAfter your app receives the [`PlayReviewInfo`](/reference/unity/class/Google/Play/Review/PlayReviewInfo) instance, it can launch the\nin-app review flow. Note that the `PlayReviewInfo` object is only valid for a\nlimited amount of time, so your app should not wait too long before launching a\nflow. \n\n var launchFlowOperation = _reviewManager.LaunchReviewFlow(_playReviewInfo);\n yield return launchFlowOperation;\n _playReviewInfo = null; // Reset the object\n if (launchFlowOperation.Error != ReviewErrorCode.NoError)\n {\n // Log error. For example, using launchFlowOperation.Error.ToString().\n yield break;\n }\n // The flow has finished. The API does not indicate whether the user\n // reviewed or not, or even whether the review dialog was shown. Thus, no\n // matter the result, we continue our app flow.\n\nNext steps\n----------\n\n[Test your app's in-app review flow](/guide/playcore/in-app-review/test) to verify that your integration is\nworking correctly."]]