using System; using System.Collections.Generic; using System.Runtime.CompilerServices; using UnityEngine.XR.OpenXR.Features; using UnityEngine.Serialization; [assembly: InternalsVisibleTo("UnityEditor.XR.OpenXR.Tests")] namespace UnityEngine.XR.OpenXR { public partial class OpenXRSettings { /// /// All known features. /// [FormerlySerializedAs("extensions")] [HideInInspector] [SerializeField] internal OpenXRFeature[] features = { }; /// /// Number of available features. /// public int featureCount => features.Length; /// /// Returns the first feature that matches the given type. /// /// Type of the feature to retrieve /// Feature by type public TFeature GetFeature() where TFeature : OpenXRFeature => (TFeature)GetFeature(typeof(TFeature)); /// /// Returns the first feature that matches the given type. /// /// Type of the feature to return /// Feature by type public OpenXRFeature GetFeature(Type featureType) { foreach (var feature in features) if (featureType.IsInstanceOfType(feature)) return feature; return null; } /// /// Returns all features of a given type. /// /// Type of the feature to retrieve /// All components of Type public OpenXRFeature[] GetFeatures() => GetFeatures(typeof(TFeature)); /// /// Returns all features of Type. /// /// Type of the feature to retrieve /// All components of Type public OpenXRFeature[] GetFeatures(Type featureType) { var result = new List(); foreach (var feature in features) if (featureType.IsInstanceOfType(feature)) result.Add(feature); return result.ToArray(); } /// /// Returns all features of a given type. /// /// Output list of features /// Feature type /// Number of features returned public int GetFeatures(List featuresOut) where TFeature : OpenXRFeature { featuresOut.Clear(); foreach (var feature in features) if (feature is TFeature xrFeature) featuresOut.Add(xrFeature); return featuresOut.Count; } /// /// Returns all features of a given type. /// /// Type of the feature to retrieve /// Output list of features /// Number of features returned public int GetFeatures(Type featureType, List featuresOut) { featuresOut.Clear(); foreach (var feature in features) if (featureType.IsInstanceOfType(feature)) featuresOut.Add(feature); return featuresOut.Count; } /// /// Return all features. /// /// All features public OpenXRFeature[] GetFeatures() => (OpenXRFeature[])features?.Clone() ?? new OpenXRFeature[0]; /// /// Return all features. /// /// Output list of features /// Number of features returned public int GetFeatures(List featuresOut) { featuresOut.Clear(); featuresOut.AddRange(features); return featuresOut.Count; } } }