@@ -198,18 +198,6 @@ private static bool TryGetShaderMainTex( Material material, out string mainTexTa
198198
199199 return false ;
200200 }
201- private static bool TryGetMetallicProperty ( Material material , out string property )
202- {
203- if ( material . HasProperty ( "_Metallic" ) )
204- {
205- property = "_Metallic" ;
206-
207- return true ;
208- }
209-
210- property = "_Metallic" ;
211- return false ;
212- }
213201
214202 /*
215203 * 1: Check that we actually have the material were looking for
@@ -239,6 +227,13 @@ private static void GenerateBuiltinPipelineMaterial( string name )
239227
240228 material . shader = Shader . Find ( pipelineShader ) ;
241229
230+ if ( material . shader . name == pipelineShader ) // if our shader is already the default RP shader, then don't do anything
231+ {
232+ AssetDatabase . StopAssetEditing ( ) ;
233+
234+ return ;
235+ }
236+
242237 string mainTexTag ;
243238
244239 if ( TryGetShaderMainTex ( material , out mainTexTag ) )
@@ -249,11 +244,9 @@ private static void GenerateBuiltinPipelineMaterial( string name )
249244 {
250245 // if the material is the built-in metal texture, then we'll set its metalness to 100%
251246
252- string metalnessTag ;
253-
254- if ( TryGetMetallicProperty ( material , out metalnessTag ) )
247+ if ( material . HasProperty ( "_Metallic" ) )
255248 {
256- material . SetFloat ( metalnessTag , 1f ) ;
249+ material . SetFloat ( "_Metallic" , 1f ) ;
257250 material . SetFloat ( "_Smoothness" , 1f ) ;
258251 material . SetTexture ( "_MetallicGlossMap" , Resources . Load < Texture2D > ( "RealtimeCSG/Textures/checker_m" ) ) ;
259252 }
@@ -274,15 +267,19 @@ private static void GenerateBuiltinPipelineMaterial( string name )
274267 }
275268
276269 AssetDatabase . StopAssetEditing ( ) ;
277-
278270 EditorUtility . SetDirty ( material ) ;
271+
272+ // SaveAssetsIfDirty doesn't exist on versions older than 2020.3.16
273+ #if UNITY_2020_3_OR_NEWER && ! ( UNITY_2020_3_0 || UNITY_2020_3_1 || UNITY_2020_3_2 || UNITY_2020_3_3 || UNITY_2020_3_4 || UNITY_2020_3_5 || UNITY_2020_3_6 || UNITY_2020_3_7 || UNITY_2020_3_8 || UNITY_2020_3_9 || UNITY_2020_3_10 || UNITY_2020_3_11 || UNITY_2020_3_12 || UNITY_2020_3_13 || UNITY_2020_3_14 || UNITY_2020_3_15 )
279274 AssetDatabase . SaveAssetIfDirty ( material ) ;
275+ #else
276+ AssetDatabase . SaveAssets ( ) ;
277+ #endif
280278
281279 AssetDatabase . Refresh ( ImportAssetOptions . ForceUpdate ) ;
282-
283280 Resources . UnloadUnusedAssets ( ) ;
284281 }
285-
282+
286283 // using built-in, just dont do anything.
287284 }
288285
0 commit comments