using System; using System.Collections.Generic; using System.IO; using System.Linq; using UnityEngine; namespace UnityEditor.Experimental.Rendering.HDPipeline { public class HDEditorUtils { delegate void MaterialResetter(Material material); static Dictionary k_MaterialResetters = new Dictionary() { { "HDRenderPipeline/LayeredLit", LayeredLitGUI.SetupMaterialKeywordsAndPass }, { "HDRenderPipeline/LayeredLitTessellation", LayeredLitGUI.SetupMaterialKeywordsAndPass }, { "HDRenderPipeline/Lit", LitGUI.SetupMaterialKeywordsAndPass }, { "HDRenderPipeline/LitTessellation", LitGUI.SetupMaterialKeywordsAndPass }, { "HDRenderPipeline/Unlit", UnlitGUI.SetupMaterialKeywordsAndPass }, { "HDRenderPipeline/Decal", DecalUI.SetupMaterialKeywordsAndPass } }; public static string GetHDRenderPipelinePath() { return "Packages/com.unity.render-pipelines.high-definition/HDRP/"; } public static string GetPostProcessingPath() { return "Packages/com.unity.postprocessing/"; } public static string GetCorePath() { return "Packages/com.unity.render-pipelines.core/CoreRP/"; } public static T LoadAsset(string relativePath) where T : UnityEngine.Object { return AssetDatabase.LoadAssetAtPath(GetHDRenderPipelinePath() + relativePath); } public static bool ResetMaterialKeywords(Material material) { MaterialResetter resetter; if (k_MaterialResetters.TryGetValue(material.shader.name, out resetter)) { CoreEditorUtils.RemoveMaterialKeywords(material); // We need to reapply ToggleOff/Toggle keyword after reset via ApplyMaterialPropertyDrawers MaterialEditor.ApplyMaterialPropertyDrawers(material); resetter(material); EditorUtility.SetDirty(material); return true; } return false; } public static List GetBaseShaderPreprocessorList() { var baseType = typeof(BaseShaderPreprocessor); var assembly = baseType.Assembly; var types = assembly.GetTypes() .Where(t => t.IsSubclassOf(baseType)) .Select(Activator.CreateInstance) .Cast() .ToList(); return types; } } }