using UnityEngine; using UnityEditor; [CustomEditor(typeof(PostEffect))] public class PostEffectEditor : Editor { PostEffect postEffect; bool first_loaded = true; BlurType temp_blurType = BlurType.Standard; public override void OnInspectorGUI() { postEffect = target as PostEffect; DoBloom(); DoFXAA(); DoBlurEffect(); DoCheckMaterial(); first_loaded = false; } void DoBloom() { GUILayout.Label("泛光相关参数", EditorStyles.boldLabel); postEffect.EnableBloom = EditorGUILayout.Toggle("Enable Bloom", postEffect.EnableBloom); postEffect.fastBloomShader = EditorGUILayout.ObjectField("Bloom Shader(Guassian)", postEffect.fastBloomShader, typeof(Shader), true) as Shader; postEffect.dualBloomShader = EditorGUILayout.ObjectField("Bloom Shader(Dual)", postEffect.dualBloomShader, typeof(Shader), true) as Shader; if(postEffect.EnableBloom && postEffect.fastBloomShader != null && postEffect.dualBloomShader != null) { postEffect.use_dual_bloom = EditorGUILayout.Toggle("Use Dual Bloom", postEffect.use_dual_bloom); postEffect.threshold = EditorGUILayout.Slider("Bloom Threshold", postEffect.threshold, 0f, 1.5f); postEffect.intensity = EditorGUILayout.Slider("Bloom Intensity", postEffect.intensity, 0f, 3f); postEffect.blurSize = EditorGUILayout.Slider("Bloom BlurSize", postEffect.blurSize, 0.25f, 5.5f); postEffect.blurIterations = EditorGUILayout.IntSlider("Bloom Iteration", postEffect.blurIterations, 1, 4); postEffect.blurType = (BlurType)EditorGUILayout.EnumPopup("Bloom BlurType", postEffect.blurType); if(temp_blurType != postEffect.blurType || first_loaded) { postEffect.ApplyBloomMaterialProperties(); temp_blurType = postEffect.blurType; } if(GUILayout.Button("Apply Bloom Properties")) { postEffect.ApplyBloomMaterialProperties(); } } GUILayout.Space(20); } void DoFXAA() { GUILayout.Label("FXAA抗锯齿相关参数", EditorStyles.boldLabel); postEffect.EnableFXAA = EditorGUILayout.Toggle("Enable FXAA", postEffect.EnableFXAA); postEffect.FXAAShader = EditorGUILayout.ObjectField("FXAA Shader", postEffect.FXAAShader, typeof(Shader), true) as Shader; if(postEffect.EnableFXAA && postEffect.FXAAShader != null) { postEffect.lowQuality = EditorGUILayout.Toggle("FXAA LowQuality", postEffect.lowQuality); postEffect.contrastThreshold = EditorGUILayout.Slider("FXAA ContrastThreshold", postEffect.contrastThreshold, 0.0312f, 0.0833f); postEffect.relativeThreshold = EditorGUILayout.Slider("FXAA RelativeThreshold", postEffect.relativeThreshold, 0.063f, 0.333f); postEffect.subpixelBlending = EditorGUILayout.Slider("FXAA RelativeThreshold", postEffect.subpixelBlending, 0f, 1f); if(GUILayout.Button("Apply FXAA Properties")) { postEffect.ApplyFXAAMaterialProperties(); } } GUILayout.Space(20); } void DoBlurEffect() { GUILayout.Label("模糊后处理相关参数", EditorStyles.boldLabel); postEffect.EnableBlur = EditorGUILayout.Toggle("Enable Blur", postEffect.EnableBlur); postEffect.blurShader = EditorGUILayout.ObjectField("GuassianBlur Shader", postEffect.blurShader, typeof(Shader), true) as Shader; postEffect.dualBlurShader = EditorGUILayout.ObjectField("DualBlur Shader", postEffect.dualBlurShader, typeof(Shader), true) as Shader; if(postEffect.EnableBlur && postEffect.blurShader != null && postEffect.dualBlurShader != null) { postEffect.use_dual_blur = EditorGUILayout.Toggle("Use Dual Blur", postEffect.use_dual_blur); postEffect.render_blur_effect = EditorGUILayout.Toggle("Use Continues Blur", postEffect.render_blur_effect); // postEffect.get_screen_shot = EditorGUILayout.Toggle("Get Blur ScreenShot", postEffect.get_screen_shot); postEffect.blurSpread = EditorGUILayout.Slider("Blur Spread", postEffect.blurSpread, 0, 10f); postEffect.blur_amount = EditorGUILayout.Slider("Blur Amount", postEffect.blur_amount, 0, 1f); postEffect.recurveMaxNum = EditorGUILayout.IntSlider("Blur Iteration", postEffect.recurveMaxNum, 1, 10); postEffect.downSample = EditorGUILayout.IntSlider("Blur DownSample", postEffect.downSample, 1, 6); } GUILayout.Space(20); } void DoCheckMaterial() { if(GUILayout.Button("Check Material")) { postEffect.CheckResources(); } } }