using System;
using UnityEngine.XR.OpenXR;
using UnityEngine.XR.OpenXR.Features;
#if UNITY_EDITOR || PACKAGE_DOCS_GENERATION
namespace UnityEditor.XR.OpenXR.Features
{
public class FeatureCategory
{
public const string Default = "";
public const string Feature = "Feature";
public const string Interaction = "Interaction";
}
[AttributeUsage(AttributeTargets.Class)]
public class OpenXRFeatureAttribute : Attribute
{
internal class CopyFieldAttribute : Attribute
{
public string FieldName;
public CopyFieldAttribute(string fieldName)
{
FieldName = fieldName;
}
}
///
/// Feature name to show in the feature configuration UI.
///
[CopyField(nameof(OpenXRFeature.nameUi))] public string UiName;
///
/// Hide this feature from the UI.
///
public bool Hidden;
///
/// Feature description to show in the UI.
///
public string Desc;
///
/// OpenXR runtime extension strings that need to be enabled to use this extension.
/// If these extensions can't be enabled, a message will be logged, but execution will continue.
/// Can contain multiple extensions separated by spaces.
///
[CopyField(nameof(OpenXRFeature.openxrExtensionStrings))] public string OpenxrExtensionStrings;
///
/// Company that created the feature, shown in the feature configuration UI.
///
[CopyField(nameof(OpenXRFeature.company))] public string Company;
///
/// Link to the feature documentation. The help button in the UI opens this link in a web browser.
///
public string DocumentationLink;
///
/// Feature version.
///
[CopyField(nameof(OpenXRFeature.version))] public string Version;
///
/// BuildTargets in this list use a custom runtime loader (that is, openxr_loader.dll).
/// Only one feature per platform can have a custom runtime loader.
/// Unity will skip copying the default loader to the build and use this feature's loader instead on these platforms.
/// Loader must be placed alongside the OpenXRFeature script or in a subfolder of it.
///
public BuildTarget[] CustomRuntimeLoaderBuildTargets;
///
/// BuildTargetsGroups that this feature supports. The feature will only be shown or included on these platforms.
///
public BuildTargetGroup[] BuildTargetGroups;
///
/// Feature category.
///
public string Category = "";
///
/// True if this feature is required, false otherwise.
/// Required features will cause the loader to fail to initialize if they fail to initialize or start.
///
[CopyField(nameof(OpenXRFeature.required))] public bool Required = false;
///
/// Determines the order in which the feature will be called in both the GetInstanceProcAddr hook list and
/// when events such as OnInstanceCreate are called. Higher priority features will hook after lower priority features and
/// be called first in the event list.
///
[CopyField(nameof(OpenXRFeature.priority))] public int Priority = 0;
///
/// A well known string id for this feature. It is recommended that that id be in reverse DNS naming format (com.foo.bar.feature).
///
[CopyField(nameof(OpenXRFeature.featureIdInternal))] public string FeatureId = "";
internal static readonly System.Text.RegularExpressions.Regex k_PackageVersionRegex = new System.Text.RegularExpressions.Regex(@"(\d*\.\d*)\..*");
///
/// This method returns the OpenXR internal documentation link. This is necessary because the documentation link was made public in the
/// Costants class which prevents it from being alterned in anything but a major revision. This method will patch up the documentation links
/// as needed as long as they are internal openxr documentation links.
///
internal string InternalDocumentationLink
{
get
{
if (string.IsNullOrEmpty(DocumentationLink))
return DocumentationLink;
// Update the version if needed
if (DocumentationLink.StartsWith(Constants.k_DocumentationManualURL))
{
var version = PackageManager.PackageInfo.FindForAssembly(typeof(OpenXRFeatureAttribute).Assembly)?.version;
var majorminor = k_PackageVersionRegex.Match(version).Groups[1].Value;
DocumentationLink = DocumentationLink.Replace("1.0", majorminor);
}
return DocumentationLink;
}
}
}
}
#endif