Unity之谷歌应用内评价(google play in-app review)

it2024-05-09  43

官网google in app review文档:https://developer.android.google.cn/guide/playcore/in-app-review

应用内评论仅适用于以下设备: 1.运行Android 5.0(API级别21)或更高版本且已安装Google Play商店的Android设备(电话和平板电脑)。 2.装有Google Play商店的Chrome操作系统设备。

google play 核心库要求:Play Core 库版本1.8.0或更高版本。

针对不同版本的unity对应的库文件也不同: 1.对于Unity版本2018.4及更高版本,请安装Game Package Registry for Unity。这将使单个软件包可通过Unity Package Manager安装。 2.对于Unity版本2018.3及更低版本,请从 Google Play Plugins for Unity releases下载最新版本。这是一个包含Play Core插件以及其他Play插件(例如Play应用内结算和Play Instant)的软件包。

一切准备好之后,开始编写脚本,脚本很简单:

using System.Collections; using System.Collections.Generic; using UnityEngine; #if UNITY_ANDROID && !UNITY_EDITOR using Google.Play.Review; #endif public class GoogleInAppReview : MonoBehaviour {       private void Start()     {        #if UNITY_ANDROID && !UNITY_EDITOR                 OpenReview(); #endif     } #if UNITY_ANDROID && !UNITY_EDITOR     public void OpenReview()     {         StartCoroutine(IE_Review());     }     IEnumerator IE_Review () {         ReviewManager rm = new ReviewManager();         var requestFlowOperation = rm.RequestReviewFlow();         yield return requestFlowOperation;         if(requestFlowOperation.Error != ReviewErrorCode.NoError)         {             Debug.LogFormat("requestFlowOperation:{0}", requestFlowOperation.Error);             yield break;         }         PlayReviewInfo playReviewInfo =  requestFlowOperation.GetResult();         var launchFlowOperation = rm.LaunchReviewFlow(playReviewInfo);         yield return launchFlowOperation;         playReviewInfo = null; // Reset the object         if (launchFlowOperation.Error != ReviewErrorCode.NoError)         {             // Log error. For example, using requestFlowOperation.Error.ToString().             yield break;         }         Debug.Log("open review over !");     } #endif }

将该脚本放在需要调用评价窗口的地方就可以了。

最新回复(0)