在运行时更改图形API(Unity) [英] Change graphics API at runtime (Unity)

查看:758
本文介绍了在运行时更改图形API(Unity)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试同时使用两种不同的AR算法(ARCore和EasyAR). ARCore当前仅支持一小部分设备,因此我们希望EasyAR在ARCore不足时接管.

I'm currently trying to use two different AR algorithms together (ARCore and EasyAR). ARCore currently only supports a small list of devices, so we want EasyAR to take over when ARCore is insufficient.

问题是,EasyAR需要OpenGL ES2,而ARCore需要OpenGL ES3.我编写了检查设备上是否存在ARCore的代码,然后导航到使用适当技术的场景.我还实现了unity的 PlayerSettings.SetGraphicsAPIs(),但这仅在Unity的编辑器中才适用于部署.现在,我正在寻找一种切实可行的替代方法.

Problem is, EasyAR requires OpenGL ES2, and ARCore requires OpenGL ES3. I've written code that checks the presence of ARCore on the device, and then navigates to a scene that uses the appropriate technology. I've also implemented unity's PlayerSettings.SetGraphicsAPIs(), but this doesn't work on deploy, only in Unity's editor. Now I'm looking for an alternative that actually does work.

代码需要在android和IOS上运行.

The code needs to run on android and on 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;
    }
}

当前,我得到一个错误列表,指出名称"PlayerSettings"在当前上下文中不存在" .我可以尝试其他替代方法吗?

Currently, I get a list of errors that says that "The name 'PlayerSettings' does not exist in the current context". Any alternatives I could try?

推荐答案

据我所知,PlayerSettings.SetGraphicsAPIs在运行时不起作用. 它仅适用于UnityEditor. 我认为您应该分别为ARCore和EasyAR进行构建.

As far as I know, PlayerSettings.SetGraphicsAPIs doesn't work at runtime. It is only for UnityEditor. I think you should build separately for the ARCore and EasyAR.

这篇关于在运行时更改图形API(Unity)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆