Skip to content

Instantly share code, notes, and snippets.

@camnewnham
Created January 11, 2020 05:12
Show Gist options
  • Save camnewnham/b0f450b37d7fcf77ebede0d710eb40f8 to your computer and use it in GitHub Desktop.
Save camnewnham/b0f450b37d7fcf77ebede0d710eb40f8 to your computer and use it in GitHub Desktop.
A coordinate system that updates when the scene changes
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