【发布时间】:2020-09-14 11:26:14
【问题描述】:
我目前正在开展一个房间规模的 Unity 项目,我需要使用持久的世界锚在我的设备上本地保存 GameObjects 的位置,而无需使用任何 Internet 访问或 Wifi。
我正在使用Unity 2019.4.7 和HoloLens2 设备。
我从早期的HoloLens1 项目以及MRTK 2.4 的WorldAnchorManager-Class 中遇到了一些实现,这似乎与HoloToolkit 的旧WorldAnchorManager 非常相似。 (例如:https://forums.hololens.com/discussion/2667/how-to-use-unity-world-anchors,或https://codeholo.com/2019/02/01/anchoring-your-gameobjects-in-hololens-apps)
很遗憾,没有解决方案对我有用。
似乎WorldAnchors 甚至没有保存在WorldAnchorStore 中。我还尝试使用没有 WorldAnchorManager-Class 的官方 Unity WorldAnchorStore,即使它在 Unity 2020 中将被弃用。
有人可以提供一个应该在我的设置中工作的示例吗?
我也会很高兴看到每一个让锚点起作用的提示。
我当前使用WorldAnchorManager 的代码如下所示。 WorldAnchorManager-Instance 中的持久锚点已启用。
using Microsoft.MixedReality.Toolkit.Experimental.Utilities;
using UnityEngine;
public class SetWorldAnkeredObject : MonoBehaviour
{
public GameObject anchoredObject;
public WorldAnchorManager store;
private string anchorId = "AnchoredCube";
private bool savedRoot;
void Start()
{
store.AttachAnchor(anchoredObject, anchorId);
}
void Update()
{
if (Input.GetKeyDown(KeyCode.L))
{
store.AttachAnchor(anchoredObject, anchorId);
}
if (Input.GetKeyDown(KeyCode.Return))
{
if (anchoredObject != null)
store.RemoveAnchor(anchorId);
anchoredObject.transform.position = this.transform.position;
store.AttachAnchor(anchoredObject, anchorId);
}
}
}
【问题讨论】:
标签: unity3d hololens windows-mixed-reality