c# - 在运行时更改图形 API (Unity)
问题描述
我目前正在尝试同时使用两种不同的 AR 算法(ARCore 和 EasyAR)。ARCore 目前只支持一小部分设备,所以我们希望在 ARCore 不足的时候让 EasyAR 接手。
问题是,EasyAR 需要 OpenGL ES2,而 ARCore 需要 OpenGL ES3。我编写了检查设备上是否存在 ARCore 的代码,然后导航到使用适当技术的场景。我还实现了统一的PlayerSettings.SetGraphicsAPIs(),但这在部署时不起作用,只能在 Unity 的编辑器中使用。现在我正在寻找一种确实有效的替代方案。
代码需要在安卓和IOS上运行。
public IEnumerator CheckCompatibility()
{
AsyncTask<ApkAvailabilityStatus> checkTask = Session.CheckApkAvailability();
CustomYieldInstruction customYield = checkTask.WaitForCompletion();
yield return customYield;
ApkAvailabilityStatus result = checkTask.Result;
switch (result)
{
case ApkAvailabilityStatus.SupportedApkTooOld:
_ShowAndroidToastMessage("Supported apk too old");
break;
case ApkAvailabilityStatus.SupportedInstalled:
_ShowAndroidToastMessage("Supported and installed");
GraphicsDeviceType[] easyAPI = { GraphicsDeviceType.OpenGLES2, GraphicsDeviceType.Vulkan };
SceneManager.LoadScene("ARCoreImageTracker");
break;
case ApkAvailabilityStatus.SupportedNotInstalled:
_ShowAndroidToastMessage("Supported, not installed, requesting installation");
Session.RequestApkInstallation(false);
break;
case ApkAvailabilityStatus.UnknownChecking:
_ShowAndroidToastMessage("Unknown Checking");
break;
case ApkAvailabilityStatus.UnknownError:
_ShowAndroidToastMessage("Unknown Error");
break;
case ApkAvailabilityStatus.UnknownTimedOut:
_ShowAndroidToastMessage("Unknown Timed out");
break;
case ApkAvailabilityStatus.UnsupportedDeviceNotCapable:
_ShowAndroidToastMessage("Unsupported Device Not Capable");
GraphicsDeviceType[] coreAPI = { GraphicsDeviceType.OpenGLES2 };
PlayerSettings.SetGraphicsAPIs(BuildTarget.Android, coreAPI);
SceneManager.LoadScene("EasyARImageTracker");
break;
}
}
目前,我得到一个错误列表,上面写着"The name 'PlayerSettings' does not exist in the current context"。我可以尝试任何替代方案吗?
解决方案
据我所知, PlayerSettings.SetGraphicsAPIs 在运行时不起作用。它仅适用于 UnityEditor。我认为您应该为 ARCore 和 EasyAR 单独构建。
推荐阅读
- apache-spark-sql - 有什么方法可以提高火花写入性能?
- regex - 必需的正则表达式验证开始两个固定字符,然后在数字固定字符之后
- java - 更改添加的 jquery 类的位置
- .net-core-3.1 - 如何在 .net core 3.1 中使用配置管理器
- kubernetes - 错误:标志 --allowed-unsafe-sysctls 已被弃用
- ios - 动态视图渲染,SwiftUI
- python - 无法使用 Beautifulsoup 抓取内容
- swift - vDSP.DCT 解包为零
- python - 使用 Pip 安装模块时出错
- python - 在 OpenCV Python 中使用鼠标单击在较大的图像上拖动、调整大小和旋转图像