Пример #1
0
        /// <summary>
        /// See [XRLoader.Initialize](xref:UnityEngine.XR.Management.XRLoader.Initialize)
        /// </summary>
        /// <returns>True if initialized, false otherwise.</returns>
        public override bool Initialize()
        {
            if (currentLoaderState == LoaderState.Initialized)
            {
                return(true);
            }

            if (!validLoaderInitStates.Contains(currentLoaderState))
            {
                return(false);
            }

            if (Instance != null)
            {
                Debug.LogError("Only one OpenXRLoader can be initialized at any given time");
                return(false);
            }

            DiagnosticReport.StartReport();

            if (!InitializeInternal())
            {
                Deinitialize();
                Instance = null;
                OpenXRAnalytics.SendInitializeEvent(false);
                return(false);
            }

            return(true);
        }
Пример #2
0
        private void SetApplicationInfo()
        {
            uint appVersion    = 0;
            uint engineVersion = 0;

            {
                var    md5  = MD5.Create();
                byte[] data = md5.ComputeHash(Encoding.UTF8.GetBytes(Application.version));
                if (BitConverter.IsLittleEndian)
                {
                    Array.Reverse(data);
                }
                appVersion = BitConverter.ToUInt32(data, 0);
            }

            {
                var    md5  = MD5.Create();
                byte[] data = md5.ComputeHash(Encoding.UTF8.GetBytes(Application.unityVersion));
                if (BitConverter.IsLittleEndian)
                {
                    Array.Reverse(data);
                }
                engineVersion = BitConverter.ToUInt32(data, 0);
            }


            var section = DiagnosticReport.GetSection("OpenXR Provider Info");

            DiagnosticReport.AddSectionEntry(section, "Spec Version", $"{OpenXRRuntime.apiVersion}");
            DiagnosticReport.AddSectionEntry(section, "Provider Version", $"{OpenXRRuntime.pluginVersion}");
            DiagnosticReport.AddSectionEntry(section, "App", $"{Application.productName} {Application.version} #{appVersion}");
            DiagnosticReport.AddSectionEntry(section, "Engine", $"{Application.unityVersion} #{engineVersion}");

            Internal_SetApplicationInfo(Application.productName, appVersion, engineVersion);
        }
        private static void ReceiveNativeEvent(OpenXRFeature.NativeEvent e, ulong payload)
        {
            var loader = Instance;

            if (loader != null)
            {
                loader.currentOpenXRState = e;
            }

            switch (e)
            {
            case OpenXRFeature.NativeEvent.XrRestartRequested:
                OpenXRRestarter.Instance.ShutdownAndRestart();
                break;

            case OpenXRFeature.NativeEvent.XrReady:
                loader.StartInternal();
                break;

            case OpenXRFeature.NativeEvent.XrFocused:
                DiagnosticReport.DumpReport("System Startup Completed");
                break;

            default:
                break;
            }

            OpenXRFeature.ReceiveNativeEvent(e, payload);

            if ((loader == null || !loader.isStarted) && e != OpenXRFeature.NativeEvent.XrInstanceChanged)
            {
                return;
            }

            switch (e)
            {
            case OpenXRFeature.NativeEvent.XrStopping:
                loader.StopInternal();
                break;

            case OpenXRFeature.NativeEvent.XrExiting:
                OpenXRRestarter.Instance.Shutdown();
                break;

            case OpenXRFeature.NativeEvent.XrLossPending:
                OpenXRRestarter.Instance.ShutdownAndRestart();
                break;

            case OpenXRFeature.NativeEvent.XrInstanceLossPending:
                OpenXRRestarter.Instance.Shutdown();
                break;

            default:
                break;
            }
        }
        private void RequestOpenXRFeatures()
        {
            var instance = OpenXRSettings.Instance;

            if (instance == null || instance.features == null)
            {
                return;
            }

            StringBuilder requestedLog = new StringBuilder("");
            StringBuilder failedLog    = new StringBuilder("");
            uint          count        = 0;
            uint          failedCount  = 0;

            foreach (var feature in instance.features)
            {
                if (feature == null || !feature.enabled)
                {
                    continue;
                }

                ++count;

                requestedLog.Append($"  {feature.nameUi}: Version={feature.version}, Company=\"{feature.company}\"");

                if (!string.IsNullOrEmpty(feature.openxrExtensionStrings))
                {
                    requestedLog.Append($", Extensions=\"{feature.openxrExtensionStrings}\"");

                    // Check to see if any of the required extensions are not supported by the runtime
                    foreach (var extensionString in feature.openxrExtensionStrings.Split(' '))
                    {
                        if (string.IsNullOrWhiteSpace(extensionString))
                        {
                            continue;
                        }
                        if (!Internal_RequestEnableExtensionString(extensionString))
                        {
                            ++failedCount;
                            failedLog.Append($"  {extensionString}: Feature=\"{feature.nameUi}\": Version={feature.version}, Company=\"{feature.company}\"\n");
                        }
                    }
                }

                requestedLog.Append("\n");
            }

            var section = DiagnosticReport.GetSection("OpenXR Runtime Info");

            DiagnosticReport.AddSectionBreak(section);
            DiagnosticReport.AddSectionEntry(section, "Features requested to be enabled", $"({count})\n{requestedLog.ToString()}");
            DiagnosticReport.AddSectionBreak(section);
            DiagnosticReport.AddSectionEntry(section, "Requested feature extensions not supported by runtime", $"({failedCount})\n{failedLog.ToString()}");
        }
        /// <summary>
        /// See [XRLoader.Initialize](xref:UnityEngine.XR.Management.XRLoader.Initialize)
        /// </summary>
        /// <returns>True if initialized, false otherwise.</returns>
        public override bool Initialize()
        {
            if (currentLoaderState == LoaderState.Initialized)
            {
                return(true);
            }

            if (!validLoaderInitStates.Contains(currentLoaderState))
            {
                return(false);
            }

            if (Instance != null)
            {
                Debug.LogError("Only one OpenXRLoader can be initialized at any given time");
                return(false);
            }

#if UNITY_EDITOR
            if (!DisableValidationChecksOnEnteringPlaymode)
            {
                if (OpenXRProjectValidation.LogPlaymodeValidationIssues())
                {
                    return(false);
                }
            }

            OpenXRSettings.Instance.lastPlayVersion = UnityEditor.PackageManager.PackageInfo.FindForAssembly(GetType().Assembly)?.version;
#endif

            DiagnosticReport.StartReport();

            // Wrap the initialization in a try catch block to ensure if any exceptions are thrown that
            // we cleanup, otherwise the user will not be able to run again until they restart the editor.
            try
            {
                if (InitializeInternal())
                {
                    return(true);
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }

            Deinitialize();
            Instance = null;
            OpenXRAnalytics.SendInitializeEvent(false);

            return(false);
        }
Пример #6
0
        private void RequestOpenXRFeatures()
        {
            var instance = OpenXRSettings.Instance;

            if (instance == null || instance.features == null)
            {
                return;
            }

            StringBuilder requestedLog = new StringBuilder("");
            StringBuilder failedLog    = new StringBuilder("");
            uint          count        = 0;
            uint          failedCount  = 0;

            foreach (var feature in instance.features)
            {
                if (feature != null && feature.enabled)
                {
                    ++count;
                    if (string.IsNullOrEmpty(feature.openxrExtensionStrings))
                    {
                        requestedLog.Append($"    Name={feature.nameUi} Extension=NA Version={feature.version}\n");
                        continue;
                    }
                    else
                    {
                        requestedLog.Append($"    Name={feature.nameUi} Extension={feature.openxrExtensionStrings} Version={feature.version}\n");
                    }

                    foreach (var extensionString in feature.openxrExtensionStrings.Split(' '))
                    {
                        if (string.IsNullOrEmpty(extensionString))
                        {
                            continue;
                        }
                        if (!Internal_RequestEnableExtensionString(extensionString))
                        {
                            ++failedCount;
                            failedLog.Append($"    Name={feature.nameUi} Extension={extensionString}  Version={feature.version}\n");
                        }
                    }
                }
            }

            var section = DiagnosticReport.GetSection("OpenXR Runtime Info");

            DiagnosticReport.AddSectionBreak(section);
            DiagnosticReport.AddSectionEntry(section, "Features requested to be enabled", $"{count}\n{requestedLog.ToString()}");
            DiagnosticReport.AddSectionBreak(section);
            DiagnosticReport.AddSectionEntry(section, "Features failed to be enabled", $"{failedCount}\n{failedLog.ToString()}");
        }
Пример #7
0
        static void ExceptionHandler(object sender, UnhandledExceptionEventArgs args)
        {
            var section = DiagnosticReport.GetSection("Unhandled Exception Report");

            DiagnosticReport.AddSectionEntry(section, "Is Terminating", $"{args.IsTerminating}");

            var e = (Exception)args.ExceptionObject;

            DiagnosticReport.AddSectionEntry(section, "Message", $"{e.Message}");
            DiagnosticReport.AddSectionEntry(section, "Source", $"{e.Source}");
            DiagnosticReport.AddSectionEntry(section, "Stack Trace", $"\n{e.StackTrace}");

            DiagnosticReport.DumpReport("Uncaught Exception");
        }
Пример #8
0
        private static void DebugLogEnabledSpecExtensions()
        {
            var section = DiagnosticReport.GetSection("OpenXR Runtime Info");

            DiagnosticReport.AddSectionBreak(section);

            var extensions = OpenXRRuntime.GetEnabledExtensions();
            var log        = new StringBuilder($"({extensions.Length})\n");

            foreach (var extension in extensions)
            {
                log.Append($"  Name={extension} Version={OpenXRRuntime.GetExtensionVersion(extension)}\n");
            }

            DiagnosticReport.AddSectionEntry(section, "Spec extensions enabled", log.ToString());
        }
Пример #9
0
        private static void ReceiveNativeEvent(OpenXRFeature.NativeEvent e, ulong payload)
        {
            var loader = Instance;

            if (loader != null)
            {
                loader.currentOpenXRState = e;
            }

            switch (e)
            {
            case OpenXRFeature.NativeEvent.XrRestartRequested:
                CreateRestarter(loader, true);
                break;

            case OpenXRFeature.NativeEvent.XrReady:
                loader.StartInternal();
                break;

            case OpenXRFeature.NativeEvent.XrFocused:
                DiagnosticReport.DumpReport("System Startup Completed");
                break;

            default:
                break;
            }

            OpenXRFeature.ReceiveNativeEvent(e, payload);

            if ((loader == null || !loader.isStarted) && e != OpenXRFeature.NativeEvent.XrInstanceChanged)
            {
                return;
            }

            switch (e)
            {
            case OpenXRFeature.NativeEvent.XrInstanceChanged:
                OpenXRInput.InstanceHasChanged();
                OpenXRInput.SendActionDataToProvider();
                break;

            case OpenXRFeature.NativeEvent.XrSessionChanged:
                OpenXRInput.CreateActionsAndSuggestedBindings();
                OpenXRInput.AttachActionSetsToSession();
                break;

            case OpenXRFeature.NativeEvent.XrStopping:
                loader.StopInternal();
                break;

            case OpenXRFeature.NativeEvent.XrExiting:
                CreateRestarter(loader, false);
                break;

            case OpenXRFeature.NativeEvent.XrLossPending:
                CreateRestarter(loader, true);
                break;

            case OpenXRFeature.NativeEvent.XrInstanceLossPending:
                OpenXRLoader.CreateRestarter(loader, false);
                break;

            default:
                break;
            }
        }
Пример #10
0
        /// <summary>
        /// See [XRLoader.DeInitialize](xref:UnityEngine.XR.Management.XRLoader.Stop)
        /// </summary>
        /// <returns>True if deinitialized, false otherwise.</returns>
        public override bool Deinitialize()
        {
            if (currentLoaderState == LoaderState.Uninitialized)
            {
                return(true);
            }

            if (!validLoaderDeinitStates.Contains(currentLoaderState))
            {
                return(false);
            }

            currentLoaderState = LoaderState.DeinitializeAttempted;

            try
            {
#if TEST_SUPPORT
                if (ShouldExitEarly())
                {
                    return(false);
                }

                // The test hook above will leave the loader in a half initialized state.  To work
                // around this we reset the instance pointer if it is missing.
                if (Instance == null)
                {
                    Instance = this;
                }
#endif
                Application.onBeforeRender -= ProcessOpenXRMessageLoop;

                ProcessOpenXRMessageLoop(); // Drain any remaining events.

                OpenXRFeature.ReceiveLoaderEvent(this, OpenXRFeature.LoaderEvent.SubsystemDestroy);

                DestroySubsystem <XRInputSubsystem>();
                DestroySubsystem <XRDisplaySubsystem>();

                DiagnosticReport.DumpReport("System Shutdown");

                Internal_DestroySession();

                ProcessOpenXRMessageLoop();

                Internal_UnloadOpenXRLibrary();

                currentLoaderState = LoaderState.Uninitialized;

                if (unhandledExceptionHandler != null)
                {
                    AppDomain currentDomain = AppDomain.CurrentDomain;
                    currentDomain.UnhandledException -= unhandledExceptionHandler;
                    unhandledExceptionHandler         = null;
                }

                return(base.Deinitialize());
            }
            finally
            {
                // Ensure we always clear the instance reference even if some part of Deinitialize threw an exception
                Instance = null;
            }
        }