using System.Collections.Generic; using UnityEngine.SceneManagement; namespace UnityEngine.XR.Simulation { static class XRayRuntimeUtils { static readonly Dictionary m_XRayRegions = new(); /// /// Dictionary of scenes that contain an XRay Region. /// public static IReadOnlyDictionary xRayRegions => m_XRayRegions; /// /// Assign an XRay Region to be the active region for the region's scene. /// /// XRay Region to assign to be used the the XRayModule. public static void AssignXRayRegion(XRayRegion xRayRegion) { var scene = xRayRegion.gameObject.scene; if (!scene.IsValid()) return; if (!m_XRayRegions.TryGetValue(scene, out var cachedRegion)) { m_XRayRegions.Add(scene, xRayRegion); } else if (cachedRegion != null) { Debug.LogWarning( $"{scene.name} already has a XRay Region on {cachedRegion.gameObject.name}. Replacing with new region on {xRayRegion.gameObject.name}"); m_XRayRegions[scene] = xRayRegion; } else { m_XRayRegions[scene] = xRayRegion; } } /// /// Remove a XRay Region from use. /// /// XRay Region to remove from use. public static void RemoveXRayRegion(XRayRegion xRayRegion) { var scene = xRayRegion.gameObject.scene; if (!scene.IsValid()) return; if (m_XRayRegions.TryGetValue(scene, out var cachedRegion)) { if (cachedRegion == xRayRegion) m_XRayRegions.Remove(scene); } } } }