private static void Init() { var projectDirectory = Directory.GetParent(Application.dataPath).FullName; var projectName = Path.GetFileName(projectDirectory); SlnFile = Path.GetFullPath($"{projectName}.sln"); InitializeEditorInstanceJson(); // for the case when files were changed and user just alt+tab to unity to make update, we want to fire CsprojAssetPostprocessor.OnGeneratedCSProjectFiles(); Log.DefaultFactory = new RiderLoggerFactory(); var lifetimeDefinition = Lifetimes.Define(EternalLifetime.Instance); var lifetime = lifetimeDefinition.Lifetime; AppDomain.CurrentDomain.DomainUnload += (EventHandler)((_, __) => { ourLogger.Verbose("lifetimeDefinition.Terminate"); lifetimeDefinition.Terminate(); }); if (PluginSettings.SelectedLoggingLevel >= LoggingLevel.VERBOSE) { Debug.Log($"Rider plugin initialized. LoggingLevel: {PluginSettings.SelectedLoggingLevel}. Change it in Unity Preferences -> Rider. Logs path: {LogPath}."); } try { var riderProtocolController = new RiderProtocolController(MainThreadDispatcher.Instance, lifetime); var serializers = new Serializers(); var identities = new Identities(IdKind.Server); MainThreadDispatcher.AssertThread(); riderProtocolController.Wire.Connected.View(lifetime, (lt, connected) => { if (connected) { var protocol = new Protocol(serializers, identities, MainThreadDispatcher.Instance, riderProtocolController.Wire); ourLogger.Log(LoggingLevel.VERBOSE, "Create UnityModel and advise for new sessions..."); ourModel.Value = CreateModel(protocol, lt); } else { ourModel.Value = null; } }); } catch (Exception ex) { ourLogger.Error("Init Rider Plugin " + ex); } ourAssetHandler = new OnOpenAssetHandler(ourModel, ourRiderPathLocator, ourPluginSettings, SlnFile); ourInitialized = true; }
private static int CreateProtocolForSolution(Lifetime lifetime, string solutionName, Action onDisconnected) { try { var dispatcher = MainThreadDispatcher.Instance; var currentWireAndProtocolLifetimeDef = lifetime.CreateNested(); var currentWireAndProtocolLifetime = currentWireAndProtocolLifetimeDef.Lifetime; var riderProtocolController = new RiderProtocolController(dispatcher, currentWireAndProtocolLifetime); #if !NET35 var serializers = new Serializers(lifetime, null, null); #else var serializers = new Serializers(); #endif var identities = new Identities(IdKind.Server); MainThreadDispatcher.AssertThread(); var protocol = new Protocol("UnityEditorPlugin" + solutionName, serializers, identities, MainThreadDispatcher.Instance, riderProtocolController.Wire, currentWireAndProtocolLifetime); riderProtocolController.Wire.Connected.WhenTrue(currentWireAndProtocolLifetime, connectionLifetime => { ourLogger.Log(LoggingLevel.VERBOSE, "Create UnityModel and advise for new sessions..."); var model = new BackendUnityModel(connectionLifetime, protocol); AdviseUnityActions(model, connectionLifetime); AdviseEditorState(model); OnModelInitialization(new UnityModelAndLifetime(model, connectionLifetime)); AdviseRefresh(model); var paths = GetLogPaths(); model.UnityApplicationData.SetValue(new UnityApplicationData( EditorApplication.applicationPath, EditorApplication.applicationContentsPath, UnityUtils.UnityApplicationVersion, paths[0], paths[1], Process.GetCurrentProcess().Id)); model.UnityApplicationSettings.ScriptCompilationDuringPlay.Set(UnityUtils.SafeScriptCompilationDuringPlay); model.UnityProjectSettings.ScriptingRuntime.SetValue(UnityUtils.ScriptingRuntime); AdviseShowPreferences(model, connectionLifetime, ourLogger); AdviseGenerateUISchema(model); AdviseExitUnity(model); GetBuildLocation(model); AdviseRunMethod(model); GetInitTime(model); ourLogger.Verbose("UnityModel initialized."); var pair = new ModelWithLifetime(model, connectionLifetime); connectionLifetime.OnTermination(() => { UnityModels.Remove(pair); }); UnityModels.Add(pair); connectionLifetime.OnTermination(() => { ourLogger.Verbose($"Connection lifetime is not alive for {solutionName}, destroying protocol"); onDisconnected(); }); }); return(riderProtocolController.Wire.Port); } catch (Exception ex) { ourLogger.Error("Init Rider Plugin " + ex); return(-1); } }
private static void Init() { var projectDirectory = Directory.GetParent(Application.dataPath).FullName; var projectName = Path.GetFileName(projectDirectory); SlnFile = Path.GetFullPath($"{projectName}.sln"); InitializeEditorInstanceJson(); // process csproj files once per Unity process if (!RiderScriptableSingleton.Instance.CsprojProcessedOnce) { ourLogger.Verbose("Call OnGeneratedCSProjectFiles once per Unity process."); CsprojAssetPostprocessor.OnGeneratedCSProjectFiles(); RiderScriptableSingleton.Instance.CsprojProcessedOnce = true; } Log.DefaultFactory = new RiderLoggerFactory(); var lifetimeDefinition = Lifetimes.Define(EternalLifetime.Instance); var lifetime = lifetimeDefinition.Lifetime; AppDomain.CurrentDomain.DomainUnload += (EventHandler)((_, __) => { ourLogger.Verbose("lifetimeDefinition.Terminate"); lifetimeDefinition.Terminate(); }); if (PluginSettings.SelectedLoggingLevel >= LoggingLevel.VERBOSE) { Debug.Log($"Rider plugin initialized. LoggingLevel: {PluginSettings.SelectedLoggingLevel}. Change it in Unity Preferences -> Rider. Logs path: {LogPath}."); } try { var riderProtocolController = new RiderProtocolController(MainThreadDispatcher.Instance, lifetime); var serializers = new Serializers(); var identities = new Identities(IdKind.Server); MainThreadDispatcher.AssertThread(); riderProtocolController.Wire.Connected.WhenTrue(lifetime, connectionLifetime => { var protocol = new Protocol("UnityEditorPlugin", serializers, identities, MainThreadDispatcher.Instance, riderProtocolController.Wire); ourLogger.Log(LoggingLevel.VERBOSE, "Create UnityModel and advise for new sessions..."); var model = new EditorPluginModel(connectionLifetime, protocol); AdviseUnityActions(model, connectionLifetime); AdviseModel(model); OnModelInitialization(new UnityModelAndLifetime(model, connectionLifetime)); AdviseRefresh(model); model.FullPluginPath.Advise(connectionLifetime, AdditionalPluginsInstaller.UpdateSelf); model.ApplicationVersion.SetValue(UnityUtils.UnityVersion.ToString()); model.ScriptingRuntime.SetValue(UnityUtils.ScriptingRuntime); ourLogger.Verbose("UnityModel initialized."); UnityModel.SetValue(model); new UnityEventLogSender(ourLogEventCollector, connectionLifetime); }); } catch (Exception ex) { ourLogger.Error("Init Rider Plugin " + ex); } ourOpenAssetHandler = new OnOpenAssetHandler(UnityModel, ourRiderPathLocator, ourPluginSettings, SlnFile); ourInitialized = true; }