private static void SetUpAppRemoting(BuildTargetGroup targetGroup) { Debug.Log($"Setting up app remoting for {targetGroup}"); const string AppRemotingPlugin = "Microsoft.MixedReality.OpenXR.Remoting.AppRemotingPlugin"; Type appRemotingFeature = typeof(AppRemoting).Assembly.GetType(AppRemotingPlugin); if (appRemotingFeature == null) { Debug.LogError($"Could not find {AppRemotingPlugin}. Has this class been removed or renamed?"); return; } FeatureHelpers.RefreshFeatures(targetGroup); OpenXRFeature feature = OpenXRSettings.ActiveBuildTargetInstance.GetFeature(appRemotingFeature); if (feature == null) { Debug.LogError($"Could not load {AppRemotingPlugin} as an OpenXR feature. Has this class been removed or renamed?"); return; } feature.enabled = true; XRGeneralSettings settings = XRGeneralSettingsPerBuildTarget.XRGeneralSettingsForBuildTarget(targetGroup); if (settings != null) { settings.InitManagerOnStart = false; } }
private bool IsExtensionEnabled(BuildTarget target, BuildTargetGroup group) { if (!BuildHelperUtils.HasLoader(group, typeof(OpenXRLoaderBase))) { return(false); } if (OpenXRSettings.ActiveBuildTargetInstance == null || OpenXRSettings.ActiveBuildTargetInstance.features == null) { return(false); } if (_ext == null || _ext.GetType() != featureType) { foreach (var ext in OpenXRSettings.ActiveBuildTargetInstance.features) { if (featureType == ext.GetType()) { _ext = ext; } } } if (_ext == null || !_ext.enabled) { return(false); } return(true); }
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; } }
/// <summary> /// Gathers and evaluates validation issues and adds them to a list. /// </summary> /// <param name="issues">List of validation issues to populate. List is cleared before populating.</param> /// <param name="buildTarget">Build target group to check for validation issues</param> public static void GetCurrentValidationIssues(List <OpenXRFeature.ValidationRule> issues, BuildTargetGroup buildTargetGroup) { CachedValidationList.Clear(); CachedValidationList.AddRange(BuiltinValidationRules); OpenXRFeature.GetValidationList(CachedValidationList, buildTargetGroup); issues.Clear(); foreach (var validation in CachedValidationList) { if (!validation.checkPredicate?.Invoke() ?? false) { issues.Add(validation); } } }
private void StopInternal() { OpenXRFeature.ReceiveLoaderEvent(this, OpenXRFeature.LoaderEvent.SubsystemStop); if (inputSubsystem?.running ?? false) { StopSubsystem <XRInputSubsystem>(); } if (displaySubsystem?.running ?? false) { StopSubsystem <XRDisplaySubsystem>(); } OpenXRInput.Stop(); Internal_EndSession(); }
private bool StartInternal() { // In order to get XrReady, we have to at least attempt to create // the session if it isn't already there. if (!Internal_CreateSessionIfNeeded()) { return(false); } if (currentOpenXRState != OpenXRFeature.NativeEvent.XrReady || (currentLoaderState != LoaderState.StartAttempted && currentLoaderState != LoaderState.Started)) { return(true); } // calls xrBeginSession Internal_BeginSession(); OpenXRInput.AttachActionSets(); // Note: Display has to be started before Input so that Input can have access to the Session object StartSubsystem <XRDisplaySubsystem>(); if (!displaySubsystem?.running ?? false) { return(false); } StartSubsystem <XRInputSubsystem>(); if (!inputSubsystem?.running ?? false) { return(false); } OpenXRFeature.ReceiveLoaderEvent(this, OpenXRFeature.LoaderEvent.SubsystemStart); return(true); }
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; } }
/// <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; } }
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); }
private void ApplySelectedConfiguration(MixedRealityProjectConfiguration selectedMRConfiguration) { bool remoting = false; BuildTargetGroup targetGroup; switch (selectedMRConfiguration) { case MixedRealityProjectConfiguration.RunNativelyOnHL2: targetGroup = BuildTargetGroup.WSA; EditorUserBuildSettings.SwitchActiveBuildTargetAsync(BuildTargetGroup.WSA, BuildTarget.WSAPlayer); EditorUserBuildSettings.wsaBuildAndRunDeployTarget = WSABuildAndRunDeployTarget.DevicePortal; EditorUserBuildSettings.wsaArchitecture = "ARM64"; break; case MixedRealityProjectConfiguration.RunNativelyOnPCVR: targetGroup = BuildTargetGroup.Standalone; EditorUserBuildSettings.SwitchActiveBuildTargetAsync(BuildTargetGroup.Standalone, BuildTarget.StandaloneWindows64); break; case MixedRealityProjectConfiguration.RunRemotelyOnUWP: remoting = true; targetGroup = BuildTargetGroup.WSA; EditorUserBuildSettings.SwitchActiveBuildTargetAsync(BuildTargetGroup.WSA, BuildTarget.WSAPlayer); EditorUserBuildSettings.wsaBuildAndRunDeployTarget = WSABuildAndRunDeployTarget.LocalMachine; EditorUserBuildSettings.wsaArchitecture = "Intel64"; // Player Capabilities UnityEditor.PlayerSettings.WSA.SetCapability(UnityEditor.PlayerSettings.WSACapability.InternetClient, true); UnityEditor.PlayerSettings.WSA.SetCapability(UnityEditor.PlayerSettings.WSACapability.InternetClientServer, true); UnityEditor.PlayerSettings.WSA.SetCapability(UnityEditor.PlayerSettings.WSACapability.PrivateNetworkClientServer, true); break; case MixedRealityProjectConfiguration.RunRemotelyOnWin32: remoting = true; targetGroup = BuildTargetGroup.Standalone; EditorUserBuildSettings.SwitchActiveBuildTargetAsync(BuildTargetGroup.Standalone, BuildTarget.StandaloneWindows64); break; default: return; } const string AppRemotingPlugin = "Microsoft.MixedReality.OpenXR.Remoting.AppRemotingPlugin"; Type appRemotingFeature = typeof(AppRemoting).Assembly.GetType(AppRemotingPlugin); if (appRemotingFeature == null) { Debug.LogError($"Could not find {AppRemotingPlugin}. Has this class been removed or renamed?"); return; } FeatureHelpers.RefreshFeatures(targetGroup); OpenXRFeature feature = OpenXRSettings.ActiveBuildTargetInstance.GetFeature(appRemotingFeature); if (feature == null) { Debug.LogError($"Could not load {AppRemotingPlugin} as an OpenXR feature. Has this class been removed or renamed?"); return; } feature.enabled = remoting; XRGeneralSettings settings = XRGeneralSettingsPerBuildTarget.XRGeneralSettingsForBuildTarget(targetGroup); if (settings != null) { settings.InitManagerOnStart = !remoting; } Debug.Log($"Set up complete for {selectedMRConfiguration}"); }