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).'

因为在2017版本后unity.Engine.VR就过时了,换成了XR,所以我们需要对一些项目维护进行对应的更改。网上查了很多资料,基本没有确切对应的解决方案,于是使用leap motion官方升级文档对比查看,解决方案如下:

public static bool IsXRDevicePresent() {#if UNITY_2020_1_OR_NEWERreturn XRSettings.isDeviceActive;#elif UNITY_2017_2_OR_NEWERreturn XRDevice.isPresent;#elsereturn VRDevice.isPresent;#endif}

我们可以直接使用XRSettings.isDeviceActive代替XRDevice.isPresent。

对应版本同上。

附所有有关XR的过时报错更改:对照上述参考


using System.Collections.Generic;
using UnityEngine;#if UNITY_2017_2_OR_NEWER
using UnityEngine.XR;
#else
using UnityEngine.VR;
#endifnamespace Leap.Unity {/// <summary>/// Wraps various (but not all) "XR" calls with Unity 5.6-supporting "VR" calls/// via #ifdefs./// </summary>public static class XRSupportUtil {#if UNITY_2019_2_OR_NEWERprivate static System.Collections.Generic.List<XRNodeState> nodeStates = new System.Collections.Generic.List<XRNodeState>();#endifpublic static bool IsXREnabled() {#if UNITY_2017_2_OR_NEWERreturn XRSettings.enabled;#elsereturn VRSettings.enabled;#endif}public static bool IsXRDevicePresent() {#if UNITY_2020_1_OR_NEWERreturn XRSettings.isDeviceActive;#elif UNITY_2017_2_OR_NEWERreturn XRDevice.isPresent;#elsereturn VRDevice.isPresent;#endif}static bool outputPresenceWarning = false;public static bool IsUserPresent(bool defaultPresence = true) {#if UNITY_2019_3_OR_NEWERvar devices = new List<InputDevice>();InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.HeadMounted, devices);if (devices.Count == 0 && !outputPresenceWarning) {Debug.LogWarning("No head-mounted devices found. Possibly no HMD is available to the XR system.");outputPresenceWarning = true;}if (devices.Count != 0) {var device = devices[0];if (device.TryGetFeatureValue(CommonUsages.userPresence, out var userPresent)) {return userPresent;}}#elif UNITY_2017_2_OR_NEWERvar userPresence = XRDevice.userPresence;if (userPresence == UserPresenceState.Present) {return true;} else if (!outputPresenceWarning && userPresence == UserPresenceState.Unsupported) {Debug.LogWarning("XR UserPresenceState unsupported (XR support is probably disabled).");outputPresenceWarning = true;}#elseif (!outputPresenceWarning){Debug.LogWarning("XR UserPresenceState is only supported in 2017.2 and newer.");outputPresenceWarning = true;}#endifreturn defaultPresence;}public static Vector3 GetXRNodeCenterEyeLocalPosition() {#if UNITY_2019_2_OR_NEWERInputTracking.GetNodeStates(nodeStates);Vector3 position;foreach(XRNodeState state in nodeStates) {if(state.nodeType == XRNode.CenterEye &&state.TryGetPosition(out position)){ return position; }}return Vector3.zero;#elif UNITY_2017_2_OR_NEWERreturn InputTracking.GetLocalPosition(XRNode.CenterEye);#elsereturn InputTracking.GetLocalPosition(VRNode.CenterEye);#endif}public static Quaternion GetXRNodeCenterEyeLocalRotation() {#if UNITY_2019_2_OR_NEWERInputTracking.GetNodeStates(nodeStates);Quaternion rotation;foreach (XRNodeState state in nodeStates) {if (state.nodeType == XRNode.CenterEye &&state.TryGetRotation(out rotation)){ return rotation; }}return Quaternion.identity;#elif UNITY_2017_2_OR_NEWERreturn InputTracking.GetLocalRotation(XRNode.CenterEye);#elsereturn InputTracking.GetLocalRotation(VRNode.CenterEye);#endif}public static Vector3 GetXRNodeHeadLocalPosition() {#if UNITY_2019_2_OR_NEWERInputTracking.GetNodeStates(nodeStates);Vector3 position;foreach(XRNodeState state in nodeStates) {if(state.nodeType == XRNode.Head &&state.TryGetPosition(out position)){ return position; }}return Vector3.zero;#elif UNITY_2017_2_OR_NEWERreturn InputTracking.GetLocalPosition(XRNode.Head);#elsereturn InputTracking.GetLocalPosition(VRNode.Head);#endif}public static Quaternion GetXRNodeHeadLocalRotation() {#if UNITY_2019_2_OR_NEWERInputTracking.GetNodeStates(nodeStates);Quaternion rotation;foreach (XRNodeState state in nodeStates) {if (state.nodeType == XRNode.Head &&state.TryGetRotation(out rotation)){ return rotation; }}return Quaternion.identity;#elif UNITY_2017_2_OR_NEWERreturn InputTracking.GetLocalRotation(XRNode.Head);#elsereturn InputTracking.GetLocalRotation(VRNode.Head);#endif}public static Vector3 GetXRNodeLocalPosition(int node) {#if UNITY_2019_2_OR_NEWERInputTracking.GetNodeStates(nodeStates);Vector3 position;foreach(XRNodeState state in nodeStates) {if(state.nodeType == (XRNode)node &&state.TryGetPosition(out position)){ return position; }}return Vector3.zero;#elif UNITY_2017_2_OR_NEWERreturn InputTracking.GetLocalPosition((XRNode)node);#elsereturn InputTracking.GetLocalPosition((VRNode)node);#endif}public static Quaternion GetXRNodeLocalRotation(int node) {#if UNITY_2019_2_OR_NEWERInputTracking.GetNodeStates(nodeStates);Quaternion rotation;foreach (XRNodeState state in nodeStates) {if (state.nodeType == (XRNode)node &&state.TryGetRotation(out rotation)){ return rotation; }}return Quaternion.identity;#elif UNITY_2017_2_OR_NEWERreturn InputTracking.GetLocalRotation((XRNode)node);#elsereturn InputTracking.GetLocalRotation((VRNode)node);#endif}public static void Recenter() {#if UNITY_2019_3_OR_NEWERvar devices = new List<InputDevice>();InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.HeadMounted, devices);if (devices.Count == 0) return;var hmdDevice = devices[0];#if !UNITY_2020_1_OR_NEWERif(hmdDevice.subsystem != null) {#endifhmdDevice.subsystem.TryRecenter();#if !UNITY_2020_1_OR_NEWER}else{#pragma warning disable 0618InputTracking.Recenter();#pragma warning restore 0618}#endif#elseInputTracking.Recenter();#endif}public static string GetLoadedDeviceName() {#if UNITY_2017_2_OR_NEWERreturn XRSettings.loadedDeviceName;#elsereturn VRSettings.loadedDeviceName;#endif}/// <summary> Returns whether there's a floor available. </summary>public static bool IsRoomScale() {#if UNITY_2019_3_OR_NEWERvar devices = new List<InputDevice>();InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.HeadMounted, devices);if (devices.Count == 0) return false;var hmdDevice = devices[0];#if !UNITY_2020_1_OR_NEWERif(hmdDevice.subsystem != null) {#endifreturn hmdDevice.subsystem.GetTrackingOriginMode().HasFlag(TrackingOriginModeFlags.Floor);#if !UNITY_2020_1_OR_NEWER}else{#pragma warning disable 0618return XRDevice.GetTrackingSpaceType() == TrackingSpaceType.RoomScale;#pragma warning restore 0618}#endif#elif UNITY_2017_2_OR_NEWERreturn XRDevice.GetTrackingSpaceType() == TrackingSpaceType.RoomScale;#elsereturn VRDevice.GetTrackingSpaceType() == TrackingSpaceType.RoomScale;#endif}static List<Vector3> _boundaryPoints = new List<Vector3>();/// <summary> Returns whether the playspace is larger than 1m on its shortest side. </summary>public static bool IsLargePlayspace() {#if UNITY_2020_1_OR_NEWER // Oculus reports a floor centered space now...var devices = new List<InputDevice>();InputDevices.GetDevicesWithCharacteristics(InputDeviceCharacteristics.HeadMounted, devices);if (devices.Count == 0) return false;var hmdDevice = devices[0];hmdDevice.subsystem.TryGetBoundaryPoints(_boundaryPoints);Bounds playspaceSize = new Bounds();foreach(Vector3 boundaryPoint in _boundaryPoints) { playspaceSize.Encapsulate(boundaryPoint); }return playspaceSize.size.magnitude > 1f; // Playspace is greater than 1m on its shortest axis#elsereturn IsRoomScale();#endif}public static float GetGPUTime() {float gpuTime = 0f;#if UNITY_5_6_OR_NEWER#if UNITY_2017_2_OR_NEWERUnityEngine.XR.XRStats.TryGetGPUTimeLastFrame(out gpuTime);#elseUnityEngine.VR.VRStats.TryGetGPUTimeLastFrame(out gpuTime);#endif#elsegpuTime = UnityEngine.VR.VRStats.gpuTimeLastFrame;#endifreturn gpuTime;}}}

Unity 2018升级2020后XR报错error CS0619: ‘XRDevice.isPresent‘ is obsolete相关推荐

  1. Battlehub 2021使用 报错error CS0619: ‘XRDevice.isPresent‘ is obsolete

    直接使用XRSettings.isDeviceActive代替XRDevice.isPresent

  2. php报错处理,关于升级php7后的报错处理

    [摘要] PHP即"超文本预处理器",是一种通用开源脚本语言.PHP是在服务器端执行的脚本语言,与C语言类似,是常用的网站编程语言.PHP独特的语法混合了C.Java.Perl以及 ...

  3. 升级php7后的报错处理

    *由于php7的出现带来大幅的性能提升,想体验下新版本带来的特性,因此做了升级. 发现在网站中请求接口时发生错误,排查后把解决方法记录下来 升级php后站点报错,提示如下: Deprecated: A ...

  4. 太爽了今天解决了大问题!——LOL英雄联盟读条后崩溃报错error,错误LOL_public……一下午终于解决

    LOL英雄联盟读条后崩溃报错error,错误LOL_public-- 背景:是这样,前一天LOL退出时被我强退了,接着今天一如既往学了会python然后打算下把棋(云顶之弈),对了在这之前还搞了下自己 ...

  5. 安装报错_MySQL8.0安装后,报错ERROR 1045 (28000)

    报错问题: 1.昨天安装Mysql8.0.18,然后使用navicat连接,结果出现: ERROR 1045 (28000): Access denied for user 'root'@'local ...

  6. 升级gcc后glibc报错

    升级完gcc后执行c++报错: /usr/lib/libstdc++.so.6: version 'GLIBCXX_3.4.15' not found 解决方法: 1. 查看libstdc++.so. ...

  7. node升级版本后vue报错

    npm i node-sass -D 转载于:https://www.cnblogs.com/FengWenQi/p/9429953.html

  8. Android studio更新后项目报错Error:android-apt plugin is incompatible with the Android Gradle plugin. Pleas

    主要原因是AS更新后对apt插件不再支持 1.build.gradle文件中的"apt"的地方把"apt"改为"annotationProcessor ...

  9. 【Android开发遇错】Android studio 添加jar后编译报错Error converting bytecode to dex: Cause: Dex cannot pars

    ** 添加了一个mysql-connector-java-5.1.38-bin.jar然后编译就报错了 ** 错误信息如下: Error:Error converting bytecode to de ...

  10. kafka集群重启后启动报错ERROR Error while creating ephemeral at /brokers/ids/3,, node already exists and owner

    ERROR Error while creating ephemeral at /brokers/ids/3,, node already exists and owner '193744291469 ...

最新文章

  1. [原创]什么是CMM?
  2. 第二十一讲 特征值和特征向量
  3. java 登录编程_Java编程通过session访问需要登录的页面
  4. 【转】61条面向对象设计的经验原则
  5. Hibernate对象标识符
  6. dockerfile拉取私库镜像_关于kubernetes拉取私库镜像需要注意的点
  7. 2.2.4 ES 6语法与ES 5语法
  8. Android Effect 解析
  9. UI 设计师不容错过的12款APP UI 交互设计
  10. 2021-04-25 AndroidStudio拖动条_小白龙抄作业
  11. 一个自己实现的js表单验证框架。
  12. scroll-view实现下拉刷新(避免onload进入页面初始refresher-triggered为true触发下拉问题)
  13. android 电子签名设备,Android 电子签名制作
  14. SIMPLE、PISO 、PIMPLE算法浅析
  15. 002柿饼派GUI模组学习之AnimatedImage控件调试
  16. matlab仿真限幅发散,simulink仿真收敛,但用m文件实现却是发散的,是怎么回事?...
  17. thinkphp5oa管理系统
  18. Elastalert的报警功能拓展:分组报警
  19. 看完这几道 JavaScript 面试题,让你与考官对答如流(上)
  20. moodle中年级、班级、小组研讨

热门文章

  1. Oracle修改expired状态,更改ORACLE 用户的 expired状态
  2. 2006年10大变态站名网站排名
  3. Python学习笔记7-函数
  4. 原生安卓开发!最详细的解释小白也能听懂,全网独家首发!
  5. 使用ViewPager和RecyclerView实现微信表情包分页显示
  6. protobuf repeated string 赋值
  7. 入门学习计算机第十三天—初识指针
  8. 可以自己diy壁纸的app_有什么APP可以做壁纸?
  9. github电脑壁纸_有什么好用的电脑壁纸软件?
  10. leopard 全部搞定状态截图