using System; using System.Collections.Generic; using System.Reflection; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.Rendering.Universal; using StringBuilder = System.Text.StringBuilder; namespace UnityEditor.Rendering.Universal { /// /// The default implementation for URP /// [SupportedOnRenderPipeline(typeof(UniversalRenderPipelineAsset))] [CustomEditor(typeof(VolumeComponent), true)] public class UniversalRenderPipelineVolumeComponentEditor : VolumeComponentEditor { private VolumeRequiresRendererFeatures m_FeatureAttribute; /// public override void OnEnable() { base.OnEnable(); // Caching the attribute as UI code can be called multiple times in the same editor frame if (m_FeatureAttribute == null) m_FeatureAttribute = target.GetType().GetCustomAttribute(); } private string GetFeatureTypeNames(in HashSet types) { var typeNameString = new StringBuilder(); foreach (var type in types) typeNameString.AppendFormat("\"{0}\" ", type.Name); return typeNameString.ToString(); } /// protected override void OnBeforeInspectorGUI() { if(m_FeatureAttribute != null) { var rendererFeatures = (GraphicsSettings.currentRenderPipeline is UniversalRenderPipelineAsset urpAsset && urpAsset.scriptableRendererData != null) ? urpAsset.scriptableRendererData.rendererFeatures : null; using (HashSetPool.Get(out var missingFeatureTypes)) { foreach (var elem in m_FeatureAttribute.TargetFeatureTypes) missingFeatureTypes.Add(elem); if (rendererFeatures != null) { foreach (var feature in rendererFeatures) { var featureType = feature.GetType(); if (missingFeatureTypes.Contains(featureType)) { missingFeatureTypes.Remove(featureType); if (missingFeatureTypes.Count == 0) break; } } } if (missingFeatureTypes.Count > 0) { CoreEditorUtils.DrawFixMeBox(string.Format("For this effect to work the {0}renderer feature(s) needs to be added and enabled on the active renderer asset", GetFeatureTypeNames(in missingFeatureTypes)), MessageType.Warning, "Open", () => { Selection.activeObject = UniversalRenderPipeline.asset.scriptableRendererData; GUIUtility.ExitGUI(); }); } } } } } }