@@ -10,10 +10,14 @@ namespace EasyEditor
1010 [ InitializeOnLoad ]
1111 internal class ExternalCodeEditor : IExternalCodeEditor
1212 {
13+ public static readonly ExternalCodeEditor instance ;
14+
1315 static ExternalCodeEditor ( )
1416 {
1517 LauncherRegistry . Load ( ) ;
16- CodeEditor . Register ( new ExternalCodeEditor ( ) ) ;
18+ instance = new ExternalCodeEditor ( ) ;
19+ CodeEditor . Register ( instance ) ;
20+ AssemblyReloadEvents . beforeAssemblyReload += OnBeforeAssemblyReload ;
1721 }
1822
1923 public CodeEditor . Installation [ ] Installations { get ; }
@@ -36,14 +40,19 @@ private static bool SupportsExtension(string path)
3640 return ! string . IsNullOrEmpty ( extension ) && DefaultExtensions . Contains ( extension . TrimStart ( '.' ) ) ;
3741 }
3842
43+ private static void OnBeforeAssemblyReload ( )
44+ {
45+ CodeEditor . Unregister ( instance ) ;
46+ }
47+
3948 public ExternalCodeEditor ( )
4049 {
4150 Installations = LauncherRegistry . Installations ;
4251 }
4352
4453 public void Initialize ( string editorInstallationPath )
4554 {
46- if ( Preferences . IsActive && Preferences . AutoSync )
55+ if ( Preferences . IsActive && Preferences . Settings . autoSync . GetBool ( ) )
4756 {
4857 SyncUtil . Sync ( ) ;
4958 }
@@ -57,42 +66,44 @@ public void OnGUI()
5766 }
5867
5968 EditorGUI . BeginDisabledGroup ( ! Preferences . IsActive || ! SyncVS . IsValid || SyncUtil . IsReloading || EditorApplication . isCompiling || EditorApplication . isUpdating ) ;
60- EditorGUI . BeginChangeCheck ( ) ;
61- GUIContent syncContent = new GUIContent (
62- "Sync solution and project files" ,
63- "Forces .sln and .csproj files to be generated and kept in sync." ) ;
64- bool v = EditorGUILayout . Toggle ( syncContent , Preferences . AutoSync ) ;
65- if ( EditorGUI . EndChangeCheck ( ) )
6669 {
67- Preferences . AutoSync = v ;
68- if ( v )
70+ EditorGUI . BeginChangeCheck ( ) ;
71+ Setting s = Preferences . Settings . autoSync ;
72+ GUIContent c = new GUIContent ( s . description , s . tooltip ) ;
73+ bool v = EditorGUILayout . Toggle ( c , s . GetBool ( ) ) ;
74+ if ( EditorGUI . EndChangeCheck ( ) )
6975 {
70- SyncUtil . Sync ( ) ;
76+ s . SetBool ( v ) ;
77+ if ( v )
78+ {
79+ SyncUtil . Sync ( ) ;
80+ }
81+ Event . current . Use ( ) ;
7182 }
72- Event . current . Use ( ) ;
7383 }
7484 if ( ! SyncVS . IsValid )
7585 {
7686 EditorGUILayout . HelpBox ( "Couldn't retrieve synchronization members. Please contact this package's author." , MessageType . Warning ) ;
7787 }
7888
79- EditorGUI . BeginChangeCheck ( ) ;
80- GUIContent matchCompilerContent = new GUIContent (
81- "Match compiler version" ,
82- "When Unity creates or updates .csproj files, it defines LangVersion as 'latest'. This can create inconsistencies with other .NET platforms (e.g. OmniSharp), which could resolve 'latest' as a different version. By matching compiler version, 'latest' will get resolved as " + Preferences . GetLangVersion ( ) + ". " ) ;
83- v = EditorGUILayout . Toggle ( matchCompilerContent , Preferences . MatchCompilerVersion ) ;
84- if ( EditorGUI . EndChangeCheck ( ) )
8589 {
86- Preferences . MatchCompilerVersion = v ;
87- if ( v )
90+ EditorGUI . BeginChangeCheck ( ) ;
91+ Setting s = Preferences . Settings . matchCompilerVersion ;
92+ GUIContent c = new GUIContent ( s . description , s . tooltip ) ;
93+ bool v = EditorGUILayout . Toggle ( c , s . GetBool ( ) ) ;
94+ if ( EditorGUI . EndChangeCheck ( ) )
8895 {
89- SyncUtil . Sync ( ) ;
96+ s . SetBool ( v ) ;
97+ if ( v )
98+ {
99+ SyncUtil . Sync ( ) ;
100+ }
101+ Event . current . Use ( ) ;
90102 }
91- Event . current . Use ( ) ;
92103 }
93104
94105 string editorPath = CodeEditor . CurrentEditorInstallation . Trim ( ) ;
95- ILauncher launcher = LauncherRegistry . GetLauncher ( editorPath ) ;
106+ Launcher launcher = LauncherRegistry . GetLauncher ( editorPath ) ;
96107 if ( launcher != null )
97108 {
98109 launcher . OnGUI ( ) ;
@@ -120,9 +131,9 @@ public bool OpenProject(string filePath = "", int line = -1, int column = -1)
120131
121132 string editorPath = CodeEditor . CurrentEditorInstallation . Trim ( ) ;
122133
123- LaunchDescriptor descriptor = new LaunchDescriptor ( filePath , line , column , Preferences . ProjectPath , Preferences . ProjectName ) ;
134+ LaunchDescriptor descriptor = new LaunchDescriptor ( filePath , line , column , Preferences . projectPath , Preferences . projectName ) ;
124135
125- ILauncher launcher = LauncherRegistry . GetLauncher ( editorPath ) ;
136+ Launcher launcher = LauncherRegistry . GetLauncher ( editorPath ) ;
126137 if ( launcher != null )
127138 {
128139 _ = launcher . Launch ( editorPath , descriptor ) ;
@@ -135,7 +146,7 @@ public void SyncAll()
135146 {
136147 SyncUtil . Sync ( ) ;
137148 string editorPath = CodeEditor . CurrentEditorInstallation . Trim ( ) ;
138- ILauncher launcher = LauncherRegistry . GetLauncher ( editorPath ) ;
149+ Launcher launcher = LauncherRegistry . GetLauncher ( editorPath ) ;
139150 if ( launcher != null )
140151 {
141152 launcher . SyncAll ( ) ;
@@ -146,7 +157,7 @@ public void SyncIfNeeded(string[] addedFiles, string[] deletedFiles, string[] mo
146157 {
147158 SyncUtil . Sync ( ) ;
148159 string editorPath = CodeEditor . CurrentEditorInstallation . Trim ( ) ;
149- ILauncher launcher = LauncherRegistry . GetLauncher ( editorPath ) ;
160+ Launcher launcher = LauncherRegistry . GetLauncher ( editorPath ) ;
150161 if ( launcher != null )
151162 {
152163 launcher . SyncIfNeeded ( addedFiles , deletedFiles , movedFiles , movedFromFiles , importedFiles ) ;
0 commit comments