Ejemplo n.º 1
0
        static RiderScriptEditor()
        {
            try
            {
                var projectGeneration = new ProjectGeneration.ProjectGeneration();
                var editor            = new RiderScriptEditor(new Discovery(), projectGeneration);
                CodeEditor.Register(editor);
                var path = GetEditorRealPath(CurrentEditor);

                if (IsRiderInstallation(path))
                {
                    RiderPathLocator.RiderInfo[] installations = null;

                    if (!RiderScriptEditorData.instance.initializedOnce)
                    {
                        installations = RiderPathLocator.GetAllRiderPaths().OrderBy(a => a.BuildNumber).ToArray();
                        // is likely outdated
                        if (installations.Any() && installations.All(a => GetEditorRealPath(a.Path) != path))
                        {
                            if (RiderPathLocator.GetIsToolbox(path)) // is toolbox - update
                            {
                                var toolboxInstallations = installations.Where(a => a.IsToolbox).ToArray();
                                if (toolboxInstallations.Any())
                                {
                                    var newEditor = toolboxInstallations.Last().Path;
                                    CodeEditor.SetExternalScriptEditor(newEditor);
                                    path = newEditor;
                                }
                                else
                                {
                                    var newEditor = installations.Last().Path;
                                    CodeEditor.SetExternalScriptEditor(newEditor);
                                    path = newEditor;
                                }
                            }
                            else // is non toolbox - notify
                            {
                                var newEditorName = installations.Last().Presentation;
                                Debug.LogWarning($"Consider updating External Editor in Unity to Rider {newEditorName}.");
                            }
                        }

                        ShowWarningOnUnexpectedScriptEditor(path);
                        RiderScriptEditorData.instance.initializedOnce = true;
                    }

                    if (!FileSystemUtil.EditorPathExists(path)) // previously used rider was removed
                    {
                        if (installations == null)
                        {
                            installations = RiderPathLocator.GetAllRiderPaths().OrderBy(a => a.BuildNumber).ToArray();
                        }
                        if (installations.Any())
                        {
                            var newEditor = installations.Last().Path;
                            CodeEditor.SetExternalScriptEditor(newEditor);
                            path = newEditor;
                        }
                    }
                    RiderScriptEditorData.instance.Init();

                    editor.CreateSolutionIfDoesntExist();
                    if (RiderScriptEditorData.instance.shouldLoadEditorPlugin)
                    {
                        editor.m_Initiliazer.Initialize(path);
                    }

                    InitProjectFilesWatcher();
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }
        }
Ejemplo n.º 2
0
        static RiderScriptEditor()
        {
            try
            {
                // todo: make ProjectGeneration lazy
                var projectGeneration = new ProjectGeneration.ProjectGeneration();
                var editor            = new RiderScriptEditor(new Discovery(), projectGeneration);
                CodeEditor.Register(editor);
                var path = GetEditorRealPath(CurrentEditor);

                if (IsRiderInstallation(path))
                {
                    RiderPathLocator.RiderInfo[] installations = null;

                    if (!RiderScriptEditorData.instance.initializedOnce)
                    {
                        installations = RiderPathLocator.GetAllRiderPaths().OrderBy(a => a.BuildNumber).ToArray();
                        // is likely outdated
                        if (installations.Any() && installations.All(a => GetEditorRealPath(a.Path) != path))
                        {
                            if (RiderPathLocator.GetIsToolbox(path)) // is toolbox - update
                            {
                                var toolboxInstallations = installations.Where(a => a.IsToolbox).ToArray();
                                if (toolboxInstallations.Any())
                                {
                                    var newEditor = toolboxInstallations.Last().Path;
                                    CodeEditor.SetExternalScriptEditor(newEditor);
                                    path = newEditor;
                                }
                                else
                                {
                                    var newEditor = installations.Last().Path;
                                    CodeEditor.SetExternalScriptEditor(newEditor);
                                    path = newEditor;
                                }
                            }
                            else // is non toolbox - notify
                            {
                                var newEditorName = installations.Last().Presentation;
                                Debug.LogWarning($"Consider updating External Editor in Unity to Rider {newEditorName}.");
                            }
                        }

                        ShowWarningOnUnexpectedScriptEditor(path);
                        RiderScriptEditorData.instance.initializedOnce = true;
                    }

                    if (!FileSystemUtil.EditorPathExists(path)) // previously used rider was removed
                    {
                        if (installations == null)
                        {
                            installations = RiderPathLocator.GetAllRiderPaths().OrderBy(a => a.BuildNumber).ToArray();
                        }
                        if (installations.Any())
                        {
                            var newEditor = installations.Last().Path;
                            CodeEditor.SetExternalScriptEditor(newEditor);
                            path = newEditor;
                        }
                    }

                    RiderScriptEditorData.instance.Init();

                    editor.CreateSolutionIfDoesntExist();
                    if (RiderScriptEditorData.instance.shouldLoadEditorPlugin)
                    {
                        editor.m_Initiliazer.Initialize(path);
                    }

                    RiderFileSystemWatcher.InitWatcher(
                        Directory.GetCurrentDirectory(), "*.*", (sender, args) =>
                    {
                        var extension = Path.GetExtension(args.Name);
                        if (extension == ".sln" || extension == ".csproj")
                        {
                            RiderScriptEditorData.instance.hasChanges = true;
                        }
                    });

                    RiderFileSystemWatcher.InitWatcher(
                        Path.Combine(Directory.GetCurrentDirectory(), "Library"),
                        "EditorOnlyScriptingUserSettings.json",
                        (sender, args) => { RiderScriptEditorData.instance.hasChanges = true; });

                    RiderFileSystemWatcher.InitWatcher(
                        Path.Combine(Directory.GetCurrentDirectory(), "Packages"),
                        "manifest.json", (sender, args) => { RiderScriptEditorData.instance.hasChanges = true; });

                    // can't switch to non-deprecated api, because UnityEditor.Build.BuildPipelineInterfaces.processors is internal
#pragma warning disable 618
                    EditorUserBuildSettings.activeBuildTargetChanged += () =>
#pragma warning restore 618
                    {
                        RiderScriptEditorData.instance.hasChanges = true;
                    };
                }
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }
        }