예제 #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);
        }
        /// <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);
        }
예제 #3
0
        private bool InitializeInternal()
        {
            Instance = this;

            currentLoaderState = LoaderState.InitializeAttempted;

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

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

            OpenXRFeature.Initialize();

            if (!LoadOpenXRSymbols())
            {
                Debug.LogError("Failed to load openxr runtime loader.");
                return(false);
            }

            // Sort the features array by priority in descending order (highest priority first)
            OpenXRSettings.Instance.features = OpenXRSettings.Instance.features
                                               .Where(f => f != null)
                                               .OrderByDescending(f => f.priority)
                                               .ThenBy(f => f.nameUi)
                                               .ToArray();

            OpenXRFeature.HookGetInstanceProcAddr();

            if (!Internal_InitializeSession())
            {
                return(false);
            }

            SetApplicationInfo();
            RequestOpenXRFeatures();
            RegisterOpenXRCallbacks();

            if (null != OpenXRSettings.Instance)
            {
                OpenXRSettings.Instance.ApplySettings();
            }

            if (!CreateSubsystems())
            {
                return(false);
            }

            if (OpenXRFeature.requiredFeatureFailed)
            {
                return(false);
            }

            OpenXRAnalytics.SendInitializeEvent(true);

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

            OpenXRInput.Initialize();

            DebugLogEnabledSpecExtensions();

            Application.onBeforeRender += ProcessOpenXRMessageLoop;
            currentLoaderState          = LoaderState.Initialized;
            return(true);
        }