在 oculus quest 3 上使用编辑器时,我可以在本地和云端保存空间锚点,但是当我在 oculus 上构建并运行 Apk 时,结果总是失败
使用方法(
OVRSpatialAnchor.Save()
)或(OVRSpatialAnchor.SaveAsync()
)
它给我 OVRSpatialAnchors.OperationResult => 使用时失败 OVRSpatialAnchor.SaveAsync(IEnumerable<OVRSpatialAnchor> anchors, SaveOptions saveOptions)
我正在使用 unity editor 2023 和(Meta XR ALl in one SDK v62)
这是我的 SpatialAnchorManager 代码:
private void CreateAnchor()
{
var createdAnchor = Instantiate(anchor, OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch), OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTouch));
var spatialAnchor = createdAnchor.AddComponent<OVRSpatialAnchor>();
StartCoroutine(InitSpatialAnchor(spatialAnchor));
}
private IEnumerator InitSpatialAnchor(OVRSpatialAnchor anchor)
{
yield return WaitForInit(anchor);
yield return SaveAsync(anchor);
// OnAnchorCreateCompleted?.Invoke(anchor);
}
protected IEnumerator WaitForInit(OVRSpatialAnchor anchor)
{
while (anchor && (!anchor.Created || !anchor.Localized))
yield return null;
if (anchor == null)
{
Debug.LogWarning($" Failed to create the spatial anchor.");
}
else
{
var a = anchor.GetComponent<Anchor>();
a.Uuid.text = $"Uuid: {anchor.Uuid}";
}
}
protected IEnumerator SaveAsync(OVRSpatialAnchor anchor)
{
var task = anchor.SaveAsync();
while (!task.IsCompleted)
yield return null;
try
{
if (!task.GetResult())
{
var ex = task.GetType();
debugText.text = $" Failed to save the spatial anchor.";
Debug.LogWarning($" Failed to save the spatial anchor.");
}
else
{
var a = anchor.GetComponent<Anchor>();
a.Status.text = $"Saved!!";
PlayerPrefs.SetString("lastCreatedAnchor", anchor.Uuid.ToString());
}
}
catch (Exception ex)
{
debugText.text = $"Exception After Saving: {ex.InnerException?.Message ?? ex.Message}";
}
}
在 Oculus 上从工作帐户切换到个人帐户后,一切正常。
似乎work帐户的空间锚点存在问题。