// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using Microsoft.MixedReality.Toolkit.Utilities; using System; using System.Linq; using UnityEngine; #if UNITY_EDITOR using Microsoft.MixedReality.Toolkit.Utilities.Editor; using UnityEditor; #endif #if WINDOWS_UWP && !ENABLE_IL2CPP using Microsoft.MixedReality.Toolkit; #endif // WINDOWS_UWP && !ENABLE_IL2CPP namespace Microsoft.MixedReality.Toolkit { /// /// Attribute that defines the properties of a Mixed Reality Toolkit extension service. /// [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] public class MixedRealityExtensionServiceAttribute : Attribute { /// /// The friendly name for this service. /// public virtual string Name { get; } /// /// The runtime platform(s) to run this service. /// public virtual SupportedPlatforms RuntimePlatforms { get; } /// /// Is a profile explicitly required? /// public virtual bool RequiresProfile { get; } /// /// The file path to the default profile asset relative to the package folder. /// public virtual string DefaultProfilePath { get; } /// /// The package where the default profile asset resides. /// public virtual string PackageFolder { get; } /// /// The default profile. /// public virtual BaseMixedRealityProfile DefaultProfile { get { #if UNITY_EDITOR MixedRealityToolkitModuleType moduleType = MixedRealityToolkitFiles.GetModuleFromPackageFolder(PackageFolder); if (moduleType != MixedRealityToolkitModuleType.None) { string folder = MixedRealityToolkitFiles.MapModulePath(moduleType); if (!string.IsNullOrWhiteSpace(folder)) { return AssetDatabase.LoadAssetAtPath(System.IO.Path.Combine(folder, DefaultProfilePath)); } } else if (EditorProjectUtilities.FindRelativeDirectory(PackageFolder, out string folder)) { return AssetDatabase.LoadAssetAtPath(System.IO.Path.Combine(folder, DefaultProfilePath)); } // If we get here, there was an issue finding the profile. Debug.LogError("Unable to find or load the profile."); #endif return null; } } /// /// Constructor /// /// The platforms on which the extension service is supported. /// The relative path to the default profile asset. /// The package folder to which the path is relative. public MixedRealityExtensionServiceAttribute( SupportedPlatforms runtimePlatforms, string name = "", string defaultProfilePath = "", string packageFolder = "MixedRealityToolkit", bool requiresProfile = false) { RuntimePlatforms = runtimePlatforms; Name = name; DefaultProfilePath = defaultProfilePath; PackageFolder = packageFolder; RequiresProfile = requiresProfile; } /// /// Convenience function for retrieving the attribute given a certain class type. /// public static MixedRealityExtensionServiceAttribute Find(Type type) { return type.GetCustomAttributes(typeof(MixedRealityExtensionServiceAttribute), true).FirstOrDefault() as MixedRealityExtensionServiceAttribute; } } }