using System; using System.Collections.Generic; using System.IO; using System.Linq; using UnityEngine; using UnityEngine.Experimental.Rendering.HDPipeline; 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 T LoadAsset(string relativePath) where T : UnityEngine.Object { return AssetDatabase.LoadAssetAtPath(HDUtils.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; } } }