using System; #if UNITY_EDITOR using System.Collections.Generic; using UnityEditor; using UnityEngine.XR.OpenXR.Features; #endif namespace UnityEngine.XR.OpenXR { #if UNITY_EDITOR public interface IPackageSettings { OpenXRSettings GetSettingsForBuildTargetGroup(UnityEditor.BuildTargetGroup buildTargetGroup); string GetActiveLoaderLibraryPath(); /// /// Returns all features of a given type from all existing build target groups. /// /// Feature type /// All known features of the given type within the package settings public IEnumerable<(BuildTargetGroup buildTargetGroup, T feature)> GetFeatures() where T : OpenXRFeature; internal void RefreshFeatureSets(); internal string PackageSettingsAssetPath(); } #endif /// /// Build time settings for OpenXR. These are serialized and available at runtime. /// [Serializable] public partial class OpenXRSettings : ScriptableObject { #if UNITY_EDITOR internal bool versionChanged = false; #else private static OpenXRSettings s_RuntimeInstance = null; private void Awake() { s_RuntimeInstance = this; } #endif internal void ApplySettings() { ApplyRenderSettings(); } #if UNITY_EDITOR private void OnValidate() { if (Application.isPlaying) ApplySettings(); } #endif private static OpenXRSettings GetInstance(bool useActiveBuildTarget) { OpenXRSettings settings = null; // When running in the Unity Editor, we have to load user's customization of configuration data directly from // EditorBuildSettings. At runtime, we need to grab it from the static instance field instead. #if UNITY_EDITOR settings = GetSettingsForBuildTargetGroup(useActiveBuildTarget ? BuildPipeline.GetBuildTargetGroup(UnityEditor.EditorUserBuildSettings.activeBuildTarget) : BuildTargetGroup.Standalone); #else settings = s_RuntimeInstance; if (settings == null) settings = ScriptableObject.CreateInstance(); #endif return settings; } #if UNITY_EDITOR /// /// Returns the Settings object for the given BuildTargetGroup /// /// BuildTargetGroup to request settings for /// OpenXRSettings object for the given build target group public static OpenXRSettings GetSettingsForBuildTargetGroup(BuildTargetGroup buildTargetGroup) { var packageSettings = GetPackageSettings(); if (null == packageSettings) return null; return packageSettings.GetSettingsForBuildTargetGroup(buildTargetGroup); } internal static IPackageSettings GetPackageSettings() { if (EditorBuildSettings.TryGetConfigObject(Constants.k_SettingsKey, out var obj) && (obj is IPackageSettings packageSettings)) return packageSettings; return null; } #endif /// /// Accessor to OpenXR build time settings. /// /// In the Unity Editor, this returns the settings for the active build target group. /// public static OpenXRSettings ActiveBuildTargetInstance => GetInstance(true); /// /// Accessor to OpenXR build time settings. /// /// In the Unity Editor, this returns the settings for the Standalone build target group. /// public static OpenXRSettings Instance => GetInstance(false); } }