public static async Task <List <PredictionResult>?> PredictInputAsync(PredictionClient client, Ast ast, Token[] astTokens, int millisecondsTimeout) { Requires.Condition(millisecondsTimeout > 0, nameof(millisecondsTimeout)); var predictors = SubsystemManager.GetSubsystems <ICommandPredictor>(); if (predictors.Count == 0) { return(null); } var context = new PredictionContext(ast, astTokens); var tasks = new Task <PredictionResult?> [predictors.Count]; using var cancellationSource = new CancellationTokenSource(); Func <object?, PredictionResult?> callBack = GetCallBack(client, context, cancellationSource); for (int i = 0; i < predictors.Count; i++) { ICommandPredictor predictor = predictors[i]; tasks[i] = Task.Factory.StartNew( callBack, predictor, cancellationSource.Token, TaskCreationOptions.DenyChildAttach, TaskScheduler.Default); } await Task.WhenAny( Task.WhenAll(tasks), Task.Delay(millisecondsTimeout, cancellationSource.Token)).ConfigureAwait(false); cancellationSource.Cancel(); var resultList = new List <PredictionResult>(predictors.Count); foreach (Task <PredictionResult?> task in tasks) { if (task.IsCompletedSuccessfully) { PredictionResult?result = task.Result; if (result != null) { resultList.Add(result); } } } return(resultList);
public static void UnregisterSubsystem() { // Exception expected when no implementation is registered Assert.Throws <InvalidOperationException>(() => SubsystemManager.UnregisterSubsystem <ICommandPredictor>(predictor1.Id)); SubsystemManager.RegisterSubsystem <ICommandPredictor, MyPredictor>(predictor1); SubsystemManager.RegisterSubsystem(SubsystemKind.CommandPredictor, predictor2); // Exception is expected when specified id cannot be found Assert.Throws <InvalidOperationException>(() => SubsystemManager.UnregisterSubsystem <ICommandPredictor>(Guid.NewGuid())); // Unregister 'predictor1' SubsystemManager.UnregisterSubsystem <ICommandPredictor>(predictor1.Id); SubsystemInfo ssInfo = SubsystemManager.GetSubsystemInfo(SubsystemKind.CommandPredictor); VerifyCommandPredictorMetadata(ssInfo); Assert.True(ssInfo.IsRegistered); Assert.Single(ssInfo.Implementations); var implInfo = ssInfo.Implementations[0]; Assert.Equal(predictor2.Id, implInfo.Id); Assert.Equal(predictor2.Name, implInfo.Name); Assert.Equal(predictor2.Description, implInfo.Description); Assert.Equal(SubsystemKind.CommandPredictor, implInfo.Kind); Assert.Same(typeof(MyPredictor), implInfo.ImplementationType); ICommandPredictor impl = SubsystemManager.GetSubsystem <ICommandPredictor>(); Assert.Same(impl, predictor2); ReadOnlyCollection <ICommandPredictor> impls = SubsystemManager.GetSubsystems <ICommandPredictor>(); Assert.Single(impls); Assert.Same(predictor2, impls[0]); // Unregister 'predictor2' SubsystemManager.UnregisterSubsystem(SubsystemKind.CommandPredictor, predictor2.Id); VerifyCommandPredictorMetadata(ssInfo); Assert.False(ssInfo.IsRegistered); Assert.Empty(ssInfo.Implementations); impl = SubsystemManager.GetSubsystem <ICommandPredictor>(); Assert.Null(impl); impls = SubsystemManager.GetSubsystems <ICommandPredictor>(); Assert.Empty(impls); }
private void Update() { m_deltaTime += Time.unscaledDeltaTime; if (m_deltaTime > 1f / m_updateRate) { // Update screen window resolution m_sb.Length = 0; m_sb.Append(m_windowStrings[0]).Append(Screen.width.ToStringNonAlloc()) .Append(m_windowStrings[1]).Append(Screen.height.ToStringNonAlloc()) .Append(m_windowStrings[2]).Append(Screen.currentResolution.refreshRate.ToStringNonAlloc()) .Append(m_windowStrings[3]) .Append(m_windowStrings[4]).Append(((int)Screen.dpi).ToStringNonAlloc()) .Append(m_windowStrings[5]); m_gameWindowResolutionText.text = m_sb.ToString(); #if GRAPHY_XR // If XR enabled, update screen XR resolution if (XRSettings.enabled) { m_sb.Length = 0; #if UNITY_2020_2_OR_NEWER SubsystemManager.GetSubsystems(m_displaySubsystems); #else SubsystemManager.GetInstances(m_displaySubsystems); #endif float refreshRate = -1; if (m_displaySubsystems.Count > 0) { m_displaySubsystems[0].TryGetDisplayRefreshRate(out refreshRate); } m_sb.Append(m_vrStrings[0]).Append(XRSettings.eyeTextureWidth.ToStringNonAlloc()) .Append(m_vrStrings[1]).Append(XRSettings.eyeTextureHeight.ToStringNonAlloc()) .Append(m_vrStrings[2]).Append(Mathf.RoundToInt(refreshRate).ToStringNonAlloc()) .Append(m_vrStrings[3]); m_gameVRResolutionText.text = m_sb.ToString(); } #endif // Reset variables m_deltaTime = 0f; } }
internal static void XRSystemInit() { if (GraphicsSettings.currentRenderPipeline == null) { return; } SubsystemManager.GetSubsystems(displayList); // XRTODO: refactor with RefreshXrSdk() for (int i = 0; i < displayList.Count; i++) { displayList[i].disableLegacyRenderer = true; displayList[i].textureLayout = XRDisplaySubsystem.TextureLayout.Texture2DArray; displayList[i].sRGB = QualitySettings.activeColorSpace == ColorSpace.Linear; } }
public static void GetSubsystemInfo() { SubsystemInfo predictorInfo = SubsystemManager.GetSubsystemInfo(typeof(ICommandPredictor)); VerifyCommandPredictorMetadata(predictorInfo); Assert.False(predictorInfo.IsRegistered); Assert.Empty(predictorInfo.Implementations); SubsystemInfo predictorInfo2 = SubsystemManager.GetSubsystemInfo(SubsystemKind.CommandPredictor); Assert.Same(predictorInfo2, predictorInfo); SubsystemInfo crossPlatformDscInfo = SubsystemManager.GetSubsystemInfo(typeof(ICrossPlatformDsc)); VerifyCrossPlatformDscMetadata(crossPlatformDscInfo); Assert.False(crossPlatformDscInfo.IsRegistered); Assert.Empty(crossPlatformDscInfo.Implementations); SubsystemInfo crossPlatformDscInfo2 = SubsystemManager.GetSubsystemInfo(SubsystemKind.CrossPlatformDsc); Assert.Same(crossPlatformDscInfo2, crossPlatformDscInfo); ReadOnlyCollection <SubsystemInfo> ssInfos = SubsystemManager.GetAllSubsystemInfo(); Assert.Equal(2, ssInfos.Count); Assert.Same(ssInfos[0], predictorInfo); Assert.Same(ssInfos[1], crossPlatformDscInfo); ICommandPredictor predictorImpl = SubsystemManager.GetSubsystem <ICommandPredictor>(); Assert.Null(predictorImpl); ReadOnlyCollection <ICommandPredictor> predictorImpls = SubsystemManager.GetSubsystems <ICommandPredictor>(); Assert.Empty(predictorImpls); ICrossPlatformDsc crossPlatformDscImpl = SubsystemManager.GetSubsystem <ICrossPlatformDsc>(); Assert.Null(crossPlatformDscImpl); ReadOnlyCollection <ICrossPlatformDsc> crossPlatformDscImpls = SubsystemManager.GetSubsystems <ICrossPlatformDsc>(); Assert.Empty(crossPlatformDscImpls); }
public static void GetSubsystemInfo() { SubsystemInfo ssInfo = SubsystemManager.GetSubsystemInfo(typeof(ICommandPredictor)); VerifySubsystemMetadata(ssInfo); Assert.False(ssInfo.IsRegistered); Assert.Empty(ssInfo.Implementations); SubsystemInfo ssInfo2 = SubsystemManager.GetSubsystemInfo(SubsystemKind.CommandPredictor); Assert.Same(ssInfo2, ssInfo); ReadOnlyCollection <SubsystemInfo> ssInfos = SubsystemManager.GetAllSubsystemInfo(); Assert.Single(ssInfos); Assert.Same(ssInfos[0], ssInfo); ICommandPredictor impl = SubsystemManager.GetSubsystem <ICommandPredictor>(); Assert.Null(impl); ReadOnlyCollection <ICommandPredictor> impls = SubsystemManager.GetSubsystems <ICommandPredictor>(); Assert.Empty(impls); }
private void DoToolbarGUI() { if (Event.current.isKey || Event.current.type == EventType.Used) { return; } GameViewSizes.instance.RefreshStandaloneAndRemoteDefaultSizes(); GUILayout.BeginHorizontal(EditorStyles.toolbar); { var availableTypes = GetAvailableWindowTypes(); if (availableTypes.Count > 1) { var typeNames = availableTypes.Values.ToList(); var types = availableTypes.Keys.ToList(); int viewIndex = EditorGUILayout.Popup(typeNames.IndexOf(titleContent.text), typeNames.ToArray(), EditorStyles.toolbarPopup, GUILayout.Width(90)); EditorGUILayout.Space(); if (types[viewIndex] != typeof(GameView)) { SwapMainWindow(types[viewIndex]); } } if (ModuleManager.ShouldShowMultiDisplayOption()) { int display = EditorGUILayout.Popup(targetDisplay, DisplayUtility.GetDisplayNames(), EditorStyles.toolbarPopupLeft, GUILayout.Width(80)); if (display != targetDisplay) { targetDisplay = display; UpdateZoomAreaAndParent(); } } EditorGUILayout.GameViewSizePopup(currentSizeGroupType, selectedSizeIndex, this, EditorStyles.toolbarPopup, GUILayout.Width(160f)); DoZoomSlider(); // If the previous platform and current does not match, update the scale if ((int)currentSizeGroupType != prevSizeGroupType) { UpdateZoomAreaAndParent(); // Update the platform to the recent one prevSizeGroupType = (int)currentSizeGroupType; } if (FrameDebuggerUtility.IsLocalEnabled()) { GUILayout.FlexibleSpace(); Color oldCol = GUI.color; // This has nothing to do with animation recording. Can we replace this color with something else? GUI.color *= AnimationMode.recordedPropertyColor; GUILayout.Label(Styles.frameDebuggerOnContent, EditorStyles.toolbarLabel); GUI.color = oldCol; // Make frame debugger windows repaint after each time game view repaints. // We want them to always display the latest & greatest game view // rendering state. if (Event.current.type == EventType.Repaint) { FrameDebuggerWindow.RepaintAll(); } } GUILayout.FlexibleSpace(); if (ShouldShowMetalFrameCaptureGUI()) { if (GUILayout.Button(Styles.metalFrameCaptureContent, EditorStyles.toolbarButton)) { m_Parent.CaptureMetalScene(); } } if (RenderDoc.IsLoaded()) { using (new EditorGUI.DisabledScope(!RenderDoc.IsSupported())) { if (GUILayout.Button(Styles.renderdocContent, EditorStyles.toolbarButton)) { m_Parent.CaptureRenderDocScene(); GUIUtility.ExitGUI(); } } } SubsystemManager.GetSubsystems(m_DisplaySubsystems); // Allow the user to select how the XR device will be rendered during "Play In Editor" if (PlayerSettings.virtualRealitySupported || (m_DisplaySubsystems.Count != 0 && !m_DisplaySubsystems[0].disableLegacyRenderer)) { EditorGUI.BeginChangeCheck(); GameViewRenderMode currentGameViewRenderMode = UnityEngine.XR.XRSettings.gameViewRenderMode; int selectedRenderMode = EditorGUILayout.Popup(Mathf.Clamp(((int)currentGameViewRenderMode) - 1, 0, Styles.xrRenderingModes.Length - 1), Styles.xrRenderingModes, EditorStyles.toolbarPopup, GUILayout.Width(80)); if (EditorGUI.EndChangeCheck() && currentGameViewRenderMode != GameViewRenderMode.None) { SetXRRenderMode(selectedRenderMode); } } // Handles the case where XRSDK is being used without the shim layer else if (m_DisplaySubsystems.Count != 0 && m_DisplaySubsystems[0].disableLegacyRenderer) { EditorGUI.BeginChangeCheck(); int currentMirrorViewBlitMode = m_DisplaySubsystems[0].GetPreferredMirrorBlitMode(); int currentRenderMode = XRTranslateMirrorViewBlitModeToRenderMode(currentMirrorViewBlitMode); int selectedRenderMode = EditorGUILayout.Popup(Mathf.Clamp(currentRenderMode, 0, Styles.xrRenderingModes.Length - 1), Styles.xrRenderingModes, EditorStyles.toolbarPopup, GUILayout.Width(80)); int selectedMirrorViewBlitMode = XRTranslateRenderModeToMirrorViewBlitMode(selectedRenderMode); if (EditorGUI.EndChangeCheck() || currentMirrorViewBlitMode == 0) { m_DisplaySubsystems[0].SetPreferredMirrorBlitMode(selectedMirrorViewBlitMode); if (selectedMirrorViewBlitMode != m_XRRenderMode) { ClearTargetTexture(); } m_XRRenderMode = selectedMirrorViewBlitMode; } } maximizeOnPlay = GUILayout.Toggle(maximizeOnPlay, Styles.maximizeOnPlayContent, EditorStyles.toolbarButton); EditorUtility.audioMasterMute = GUILayout.Toggle(EditorUtility.audioMasterMute, Styles.muteContent, EditorStyles.toolbarButton); m_Stats = GUILayout.Toggle(m_Stats, Styles.statsContent, EditorStyles.toolbarButton); if (EditorGUILayout.DropDownToggle(ref m_Gizmos, Styles.gizmosContent, EditorStyles.toolbarDropDownToggleRight)) { Rect rect = GUILayoutUtility.topLevel.GetLast(); if (AnnotationWindow.ShowAtPosition(rect, true)) { GUIUtility.ExitGUI(); } } } GUILayout.EndHorizontal(); }
public static void RegisterSubsystem() { try { Assert.Throws <ArgumentNullException>( paramName: "proxy", () => SubsystemManager.RegisterSubsystem <ICommandPredictor, MyPredictor>(null)); Assert.Throws <ArgumentNullException>( paramName: "proxy", () => SubsystemManager.RegisterSubsystem(SubsystemKind.CommandPredictor, null)); Assert.Throws <ArgumentException>( paramName: "proxy", () => SubsystemManager.RegisterSubsystem((SubsystemKind)0, predictor1)); // Register 'predictor1' SubsystemManager.RegisterSubsystem <ICommandPredictor, MyPredictor>(predictor1); // Now validate the SubsystemInfo of the 'ICommandPredictor' subsystem SubsystemInfo ssInfo = SubsystemManager.GetSubsystemInfo(typeof(ICommandPredictor)); SubsystemInfo crossPlatformDscInfo = SubsystemManager.GetSubsystemInfo(typeof(ICrossPlatformDsc)); VerifyCommandPredictorMetadata(ssInfo); Assert.True(ssInfo.IsRegistered); Assert.Single(ssInfo.Implementations); // Now validate the 'ImplementationInfo' var implInfo = ssInfo.Implementations[0]; Assert.Equal(predictor1.Id, implInfo.Id); Assert.Equal(predictor1.Name, implInfo.Name); Assert.Equal(predictor1.Description, implInfo.Description); Assert.Equal(SubsystemKind.CommandPredictor, implInfo.Kind); Assert.Same(typeof(MyPredictor), implInfo.ImplementationType); // Now validate the subsystem implementation itself. ICommandPredictor impl = SubsystemManager.GetSubsystem <ICommandPredictor>(); Assert.Same(impl, predictor1); Assert.Null(impl.FunctionsToDefine); Assert.Equal(SubsystemKind.CommandPredictor, impl.Kind); const string Client = "SubsystemTest"; const string Input = "Hello world"; var predClient = new PredictionClient(Client, PredictionClientKind.Terminal); var predCxt = PredictionContext.Create(Input); var results = impl.GetSuggestion(predClient, predCxt, CancellationToken.None); Assert.Equal($"'{Input}' from '{Client}' - TEST-1 from {impl.Name}", results.SuggestionEntries[0].SuggestionText); Assert.Equal($"'{Input}' from '{Client}' - TeSt-2 from {impl.Name}", results.SuggestionEntries[1].SuggestionText); // Now validate the all-subsystem-implementation collection. ReadOnlyCollection <ICommandPredictor> impls = SubsystemManager.GetSubsystems <ICommandPredictor>(); Assert.Single(impls); Assert.Same(predictor1, impls[0]); // Register 'predictor2' SubsystemManager.RegisterSubsystem(SubsystemKind.CommandPredictor, predictor2); // Now validate the SubsystemInfo of the 'ICommandPredictor' subsystem VerifyCommandPredictorMetadata(ssInfo); Assert.True(ssInfo.IsRegistered); Assert.Equal(2, ssInfo.Implementations.Count); // Now validate the new 'ImplementationInfo' implInfo = ssInfo.Implementations[1]; Assert.Equal(predictor2.Id, implInfo.Id); Assert.Equal(predictor2.Name, implInfo.Name); Assert.Equal(predictor2.Description, implInfo.Description); Assert.Equal(SubsystemKind.CommandPredictor, implInfo.Kind); Assert.Same(typeof(MyPredictor), implInfo.ImplementationType); // Now validate the new subsystem implementation. impl = SubsystemManager.GetSubsystem <ICommandPredictor>(); Assert.Same(impl, predictor2); // Now validate the all-subsystem-implementation collection. impls = SubsystemManager.GetSubsystems <ICommandPredictor>(); Assert.Equal(2, impls.Count); Assert.Same(predictor1, impls[0]); Assert.Same(predictor2, impls[1]); } finally { SubsystemManager.UnregisterSubsystem <ICommandPredictor>(predictor1.Id); SubsystemManager.UnregisterSubsystem(SubsystemKind.CommandPredictor, predictor2.Id); } }