public static void CreateRequestAndShow([NotNull] UnityHost unityHost, [NotNull] FileSystemPath solutionDirPath, [NotNull] UnitySceneDataLocalCache unitySceneDataLocalCache, [NotNull] string anchor, IPsiSourceFile sourceFile, bool needExpand = false) { using (ReadLockCookie.Create()) { var request = CreateRequest(solutionDirPath, unitySceneDataLocalCache, anchor, sourceFile, needExpand); unityHost.PerformModelAction(t => t.ShowGameObjectOnScene.Fire(request)); } UnityFocusUtil.FocusUnity(unityHost.GetValue(t => t.UnityProcessId.Value)); }
public void Complete() { myShellLocks.Tasks.StartNew(myLifetimeDef.Lifetime, Scheduling.MainGuard, () => { if (myConsumer.Result.Count != 0) { if (myFocusUnity) { UnityFocusUtil.FocusUnity(myUnityHost.GetValue(t => t.UnityProcessId.Value)); } if (mySelected != null) { myUnityHost.PerformModelAction(t => t.ShowGameObjectOnScene.Fire(mySelected)); } myUnityHost.PerformModelAction(t => t.FindUsageResults.Fire(new FindUsageResult(myDisplayName, myConsumer.Result.ToArray()))); } myLifetimeDef.Terminate(); }); }
public ConnectionTracker(Lifetime lifetime, ILogger logger, UnityHost host, UnityEditorProtocol editorProtocol, IThreading locks, UnitySolutionTracker unitySolutionTracker, IIsApplicationActiveState isApplicationActiveState) { State = new Property <UnityEditorState>(lifetime, "UnityEditorPlugin::ConnectionState", UnityEditorState.Disconnected); if (locks.Dispatcher.IsAsyncBehaviorProhibited) { return; } unitySolutionTracker.IsUnityProject.AdviseOnce(lifetime, args => { if (!args) { return; } var updateConnectionAction = new Action(() => { var model = editorProtocol.UnityModel.Value; if (model == null) { State.SetValue(UnityEditorState.Disconnected); } else { if (!model.IsBound) { State.SetValue(UnityEditorState.Disconnected); } var rdTask = model.GetUnityEditorState.Start(Unit.Instance); rdTask?.Result.Advise(lifetime, result => { State.SetValue(result.Result); logger.Trace($"Inside Result. Sending connection state. State: {State.Value}"); host.PerformModelAction(m => m.EditorState.Value = Wrap(State.Value)); }); var waitTask = Task.Delay(TimeSpan.FromSeconds(2)); waitTask.ContinueWith(_ => { if (rdTask != null && !rdTask.AsTask().IsCompleted) { logger.Trace("There were no response from Unity in two seconds. Set connection state to Disconnected."); State.SetValue(UnityEditorState.Disconnected); } }, locks.Tasks.GuardedMainThreadScheduler); } logger.Trace($"Sending connection state. State: {State.Value}"); host.PerformModelAction(m => m.EditorState.Value = Wrap(State.Value)); }); lifetime.StartMainUnguardedAsync(async() => { while (lifetime.IsAlive) { if (isApplicationActiveState.IsApplicationActive.Value || host.GetValue(rdUnityModel => rdUnityModel.RiderFrontendTests).HasTrueValue()) { updateConnectionAction(); } await Task.Delay(1000, lifetime); } }); }); }