Skip to content

Hotfix for 2020.3.15f2 and lower #343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions Plugins/Editor/Scripts/Control/Helpers/MaterialUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,18 +198,6 @@ private static bool TryGetShaderMainTex( Material material, out string mainTexTa

return false;
}
private static bool TryGetMetallicProperty(Material material, out string property )
{
if( material.HasProperty( "_Metallic" ) )
{
property = "_Metallic";

return true;
}

property = "_Metallic";
return false;
}

/*
* 1: Check that we actually have the material were looking for
Expand Down Expand Up @@ -239,6 +227,13 @@ private static void GenerateBuiltinPipelineMaterial( string name )

material.shader = Shader.Find( pipelineShader );

if( material.shader.name == pipelineShader ) // if our shader is already the default RP shader, then don't do anything
{
AssetDatabase.StopAssetEditing();

return;
}

string mainTexTag;

if( TryGetShaderMainTex( material, out mainTexTag ) )
Expand All @@ -249,11 +244,9 @@ private static void GenerateBuiltinPipelineMaterial( string name )
{
// if the material is the built-in metal texture, then we'll set its metalness to 100%

string metalnessTag;

if( TryGetMetallicProperty( material, out metalnessTag ) )
if( material.HasProperty( "_Metallic" ) )
{
material.SetFloat( metalnessTag, 1f );
material.SetFloat( "_Metallic", 1f );
material.SetFloat( "_Smoothness", 1f );
material.SetTexture( "_MetallicGlossMap", Resources.Load<Texture2D>( "RealtimeCSG/Textures/checker_m" ) );
}
Expand All @@ -274,15 +267,19 @@ private static void GenerateBuiltinPipelineMaterial( string name )
}

AssetDatabase.StopAssetEditing();

EditorUtility.SetDirty( material );

// SaveAssetsIfDirty doesn't exist on versions older than 2020.3.16
#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)
AssetDatabase.SaveAssetIfDirty( material );
#else
AssetDatabase.SaveAssets();
#endif

AssetDatabase.Refresh( ImportAssetOptions.ForceUpdate );

Resources.UnloadUnusedAssets();
}

// using built-in, just dont do anything.
}

Expand Down