由于 Google Play 游戏电脑版提供了一个标准的 Android 运行时环境,因此除了确保游戏中包含 x86 或 x86-64 二进制文件之外,针对移动设备和针对 PC 封装游戏之间没有区别。如有可能,您应该在 PC build 上使用与移动设备 build 相同的 APK 或 app bundle。
如果针对移动设备和 Google Play 游戏电脑版使用同一个软件包,最好在运行时启用 Google Play 游戏电脑版专用功能,具体可通过两种方式来实现,一种是检测是否有键盘:
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");