今天遇到一个方法过时的问题:
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).'
新的SDK更改的已经不是直接获取此属性的返回值,由于多个脚本都需要修改此重复问题,于是新建一个类,设置类似的写法,利用新的SDK来返回想要的返回值;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR;
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;
}
}
在使用调用的语句中直接使用ExampleUtil.isPresent()来接收返回值即可。