Created
January 11, 2020 05:12
-
-
Save camnewnham/b0f450b37d7fcf77ebede0d710eb40f8 to your computer and use it in GitHub Desktop.
A coordinate system that updates when the scene changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Runtime.InteropServices; | |
using UnityEngine; | |
namespace MyApp | |
{ | |
public static class HoloLensCoordinateSystem// : MonoBehaviour | |
{ | |
public static HoloLensCoordinateSystem Instance; | |
public static Windows.Perception.Spatial.SpatialCoordinateSystem Current; | |
void Awake() | |
{ | |
if (Instance != null) | |
{ | |
Debug.LogError($"{nameof(HoloLensCoordinateSystem)} is already initialized"); | |
Destroy(this); | |
} | |
Instance = this; | |
Debug.Log("Inititialized coordinate system."); | |
Current = Windows.Perception.Spatial.SpatialLocator.GetDefault().CreateStationaryFrameOfReferenceAtCurrentLocation().CoordinateSystem; | |
UnityEngine.SceneManagement.SceneManager.activeSceneChanged += SceneManager_activeSceneChanged; | |
} | |
private static void SceneManager_activeSceneChanged(UnityEngine.SceneManagement.Scene arg0, UnityEngine.SceneManagement.Scene arg1) | |
{ | |
Current = Windows.Perception.Spatial.SpatialLocator.GetDefault().CreateStationaryFrameOfReferenceAtCurrentLocation().CoordinateSystem; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment