为 Google Play Games on PC 打包游戏

由于 Google Play Games on PC 提供标准的 Android 运行时环境,因此除了确保您包含 x86 或 x86-64 二进制文件外,为移动设备或 PC 打包游戏之间没有区别。如果可能,您应该在 PC 上使用与移动设备构建相同的 APK 或 应用捆绑包

在跨移动设备和 Google Play Games on PC 使用一个软件包时,最好在运行时通过 检测键盘的存在 来启用 Google Play Games on PC 的特定功能。

Kotlin

val hasKeyboard = resources.configuration.keyboard == KEYBOARD_QWERTY

Java

boolean hasKeyboard = getResources().getConfiguration().keyboard == KEYBOARD.QWERTY

C#

var unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
var currentActivity = unityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity");
var resources = currentActivity.Call<AndroidJavaObject>("getResources");
var configuration = resources.Call<AndroidJavaObject>("getConfiguration");
var keyboard = configuration.Get<int>("keyboard");
var hasKeyboard == 2; // Configuration.KEYBOARD_QWERTY

或者检查 "com.google.android.play.feature.HPE_EXPERIENCE" 系统功能。

Kotlin

var isPC = packageManager.hasSystemFeature("com.google.android.play.feature.HPE_EXPERIENCE")
  

Java

PackageManager pm = getPackageManager();
boolean isPC = pm.hasSystemFeature("com.google.android.play.feature.HPE_EXPERIENCE")
  

C#

var unityPlayerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
var currentActivity = unityPlayerClass.GetStatic<AndroidJavaObject>("currentActivity");
var packageManager = currentActivity.Call<AndroidJavaObject>("getPackageManager");
var isPC = packageManager.Call<bool>("hasSystemFeature", "com.google.android.play.feature.HPE_EXPERIENCE");