@@ -198,18 +198,6 @@ private static bool TryGetShaderMainTex( Material material, out string mainTexTa
198
198
199
199
return false ;
200
200
}
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
- }
213
201
214
202
/*
215
203
* 1: Check that we actually have the material were looking for
@@ -239,6 +227,13 @@ private static void GenerateBuiltinPipelineMaterial( string name )
239
227
240
228
material . shader = Shader . Find ( pipelineShader ) ;
241
229
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
+
242
237
string mainTexTag ;
243
238
244
239
if ( TryGetShaderMainTex ( material , out mainTexTag ) )
@@ -249,11 +244,9 @@ private static void GenerateBuiltinPipelineMaterial( string name )
249
244
{
250
245
// if the material is the built-in metal texture, then we'll set its metalness to 100%
251
246
252
- string metalnessTag ;
253
-
254
- if ( TryGetMetallicProperty ( material , out metalnessTag ) )
247
+ if ( material . HasProperty ( "_Metallic" ) )
255
248
{
256
- material . SetFloat ( metalnessTag , 1f ) ;
249
+ material . SetFloat ( "_Metallic" , 1f ) ;
257
250
material . SetFloat ( "_Smoothness" , 1f ) ;
258
251
material . SetTexture ( "_MetallicGlossMap" , Resources . Load < Texture2D > ( "RealtimeCSG/Textures/checker_m" ) ) ;
259
252
}
@@ -274,15 +267,19 @@ private static void GenerateBuiltinPipelineMaterial( string name )
274
267
}
275
268
276
269
AssetDatabase . StopAssetEditing ( ) ;
277
-
278
270
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 )
279
274
AssetDatabase . SaveAssetIfDirty ( material ) ;
275
+ #else
276
+ AssetDatabase . SaveAssets ( ) ;
277
+ #endif
280
278
281
279
AssetDatabase . Refresh ( ImportAssetOptions . ForceUpdate ) ;
282
-
283
280
Resources . UnloadUnusedAssets ( ) ;
284
281
}
285
-
282
+
286
283
// using built-in, just dont do anything.
287
284
}
288
285
0 commit comments