@@ -99,6 +99,9 @@ public void OnGUI()
9999 GUILayout . BeginHorizontal ( ) ;
100100 GUILayout . FlexibleSpace ( ) ;
101101
102+ if ( ! TryGetVisualStudioInstallationForPath ( CodeEditor . CurrentEditorInstallation , true , out var installation ) )
103+ return ;
104+
102105 var package = UnityEditor . PackageManager . PackageInfo . FindForAssembly ( GetType ( ) . Assembly ) ;
103106
104107 var style = new GUIStyle
@@ -112,43 +115,36 @@ public void OnGUI()
112115
113116 EditorGUILayout . LabelField ( "Generate .csproj files for:" ) ;
114117 EditorGUI . indentLevel ++ ;
115- SettingsButton ( ProjectGenerationFlag . Embedded , "Embedded packages" , "" ) ;
116- SettingsButton ( ProjectGenerationFlag . Local , "Local packages" , "" ) ;
117- SettingsButton ( ProjectGenerationFlag . Registry , "Registry packages" , "" ) ;
118- SettingsButton ( ProjectGenerationFlag . Git , "Git packages" , "" ) ;
119- SettingsButton ( ProjectGenerationFlag . BuiltIn , "Built-in packages" , "" ) ;
120- SettingsButton ( ProjectGenerationFlag . LocalTarBall , "Local tarball" , "" ) ;
121- SettingsButton ( ProjectGenerationFlag . Unknown , "Packages from unknown sources" , "" ) ;
122- SettingsButton ( ProjectGenerationFlag . PlayerAssemblies , "Player projects" , "For each player project generate an additional csproj with the name 'project-player.csproj'" ) ;
123- RegenerateProjectFiles ( ) ;
118+ SettingsButton ( ProjectGenerationFlag . Embedded , "Embedded packages" , "" , installation ) ;
119+ SettingsButton ( ProjectGenerationFlag . Local , "Local packages" , "" , installation ) ;
120+ SettingsButton ( ProjectGenerationFlag . Registry , "Registry packages" , "" , installation ) ;
121+ SettingsButton ( ProjectGenerationFlag . Git , "Git packages" , "" , installation ) ;
122+ SettingsButton ( ProjectGenerationFlag . BuiltIn , "Built-in packages" , "" , installation ) ;
123+ SettingsButton ( ProjectGenerationFlag . LocalTarBall , "Local tarball" , "" , installation ) ;
124+ SettingsButton ( ProjectGenerationFlag . Unknown , "Packages from unknown sources" , "" , installation ) ;
125+ SettingsButton ( ProjectGenerationFlag . PlayerAssemblies , "Player projects" , "For each player project generate an additional csproj with the name 'project-player.csproj'" , installation ) ;
126+ RegenerateProjectFiles ( installation ) ;
124127 EditorGUI . indentLevel -- ;
125128 }
126129
127- private void RegenerateProjectFiles ( )
130+ private static void RegenerateProjectFiles ( IVisualStudioInstallation installation )
128131 {
129132 var rect = EditorGUI . IndentedRect ( EditorGUILayout . GetControlRect ( ) ) ;
130133 rect . width = 252 ;
131134 if ( GUI . Button ( rect , "Regenerate project files" ) )
132135 {
133- if ( TryGetVisualStudioInstallationForPath ( CodeEditor . CurrentEditorInstallation , true , out var installation ) )
134- {
135- installation . ProjectGenerator . Sync ( ) ;
136- }
136+ installation . ProjectGenerator . Sync ( ) ;
137137 }
138138 }
139139
140- private void SettingsButton ( ProjectGenerationFlag preference , string guiMessage , string toolTip )
140+ private static void SettingsButton ( ProjectGenerationFlag preference , string guiMessage , string toolTip , IVisualStudioInstallation installation )
141141 {
142- if ( TryGetVisualStudioInstallationForPath ( CodeEditor . CurrentEditorInstallation , true , out var installation ) )
143- {
144- var generator = installation . ProjectGenerator ;
145- var prevValue = generator . AssemblyNameProvider . ProjectGenerationFlag . HasFlag ( preference ) ;
146- var newValue = EditorGUILayout . Toggle ( new GUIContent ( guiMessage , toolTip ) , prevValue ) ;
147- if ( newValue != prevValue )
148- {
149- generator . AssemblyNameProvider . ToggleProjectGeneration ( preference ) ;
150- }
151- }
142+ var generator = installation . ProjectGenerator ;
143+ var prevValue = generator . AssemblyNameProvider . ProjectGenerationFlag . HasFlag ( preference ) ;
144+
145+ var newValue = EditorGUILayout . Toggle ( new GUIContent ( guiMessage , toolTip ) , prevValue ) ;
146+ if ( newValue != prevValue )
147+ generator . AssemblyNameProvider . ToggleProjectGeneration ( preference ) ;
152148 }
153149
154150 public void SyncIfNeeded ( string [ ] addedFiles , string [ ] deletedFiles , string [ ] movedFiles , string [ ] movedFromFiles , string [ ] importedFiles )
0 commit comments