简体   繁体   English

在Hololens中重新启动场景后应用坐标

[英]Apply coordinates after scene restart in hololens

I have the following setup right now: 我现在有以下设置:

  • "Startup" scene which initializes all managers (spatial mapping, cursors, camera, ...) “启动”场景可初始化所有管理器(空间映射,光标,摄像机等)
  • "Main" scene with animations and one object which moves around “主要”场景,带有动画和一个可移动的对象

Once the users interacts with the program the scene restarts at some point, then the following should happen: 用户与程序交互后,场景将在某个时间点重新开始,然后将发生以下情况:

  • Object's coordinates get stored (Eg DontDestroyOnLoad() on a "storage object". I need to destroy the object since it needs to reset itself on scene restart) 对象的坐标得到存储(例如,“存储对象”上的DontDestroyOnLoad()。我需要销毁该对象,因为它需要在场景重启时重置自身)
  • Scene restarts 场景重启
  • Object gets recreated with stored coordinates 使用存储的坐标重新创建对象

Code: 码:

DataPositionStorer positionStorer = new GameObject("DataPositionStorer").AddComponent<DataPositionStorer>();
DontDestroyOnLoad(positionStorer.gameObject);
// dataPoints is the specific object I need to keep the coordinates of
positionStorer.Position = dataPoints.transform.position;
positionStorer.Rotation = dataPoints.transform.rotation;
positionStorer.Zoom = dataPoints.transform.localScale;

// Reload current scene ("Main")
SceneManager.LoadScene(SceneManager.GetActiveScene().name);

And in the startup method of the object: 并在对象的启动方法中:

DataPositionStorer positionStorer = FindObjectOfType<DataPositionStorer>();
if (positionStorer!= null)
{
    dataPoints.transform.position = positionStorer.Position;
    dataPoints.transform.localRotation = positionStorer.Rotation;
    dataPoints.transform.localScale = positionStorer.Zoom;
}

This setup works in the unity player but once I run it in the hololens emulator / on a hololens the position afterwards isn't correct anymore. 此设置可在统一播放器中使用,但是一旦我在hololens仿真器中/在hololens上运行它,此后的位置就不再正确了。

Can somebody help me resolve this problem on the emulator / hololens? 有人可以帮助我解决模拟器/ Hololens上的此问题吗?

Thanks to the two guys commenting I've found a solution: 感谢两个人的评论,我找到了一个解决方案:

  • Load the WorldAnchorManager Script in the Setup scene and make it DontDestroyOnLoad 在设置场景中加载WorldAnchorManager脚本,并将其设置为DontDestroyOnLoad
  • Attach a World Anchor before the scene restarts 在场景重新开始之前附加一个世界锚点
  • Load the World Anchor after the scene restarted 场景重启后加载世界锚

This however only works on the emulator / HoloLens itself. 但是,这仅适用于仿真器/ HoloLens本身。 In the Unity Editor World Anchors don't work! 在Unity编辑器中,世界锚不起作用! So just copy paste the coordinates over like I did in my initial post. 因此,只需像我在初始帖子中那样复制坐标即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM