using System;
using System.Collections.Generic;
using System.Reflection;
namespace UnityEditor.Rendering
{
///
/// Core Render Pipeline preferences.
///
public static class CoreRenderPipelinePreferences
{
///
/// Path to the Render Pipeline Preferences
///
public static readonly string corePreferencePath = "Preferences/Core Render Pipeline";
private static readonly List s_Providers = new();
[InitializeOnLoadMethod]
static void InitPreferenceProviders()
{
foreach (var provider in TypeCache.GetTypesDerivedFrom())
{
if (provider.GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, Type.EmptyTypes, null) == null)
continue;
s_Providers.Add(Activator.CreateInstance(provider) as ICoreRenderPipelinePreferencesProvider);
}
}
[SettingsProvider]
static SettingsProvider PreferenceGUI()
{
var provider = new SettingsProvider(corePreferencePath, SettingsScope.User)
{
guiHandler = searchContext =>
{
var labelWidth = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = 251;
using (new EditorGUILayout.HorizontalScope())
{
EditorGUILayout.Space(10, false);
using (new EditorGUILayout.VerticalScope())
{
foreach (var providers in s_Providers)
{
EditorGUILayout.LabelField(providers.header, EditorStyles.boldLabel);
providers.PreferenceGUI();
}
}
}
EditorGUIUtility.labelWidth = labelWidth;
}
};
FillKeywords(provider);
return provider;
}
private static void FillKeywords(SettingsProvider provider)
{
List keywords = new List();
foreach (var providers in s_Providers)
keywords.AddRange(providers.keywords);
provider.keywords = keywords;
}
///
/// Open the Core Rendering Pipeline preference window.
///
public static void Open()
{
SettingsService.OpenUserPreferences(corePreferencePath);
}
}
}