Conversation
There was a problem hiding this comment.
Pull request overview
Refactors toon shader conversion and editor tests to use centralized editor constants for package shader paths, reducing reliance on shader-name lookups.
Changes:
- Added
ToonEditorConstantsshader asset paths for the main and tessellation toon shaders. - Updated the shader compile editor test to compile specific shaders via explicit package paths and added the needed editor assembly reference.
- Updated converter code to load toon shaders via
AssetDatabase.LoadAssetAtPath(with caching) instead ofShader.Find.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
com.unity.toonshader/Tests/Editor/Unity.ToonShader.EditorTests.asmdef |
Adds reference to the editor assembly so tests can access editor-side constants/APIs. |
com.unity.toonshader/Tests/Editor/ShaderCompileTest.cs |
Switches test to compile specific shader assets using ToonEditorConstants paths and asserts they load. |
com.unity.toonshader/Editor/Scripts/ToonEditorConstants.cs |
Introduces centralized shader asset path constants under the package path. |
com.unity.toonshader/Editor/Converter/RenderPipelineConverterContainer.cs |
Replaces Shader.Find with cached load-by-path helper to assign toon shaders during conversion. |
com.unity.toonshader/Editor/Converter/FromUTS2/BuiltInUTS2toIntegratedConverter.cs |
Uses the new shader loading helper during conversion. |
com.unity.toonshader/Editor/AssemblyInfo.cs |
Adds InternalsVisibleTo for the editor tests assembly. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| [assembly: InternalsVisibleTo("Unity.VisualCompositor.Editor")] | ||
| [assembly: InternalsVisibleTo("Unity.VisualCompositor.EditorTests")] | ||
|
|
||
| [assembly: InternalsVisibleTo("Unity.ToonShader.EditorTests")] |
There was a problem hiding this comment.
InternalsVisibleTo target assembly name casing doesn't match the test asmdef name (Unity.Toonshader.EditorTests). If the names don't match exactly, editor internals (e.g., ToonEditorConstants) won't be visible to the tests, causing compile errors. Update the attribute string to exactly match the asmdef's name value (and keep casing consistent across assemblies).
| [assembly: InternalsVisibleTo("Unity.ToonShader.EditorTests")] | |
| [assembly: InternalsVisibleTo("Unity.Toonshader.EditorTests")] |
| protected Shader GetOrLoadToonShader(bool tess) { | ||
| if (tess) { | ||
| return GetOrLoadToonShader(ref m_toonTessShader, ToonEditorConstants.TOON_TESS_SHADER_PATH); | ||
| } | ||
|
|
||
| return GetOrLoadToonShader(ref m_toonShader, ToonEditorConstants.TOON_SHADER_PATH); | ||
|
|
||
| } | ||
|
|
||
| Shader GetOrLoadToonShader(ref Shader shader, string path) { | ||
| if (null != shader) | ||
| return shader; | ||
|
|
||
| shader = AssetDatabase.LoadAssetAtPath<Shader>(path); | ||
| return shader; | ||
| } |
There was a problem hiding this comment.
GetOrLoadToonShader can return null when the shader asset can't be loaded at the expected package path; the caller then assigns material.shader = null, which can break subsequent conversion steps. Add an explicit null check after LoadAssetAtPath (log an actionable error including the path/material), and consider a fallback to Shader.Find using the known shader names to preserve behavior if assets are relocated/missing.
| protected Shader GetOrLoadToonShader(bool tess) { | |
| if (tess) { | |
| return GetOrLoadToonShader(ref m_toonTessShader, ToonEditorConstants.TOON_TESS_SHADER_PATH); | |
| } | |
| return GetOrLoadToonShader(ref m_toonShader, ToonEditorConstants.TOON_SHADER_PATH); | |
| } | |
| Shader GetOrLoadToonShader(ref Shader shader, string path) { | |
| if (null != shader) | |
| return shader; | |
| shader = AssetDatabase.LoadAssetAtPath<Shader>(path); | |
| return shader; | |
| } | |
| protected Shader GetOrLoadToonShader(bool tess, Material material = null) { | |
| if (tess) { | |
| return GetOrLoadToonShader(ref m_toonTessShader, ToonEditorConstants.TOON_TESS_SHADER_PATH, material); | |
| } | |
| return GetOrLoadToonShader(ref m_toonShader, ToonEditorConstants.TOON_SHADER_PATH, material); | |
| } | |
| Shader GetOrLoadToonShader(ref Shader shader, string path, Material material = null) { | |
| if (null != shader) | |
| return shader; | |
| shader = AssetDatabase.LoadAssetAtPath<Shader>(path); | |
| if (null != shader) | |
| return shader; | |
| string shaderFileName = Path.GetFileNameWithoutExtension(path); | |
| shader = FindShaderAssetByFileName(shaderFileName); | |
| if (null != shader) { | |
| Debug.LogWarning($"Toon shader could not be loaded from expected path '{path}' for material '{(material != null ? material.name : "<unknown>")}'. Using relocated shader asset '{shader.name}' found by filename lookup instead."); | |
| return shader; | |
| } | |
| shader = Shader.Find(shaderFileName); | |
| if (null != shader) { | |
| Debug.LogWarning($"Toon shader could not be loaded from expected path '{path}' for material '{(material != null ? material.name : "<unknown>")}'. Using Shader.Find('{shaderFileName}') as a fallback."); | |
| return shader; | |
| } | |
| Debug.LogError($"Failed to load Toon shader from expected path '{path}' for material '{(material != null ? material.name : "<unknown>")}'. Ensure the shader asset exists at that path or pass the correct shader reference to the converter."); | |
| return null; | |
| } | |
| private Shader FindShaderAssetByFileName(string shaderFileName) { | |
| string[] guids = AssetDatabase.FindAssets($"{shaderFileName} t:Shader"); | |
| foreach (string guid in guids) { | |
| string candidatePath = AssetDatabase.GUIDToAssetPath(guid); | |
| if (!string.Equals(Path.GetFileNameWithoutExtension(candidatePath), shaderFileName, StringComparison.OrdinalIgnoreCase)) | |
| continue; | |
| Shader candidateShader = AssetDatabase.LoadAssetAtPath<Shader>(candidatePath); | |
| if (null != candidateShader) | |
| return candidateShader; | |
| } | |
| return null; | |
| } |
No description provided.