/// <summary>
 ///
 /// </summary>
 public MixedRealityControllerAttribute(
     SupportedControllerType supportedControllerType,
     Handedness[] supportedHandedness,
     string texturePath = "",
     MixedRealityControllerConfigurationFlags flags      = 0,
     SupportedUnityXRPipelines supportedUnityXRPipelines = (SupportedUnityXRPipelines)(-1))
 {
     SupportedControllerType = supportedControllerType;
     SupportedHandedness     = supportedHandedness;
     TexturePath             = texturePath;
     Flags = flags;
     SupportedUnityXRPipelines = supportedUnityXRPipelines;
 }
 public MixedRealityDataProviderAttribute(
     Type serviceInterfaceType,
     SupportedPlatforms runtimePlatforms,
     string name          = "",
     string profilePath   = "",
     string packageFolder = "MixedRealityToolkit",
     bool requiresProfile = false,
     SupportedUnityXRPipelines supportedUnityXRPipelines = (SupportedUnityXRPipelines)(-1))
     : base(runtimePlatforms, name, profilePath, packageFolder, requiresProfile)
 {
     ServiceInterfaceType      = serviceInterfaceType;
     SupportedUnityXRPipelines = supportedUnityXRPipelines;
 }
Esempio n. 3
0
 /// <summary>
 /// Checks to determine if all bits in a provided mask are set.
 /// </summary>
 /// <param name="a"><see cref="SupportedUnityXRPipelines"/> value.</param>
 /// <param name="b"><see cref="SupportedUnityXRPipelines"/> mask.</param>
 /// <returns>
 /// True if all of the bits in the specified mask are set in the current value.
 /// </returns>
 public static bool IsMaskSet(this SupportedUnityXRPipelines a, SupportedUnityXRPipelines b)
 {
     return((a & b) == b);
 }
Esempio n. 4
0
        /// <summary>
        /// Internal method that creates an instance of the specified concrete type and registers the provider.
        /// </summary>
        private bool RegisterDataProviderInternal <T>(
            bool retryWithRegistrar,
            Type concreteType,
            string providerName,
            SupportedPlatforms supportedPlatforms = (SupportedPlatforms)(-1),
            params object[] args) where T : IMixedRealityDataProvider
        {
            if (!PlatformUtility.IsPlatformSupported(supportedPlatforms))
            {
                DebugUtilities.LogVerboseFormat(
                    "Not registering data provider of type {0} with name {1} because the current platform is not in supported platforms {2}",
                    concreteType,
                    providerName,
                    supportedPlatforms);
                return(false);
            }

            if (concreteType == null)
            {
                if (!Application.isEditor)
                {
                    Debug.LogWarning($"Unable to register {typeof(T).Name} data provider ({(!string.IsNullOrWhiteSpace(providerName) ? providerName : "unknown")}) because the value of concreteType is null.\n" +
                                     "This may be caused by code being stripped during linking. The link.xml file in the MixedRealityToolkit.Generated folder is used to control code preservation.\n" +
                                     "More information can be found at https://docs.unity3d.com/Manual/ManagedCodeStripping.html.");
                }
                return(false);
            }

            SupportedUnityXRPipelines selectedPipeline =
#if UNITY_2020_1_OR_NEWER
                SupportedUnityXRPipelines.XRSDK;
#elif UNITY_2019
                !XRSettingsUtilities.LegacyXRAvailable ? SupportedUnityXRPipelines.XRSDK : SupportedUnityXRPipelines.LegacyXR;
#else
                SupportedUnityXRPipelines.LegacyXR;
#endif

            if (MixedRealityExtensionServiceAttribute.Find(concreteType) is MixedRealityDataProviderAttribute providerAttribute)
            {
                if (!providerAttribute.SupportedUnityXRPipelines.HasFlag(selectedPipeline))
                {
                    DebugUtilities.LogVerboseFormat("{0} not suitable for the current XR pipeline ({1})", concreteType.Name, selectedPipeline);
                    return(false);
                }
            }

            if (!typeof(IMixedRealityDataProvider).IsAssignableFrom(concreteType))
            {
                Debug.LogError($"Unable to register the {concreteType.Name} data provider. It does not implement {typeof(IMixedRealityDataProvider)}.");
                return(false);
            }

            T dataProviderInstance;

            try
            {
                dataProviderInstance = (T)Activator.CreateInstance(concreteType, args);
            }
            catch (Exception e)
            {
                if (retryWithRegistrar && (e is MissingMethodException))
                {
                    Debug.LogWarning($"Failed to find an appropriate constructor for the {concreteType.Name} data provider. Adding the Registrar instance and re-attempting registration.");
#pragma warning disable 0618
                    List <object> updatedArgs = new List <object>();
                    updatedArgs.Add(Registrar);
                    if (args != null)
                    {
                        updatedArgs.AddRange(args);
                    }
                    return(RegisterDataProviderInternal <T>(
                               false, // Do NOT retry, we have already added the configured IMIxedRealityServiceRegistrar
                               concreteType,
                               providerName,
                               supportedPlatforms,
                               updatedArgs.ToArray()));

#pragma warning restore 0618
                }

                Debug.LogError($"Failed to register the {concreteType.Name} data provider: {e.GetType()} - {e.Message}");

                // Failures to create the concrete type generally surface as nested exceptions - just logging
                // the top level exception itself may not be helpful. If there is a nested exception (for example,
                // null reference in the constructor of the object itself), it's helpful to also surface those here.
                if (e.InnerException != null)
                {
                    Debug.LogError("Underlying exception information: " + e.InnerException);
                }
                return(false);
            }

            return(RegisterDataProvider(dataProviderInstance));
        }