Unity-报错解决error CS0619: ‘XRDevice.isPresent‘ is obsolete

Posted 至巫

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Unity-报错解决error CS0619: ‘XRDevice.isPresent‘ is obsolete相关的知识,希望对你有一定的参考价值。

Unity报错解决error CS0619: 'XRDevice.isPresent' is obsolete:

1.问题描述

Assets\\Battlehub\\RTCommon\\Scripts\\RTEBase.cs(690,20): error CS0619: ‘XRDevice.isPresent’ is obsolete: ‘This is obsolete, and should no longer be used. Instead, find the active XRDisplaySubsystem and check that the running property is true (for details, see XRDevice.isPresent documentation).’

这个报错是我在使用Unity的RuntimesEditor插件的时候出现的,大概就是说API过期了需要修改一下。


2.解决办法

在网上查了查没找到相关的,于是就根据报错提示直接去Unity的Api文档查看。看了一下才知道是之前的接口不能用了,重写一下就行。XRDevice.isPresent文档。按照文档中说的重写一个内部类再调用就行。
在代码中添加下面这部分,然后修改一下调用的代码就行。

internal static class ExampleUtil

    public static bool isPresent()
    
        var xrDisplaySubsystems = new List<XRDisplaySubsystem>();
        SubsystemManager.GetInstances<XRDisplaySubsystem>(xrDisplaySubsystems);
        foreach (var xrDisplay in xrDisplaySubsystems)
        
            if (xrDisplay.running)
            
                return true;
            
        
        return false;
    

以上是关于Unity-报错解决error CS0619: ‘XRDevice.isPresent‘ is obsolete的主要内容,如果未能解决你的问题,请参考以下文章

Unity 报错解决方法:Standard Shader Invalid Subscript uv2 error

Unity 报错解决方法:Standard Shader Invalid Subscript uv2 error

Jenkins前端项目打包报错:Error('Callback was already called.')(已解决)

Asp.Net程序报错 - error CS2001: Source file 'C:WindowsTEMPeulevokb.0.cs' could not be found w

Unity报错:Read only asset Packages/com.xxxxx.xxx.xxxx/Editor/VSCodeDiscovery.cs.IPGSD has no meta(代码片段

Unity报错:Read only asset Packages/com.xxxxx.xxx.xxxx/Editor/VSCodeDiscovery.cs.IPGSD has no meta(代码片段