浏览代码

First version of debug menu serialization and undo/redo

/Branch_Batching2
Julien Ignace 7 年前
当前提交
20413141
共有 25 个文件被更改,包括 713 次插入594 次删除
  1. 2
      Assets/ScriptableRenderPipeline/Core/Camera/CameraSwitcher.cs
  2. 63
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenu.cs
  3. 7
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuItemUI.cs
  4. 69
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuManager.cs
  5. 3
      Assets/ScriptableRenderPipeline/Core/Debugging/Editor/DebugMenuEditor.cs
  6. 14
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/DebugDisplay.cs
  7. 238
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs
  8. 20
      Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.asset
  9. 325
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugItemHandler.cs
  10. 143
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuState.cs
  11. 12
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuState.cs.meta
  12. 9
      Assets/ScriptableRenderPipeline/Core/Debugging/Serialization.meta
  13. 10
      Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateBool.cs
  14. 12
      Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateBool.cs.meta
  15. 10
      Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateColor.cs
  16. 12
      Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateColor.cs.meta
  17. 10
      Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateFloat.cs
  18. 12
      Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateFloat.cs.meta
  19. 10
      Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateInt.cs
  20. 12
      Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateInt.cs.meta
  21. 10
      Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateUInt.cs
  22. 12
      Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateUInt.cs.meta
  23. 292
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugItemDrawer.cs
  24. 0
      /Assets/ScriptableRenderPipeline/Core/Debugging/DebugItemHandler.cs.meta

2
Assets/ScriptableRenderPipeline/Core/Camera/CameraSwitcher.cs


m_CameraNames[GetCameraCount() - 1] = new GUIContent("Original Camera");
m_CameraIndices[GetCameraCount() - 1] = GetCameraCount() - 1;
DebugMenuManager.instance.AddDebugItem<int>("Camera", "Camera Switcher", () => m_CurrentCameraIndex, (value) => SetCameraIndex((int)value), false, new DebugItemDrawerIntEnum(m_CameraNames, m_CameraIndices));
DebugMenuManager.instance.AddDebugItem<int>("Camera", "Camera Switcher", () => m_CurrentCameraIndex, (value) => SetCameraIndex((int)value), false, new DebugItemHandlerIntEnum(m_CameraNames, m_CameraIndices));
}
int GetCameraCount()

63
Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenu.cs


{
public Type type { get { return m_Type; } }
public string name { get { return m_Name; } }
public DebugItemDrawer drawer { get { return m_Drawer; } }
public DebugItemHandler handler { get { return m_Handler; } }
public DebugMenuItem(string name, Type type, Func<object> getter, Action<object> setter, bool dynamicDisplay = false, DebugItemDrawer drawer = null)
public DebugMenuItem(string name, Type type, Func<object> getter, Action<object> setter, bool dynamicDisplay = false, DebugItemHandler handler = null)
m_Drawer = drawer;
m_Handler = handler;
m_DynamicDisplay = dynamicDisplay;
}

}
public void SetValue(object value)
public void SetValue(object value, bool record = true)
m_Drawer.ClampValues(m_Getter, m_Setter);
m_Handler.ClampValues(m_Getter, m_Setter);
// Update state for serialization/undo
if(record)
m_State.SetValue(m_Getter());
}
}

}
Func<object> m_Getter;
Action<object> m_Setter;
Type m_Type;
string m_Name;
DebugItemDrawer m_Drawer = null;
bool m_DynamicDisplay = false;
public void SetDebugItemState(DebugMenuItemState state)
{
m_State = state;
}
Func<object> m_Getter;
Action<object> m_Setter;
Type m_Type;
string m_Name;
DebugItemHandler m_Handler = null;
bool m_DynamicDisplay = false;
DebugMenuItemState m_State = null;
}
public class DebugMenu

return m_Items[index];
}
public DebugMenuItem GetDebugMenuItem(string name)
{
return m_Items.Find(x => x.name == name);
}
public DebugMenuItem GetSelectedDebugMenuItem()
{
if(m_SelectedItem != -1)

m_ItemsUI.Clear();
foreach (DebugMenuItem menuItem in m_Items)
{
DebugItemDrawer drawer = menuItem.drawer; // Should never be null, we have at least the default drawer
m_ItemsUI.Add(drawer.BuildGUI(m_Root, menuItem));
DebugItemHandler handler = menuItem.handler; // Should never be null, we have at least the default handler
m_ItemsUI.Add(handler.BuildGUI(m_Root));
}
}

m_ItemsUI[m_SelectedItem].OnValidate();
}
public void AddDebugMenuItem<ItemType>(string name, Func<object> getter, Action<object> setter, bool dynamicDisplay = false, DebugItemDrawer drawer = null)
public void AddDebugMenuItem<ItemType>(string name, Func<object> getter, Action<object> setter, bool dynamicDisplay = false, DebugItemHandler handler = null)
if (drawer == null)
drawer = new DebugItemDrawer();
DebugMenuItem newItem = new DebugMenuItem(name, typeof(ItemType), getter, setter, dynamicDisplay, drawer);
drawer.SetDebugItem(newItem);
if (handler == null)
handler = new DefaultDebugItemHandler();
DebugMenuItem newItem = new DebugMenuItem(name, typeof(ItemType), getter, setter, dynamicDisplay, handler);
handler.SetDebugMenuItem(newItem);
DebugMenuManager dmm = DebugMenuManager.instance;
DebugMenuItemState itemState = dmm.FindDebugItemState(name, m_Name);
if(itemState == null)
{
itemState = handler.CreateDebugMenuItemState();
itemState.Initialize(name, m_Name);
itemState.SetValue(getter());
dmm.AddDebugMenuItemState(itemState);
}
newItem.SetDebugItemState(itemState);
}
public void Update()

7
Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuItemUI.cs


namespace UnityEngine.Experimental.Rendering
{
// Class that users need to extend for runtime debug menu item UI
public abstract class DebugMenuItemUI
{
protected GameObject m_Root = null;

m_MenuItem = menuItem;
}
// Implement for selection specific beahavior (like changing color for example)
// Implement behavior when user execute the "Validate" action
// Implement behavior when user execute the "Increment" action
// Implement behavior when user execute the "Decrement" action
// Implement this method to update the UI with current item value.
// User must call it whenever Validate/Increment/Decrement is called. It will also be automatically called for dynamically displayed items.
public abstract void Update();
}

69
Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuManager.cs


{
public class DebugMenuManager
{
static private DebugMenuManager s_Instance = null;
private static DebugMenuManager s_Instance = null;
private static string s_MenuStateAssetPath = "Assets/DebugMenuState.asset";
private DebugMenuState m_DebugMenuState = null;
static public DebugMenuManager instance
{

{
s_Instance = new DebugMenuManager();
s_Instance.Initialize();
}
return s_Instance;

bool m_Enabled = false;
int m_ActiveMenuIndex = 0;
List<DebugMenu> m_DebugMenus = new List<DebugMenu>();
DebugMenu m_PersistentDebugMenu = null;
DebugMenuUI m_DebugMenuUI = null;
bool m_UpdateFromItemStateRequired = false;
public bool isEnabled { get { return m_Enabled; } }
public int activeMenuIndex { get { return m_ActiveMenuIndex; } set { m_ActiveMenuIndex = value; } }
public int menuCount { get { return m_DebugMenus.Count; } }
DebugMenuManager()
{
LookUpDebugMenuClasses();

var updater = Object.FindObjectOfType<DebugMenuUpdater>();
var updater = GameObject.Find("DebugMenuUpdater");
if (updater == null)
{
GameObject go = new GameObject("DebugMenuUpdater");

}
bool m_Enabled = false;
int m_ActiveMenuIndex = 0;
List<DebugMenu> m_DebugMenus = new List<DebugMenu>();
DebugMenu m_PersistentDebugMenu = null;
DebugMenuUI m_DebugMenuUI = null;
private void Initialize()
{
#if UNITY_EDITOR
m_DebugMenuState = UnityEditor.AssetDatabase.LoadAssetAtPath<DebugMenuState>(s_MenuStateAssetPath);
if (m_DebugMenuState == null)
{
m_DebugMenuState = ScriptableObject.CreateInstance<DebugMenuState>();
UnityEditor.AssetDatabase.CreateAsset(m_DebugMenuState, s_MenuStateAssetPath);
}
#endif
}
public void RequireUpdateFromDebugItemState()
{
m_UpdateFromItemStateRequired = true;
}
public bool isEnabled { get { return m_Enabled; } }
public int activeMenuIndex { get { return m_ActiveMenuIndex; } set { m_ActiveMenuIndex = value; } }
public int menuCount { get { return m_DebugMenus.Count; } }
public DebugMenuItemState FindDebugItemState(string itemName, string menuName)
{
return m_DebugMenuState.FindDebugItemState(itemName, menuName);
}
public void AddDebugMenuItemState(DebugMenuItemState state)
{
m_DebugMenuState.AddDebugItemState(state);
}
public DebugMenu GetDebugMenu(int index)
{

return null;
}
DebugMenu GetDebugMenu(string name)
public DebugMenu GetDebugMenu(string name)
{
foreach(DebugMenu menu in m_DebugMenus)
{

m_DebugMenus[m_ActiveMenuIndex].Update();
m_PersistentDebugMenu.Update();
if(m_UpdateFromItemStateRequired)
{
m_UpdateFromItemStateRequired = false;
m_DebugMenuState.UpdateAllItems();
}
public void AddDebugItem<DebugMenuType, ItemType>(string name, Func<object> getter, Action<object> setter = null, bool dynamicDisplay = false, DebugItemDrawer drawer = null) where DebugMenuType : DebugMenu
public void AddDebugItem<DebugMenuType, ItemType>(string name, Func<object> getter, Action<object> setter = null, bool dynamicDisplay = false, DebugItemHandler handler = null) where DebugMenuType : DebugMenu
debugMenu.AddDebugMenuItem<ItemType>(name, getter, setter, dynamicDisplay, drawer);
debugMenu.AddDebugMenuItem<ItemType>(name, getter, setter, dynamicDisplay, handler);
public void AddDebugItem<ItemType>(string debugMenuName, string name, Func<object> getter, Action<object> setter = null, bool dynamicDisplay = false, DebugItemDrawer drawer = null)
public void AddDebugItem<ItemType>(string debugMenuName, string name, Func<object> getter, Action<object> setter = null, bool dynamicDisplay = false, DebugItemHandler handler = null)
{
DebugMenu debugMenu = GetDebugMenu(debugMenuName);
// If the menu does not exist, create a generic one. This way, users don't have to explicitely create a new DebugMenu class if they don't need any particular overriding of default behavior.

if (debugMenu != null)
{
debugMenu.AddDebugMenuItem<ItemType>(name, getter, setter, dynamicDisplay, drawer);
debugMenu.AddDebugMenuItem<ItemType>(name, getter, setter, dynamicDisplay, handler);
}
}
}

3
Assets/ScriptableRenderPipeline/Core/Debugging/Editor/DebugMenuEditor.cs


bool needRepaint = false;
for (int i = 0; i < activeMenu.itemCount; ++i)
{
needRepaint = needRepaint || activeMenu.GetDebugMenuItem(i).drawer.OnEditorGUI();
DebugMenuItem menuItem = activeMenu.GetDebugMenuItem(i);
needRepaint = needRepaint || menuItem.handler.OnEditorGUI();
}
if (needRepaint)

14
Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/DebugDisplay.cs


VisualizeCascade
}
[Serializable]
public bool displayMaterialDebug = false;
public bool displayRenderingDebug = false;
public bool displayLightingDebug = false;
public MaterialDebugSettings materialDebugSettings = new MaterialDebugSettings();
public LightingDebugSettings lightingDebugSettings = new LightingDebugSettings();

DebugMenuManager.instance.AddDebugItem<float>("Display Stats", "Frame Rate", () => 1.0f / Time.deltaTime, null, true);
DebugMenuManager.instance.AddDebugItem<float>("Display Stats", "Frame Time", () => Time.deltaTime * 1000.0f, null, true);
DebugMenuManager.instance.AddDebugItem<int>("Material", "Material",() => materialDebugSettings.debugViewMaterial, (value) => SetDebugViewMaterial((int)value), false, new DebugItemDrawerIntEnum(DebugDisplaySettings.debugViewMaterialStrings, DebugDisplaySettings.debugViewMaterialValues));
DebugMenuManager.instance.AddDebugItem<int>("Material", "Engine",() => materialDebugSettings.debugViewEngine, (value) => SetDebugViewEngine((int)value), false, new DebugItemDrawerIntEnum(DebugDisplaySettings.debugViewEngineStrings, DebugDisplaySettings.debugViewEngineValues));
DebugMenuManager.instance.AddDebugItem<int>("Material", "Material",() => materialDebugSettings.debugViewMaterial, (value) => SetDebugViewMaterial((int)value), false, new DebugItemHandlerIntEnum(DebugDisplaySettings.debugViewMaterialStrings, DebugDisplaySettings.debugViewMaterialValues));
DebugMenuManager.instance.AddDebugItem<int>("Material", "Engine",() => materialDebugSettings.debugViewEngine, (value) => SetDebugViewEngine((int)value), false, new DebugItemHandlerIntEnum(DebugDisplaySettings.debugViewEngineStrings, DebugDisplaySettings.debugViewEngineValues));
DebugMenuManager.instance.AddDebugItem<int>("Material", "GBuffer",() => materialDebugSettings.debugViewGBuffer, (value) => SetDebugViewGBuffer((int)value), false, new DebugItemDrawerIntEnum(DebugDisplaySettings.debugViewMaterialGBufferStrings, DebugDisplaySettings.debugViewMaterialGBufferValues));
DebugMenuManager.instance.AddDebugItem<int>("Material", "GBuffer",() => materialDebugSettings.debugViewGBuffer, (value) => SetDebugViewGBuffer((int)value), false, new DebugItemHandlerIntEnum(DebugDisplaySettings.debugViewMaterialGBufferStrings, DebugDisplaySettings.debugViewMaterialGBufferValues));
DebugMenuManager.instance.AddDebugItem<LightingDebugMenu, bool>("Enable Shadows", () => lightingDebugSettings.enableShadows, (value) => lightingDebugSettings.enableShadows = (bool)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugMenu, ShadowMapDebugMode>("Shadow Debug Mode", () => lightingDebugSettings.shadowDebugMode, (value) => lightingDebugSettings.shadowDebugMode = (ShadowMapDebugMode)value);

DebugMenuManager.instance.AddDebugItem<LightingDebugMenu, float>("Override Smoothness Value", () => lightingDebugSettings.overrideSmoothnessValue, (value) => lightingDebugSettings.overrideSmoothnessValue = (float)value, false, new DebugItemDrawFloatMinMax(0.0f, 1.0f));
DebugMenuManager.instance.AddDebugItem<LightingDebugMenu, float>("Override Smoothness Value", () => lightingDebugSettings.overrideSmoothnessValue, (value) => lightingDebugSettings.overrideSmoothnessValue = (float)value, false, new DebugItemHandlerFloatMinMax(0.0f, 1.0f));
DebugMenuManager.instance.AddDebugItem<LightingDebugMenu, float>("Sky Reflection Mipmap", () => lightingDebugSettings.skyReflectionMipmap, (value) => lightingDebugSettings.skyReflectionMipmap = (float)value, false, new DebugItemDrawFloatMinMax(0.0f, 1.0f));
DebugMenuManager.instance.AddDebugItem<LightingDebugMenu, float>("Sky Reflection Mipmap", () => lightingDebugSettings.skyReflectionMipmap, (value) => lightingDebugSettings.skyReflectionMipmap = (float)value, false, new DebugItemHandlerFloatMinMax(0.0f, 1.0f));
DebugMenuManager.instance.AddDebugItem<bool>("Rendering", "Display Opaque",() => renderingDebugSettings.displayOpaqueObjects, (value) => renderingDebugSettings.displayOpaqueObjects = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>("Rendering", "Display Transparency",() => renderingDebugSettings.displayTransparentObjects, (value) => renderingDebugSettings.displayTransparentObjects = (bool)value);

238
Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs


private SerializedProperty m_DefaultDiffuseMaterial;
private SerializedProperty m_DefaultShader;
// Display Debug
SerializedProperty m_ShowMaterialDebug = null;
SerializedProperty m_ShowLightingDebug = null;
SerializedProperty m_ShowRenderingDebug = null;
SerializedProperty m_DebugOverlayRatio = null;
// Rendering Debug
SerializedProperty m_DisplayOpaqueObjects = null;
SerializedProperty m_DisplayTransparentObjects = null;
SerializedProperty m_EnableDistortion = null;
SerializedProperty m_EnableSSS = null;
// Lighting debug
SerializedProperty m_DebugShadowEnabled = null;
SerializedProperty m_ShadowDebugMode = null;
SerializedProperty m_ShadowDebugShadowMapIndex = null;
SerializedProperty m_LightingDebugOverrideSmoothness = null;
SerializedProperty m_LightingDebugOverrideSmoothnessValue = null;
SerializedProperty m_LightingDebugAlbedo = null;
SerializedProperty m_LightingDebugDisplaySkyReflection = null;
SerializedProperty m_LightingDebugDisplaySkyReflectionMipmap = null;
// Rendering Settings
SerializedProperty m_RenderingUseForwardOnly = null;
SerializedProperty m_RenderingUseDepthPrepass = null;

m_DefaultDiffuseMaterial = serializedObject.FindProperty("m_DefaultDiffuseMaterial");
m_DefaultShader = serializedObject.FindProperty("m_DefaultShader");
// DebugDisplay debug
m_DebugOverlayRatio = FindProperty(x => x.debugDisplaySettings.debugOverlayRatio);
m_ShowLightingDebug = FindProperty(x => x.debugDisplaySettings.displayLightingDebug);
m_ShowRenderingDebug = FindProperty(x => x.debugDisplaySettings.displayRenderingDebug);
m_ShowMaterialDebug = FindProperty(x => x.debugDisplaySettings.displayMaterialDebug);
// Rendering debug
m_DisplayOpaqueObjects = FindProperty(x => x.debugDisplaySettings.renderingDebugSettings.displayOpaqueObjects);
m_DisplayTransparentObjects = FindProperty(x => x.debugDisplaySettings.renderingDebugSettings.displayTransparentObjects);
m_EnableDistortion = FindProperty(x => x.debugDisplaySettings.renderingDebugSettings.enableDistortion);
m_EnableSSS = FindProperty(x => x.debugDisplaySettings.renderingDebugSettings.enableSSS);
// Lighting debug
m_DebugShadowEnabled = FindProperty(x => x.debugDisplaySettings.lightingDebugSettings.enableShadows);
m_ShadowDebugMode = FindProperty(x => x.debugDisplaySettings.lightingDebugSettings.shadowDebugMode);
m_ShadowDebugShadowMapIndex = FindProperty(x => x.debugDisplaySettings.lightingDebugSettings.shadowMapIndex);
m_LightingDebugOverrideSmoothness = FindProperty(x => x.debugDisplaySettings.lightingDebugSettings.overrideSmoothness);
m_LightingDebugOverrideSmoothnessValue = FindProperty(x => x.debugDisplaySettings.lightingDebugSettings.overrideSmoothnessValue);
m_LightingDebugAlbedo = FindProperty(x => x.debugDisplaySettings.lightingDebugSettings.debugLightingAlbedo);
m_LightingDebugDisplaySkyReflection = FindProperty(x => x.debugDisplaySettings.lightingDebugSettings.displaySkyReflection);
m_LightingDebugDisplaySkyReflectionMipmap = FindProperty(x => x.debugDisplaySettings.lightingDebugSettings.skyReflectionMipmap);
// Rendering settings
m_RenderingUseForwardOnly = FindProperty(x => x.renderingSettings.useForwardRenderingOnly);
m_RenderingUseDepthPrepass = FindProperty(x => x.renderingSettings.useDepthPrepass);

method.Invoke(asset, new object[0]);
}
private void DebuggingUI(HDRenderPipeline renderContext, HDRenderPipelineInstance renderpipelineInstance)
{
EditorGUILayout.LabelField(styles.debugging);
// Debug Display settings
EditorGUI.indentLevel++;
m_DebugOverlayRatio.floatValue = EditorGUILayout.Slider(styles.debugOverlayRatio, m_DebugOverlayRatio.floatValue, 0.1f, 1.0f);
EditorGUILayout.Space();
RenderingDebugSettingsUI(renderContext);
MaterialDebugSettingsUI(renderContext);
LightingDebugSettingsUI(renderContext, renderpipelineInstance);
EditorGUILayout.Space();
EditorGUI.indentLevel--;
}
private void MaterialDebugSettingsUI(HDRenderPipeline renderContext)
{
HDRenderPipeline hdPipe = target as HDRenderPipeline;
m_ShowMaterialDebug.boolValue = EditorGUILayout.Foldout(m_ShowMaterialDebug.boolValue, styles.materialDebugLabel);
if (!m_ShowMaterialDebug.boolValue)
return;
EditorGUI.indentLevel++;
bool dirty = false;
EditorGUI.BeginChangeCheck();
int value = EditorGUILayout.IntPopup(styles.debugViewMaterial, hdPipe.debugDisplaySettings.materialDebugSettings.debugViewMaterial, DebugDisplaySettings.debugViewMaterialStrings, DebugDisplaySettings.debugViewMaterialValues);
if (EditorGUI.EndChangeCheck())
{
hdPipe.debugDisplaySettings.SetDebugViewMaterial(value);
dirty = true;
}
EditorGUI.BeginChangeCheck();
value = EditorGUILayout.IntPopup(styles.debugViewEngine, hdPipe.debugDisplaySettings.materialDebugSettings.debugViewEngine, DebugDisplaySettings.debugViewEngineStrings, DebugDisplaySettings.debugViewEngineValues);
if (EditorGUI.EndChangeCheck())
{
hdPipe.debugDisplaySettings.SetDebugViewEngine(value);
dirty = true;
}
EditorGUI.BeginChangeCheck();
value = EditorGUILayout.IntPopup(styles.debugViewMaterialVarying, (int)hdPipe.debugDisplaySettings.materialDebugSettings.debugViewVarying, DebugDisplaySettings.debugViewMaterialVaryingStrings, DebugDisplaySettings.debugViewMaterialVaryingValues);
if (EditorGUI.EndChangeCheck())
{
hdPipe.debugDisplaySettings.SetDebugViewVarying((Attributes.DebugViewVarying)value);
dirty = true;
}
EditorGUI.BeginChangeCheck();
value = EditorGUILayout.IntPopup(styles.debugViewMaterialGBuffer, (int)hdPipe.debugDisplaySettings.materialDebugSettings.debugViewGBuffer, DebugDisplaySettings.debugViewMaterialGBufferStrings, DebugDisplaySettings.debugViewMaterialGBufferValues);
if (EditorGUI.EndChangeCheck())
{
hdPipe.debugDisplaySettings.SetDebugViewGBuffer(value);
dirty = true;
}
if(dirty)
HackSetDirty(renderContext); // Repaint
EditorGUI.indentLevel--;
}
private void RenderingDebugSettingsUI(HDRenderPipeline renderContext)
{
m_ShowRenderingDebug.boolValue = EditorGUILayout.Foldout(m_ShowRenderingDebug.boolValue, styles.renderingDebugSettings);
if (!m_ShowRenderingDebug.boolValue)
return;
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_DisplayOpaqueObjects, styles.displayOpaqueObjects);
EditorGUILayout.PropertyField(m_DisplayTransparentObjects, styles.displayTransparentObjects);
EditorGUILayout.PropertyField(m_EnableDistortion, styles.enableDistortion);
EditorGUILayout.PropertyField(m_EnableSSS, styles.enableSSS);
EditorGUI.indentLevel--;
}
private void SssSettingsUI(HDRenderPipeline pipe)
{
EditorGUILayout.Space();

EditorGUI.indentLevel--;
}
private void LightingDebugSettingsUI(HDRenderPipeline renderContext, HDRenderPipelineInstance renderpipelineInstance)
{
m_ShowLightingDebug.boolValue = EditorGUILayout.Foldout(m_ShowLightingDebug.boolValue, styles.lightingDebugSettings);
if (!m_ShowLightingDebug.boolValue)
return;
HDRenderPipeline hdPipe = target as HDRenderPipeline;
bool dirty = false;
EditorGUI.BeginChangeCheck();
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_DebugShadowEnabled, styles.shadowDebugEnable);
EditorGUILayout.PropertyField(m_ShadowDebugMode, styles.shadowDebugVisualizationMode);
if (!m_ShadowDebugMode.hasMultipleDifferentValues)
{
if ((ShadowMapDebugMode)m_ShadowDebugMode.intValue == ShadowMapDebugMode.VisualizeShadowMap)
{
EditorGUILayout.IntSlider(m_ShadowDebugShadowMapIndex, 0, renderpipelineInstance.GetCurrentShadowCount() - 1, styles.shadowDebugVisualizeShadowIndex);
}
}
if (EditorGUI.EndChangeCheck())
{
dirty = true;
}
EditorGUI.BeginChangeCheck();
int value = EditorGUILayout.IntPopup(styles.lightingVisualizationMode, (int)hdPipe.debugDisplaySettings.lightingDebugSettings.debugLightingMode, styles.debugViewLightingStrings, styles.debugViewLightingValues);
if (EditorGUI.EndChangeCheck())
{
hdPipe.debugDisplaySettings.SetDebugLightingMode((DebugLightingMode)value);
dirty = true;
}
EditorGUI.BeginChangeCheck();
if (hdPipe.debugDisplaySettings.GetDebugLightingMode() == DebugLightingMode.DiffuseLighting)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_LightingDebugAlbedo, styles.lightingDebugAlbedo);
EditorGUI.indentLevel--;
}
if (hdPipe.debugDisplaySettings.GetDebugLightingMode() == DebugLightingMode.SpecularLighting)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_LightingDebugOverrideSmoothness, styles.lightingDebugOverrideSmoothness);
if (!m_LightingDebugOverrideSmoothness.hasMultipleDifferentValues && m_LightingDebugOverrideSmoothness.boolValue == true)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_LightingDebugOverrideSmoothnessValue, styles.lightingDebugOverrideSmoothnessValue);
EditorGUI.indentLevel--;
}
EditorGUI.indentLevel--;
}
EditorGUILayout.PropertyField(m_LightingDebugDisplaySkyReflection, styles.lightingDisplaySkyReflection);
if (!m_LightingDebugDisplaySkyReflection.hasMultipleDifferentValues && m_LightingDebugDisplaySkyReflection.boolValue == true)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(m_LightingDebugDisplaySkyReflectionMipmap, styles.lightingDisplaySkyReflectionMipmap);
EditorGUI.indentLevel--;
}
EditorGUI.indentLevel--;
if (EditorGUI.EndChangeCheck())
{
dirty = true;
}
if(dirty)
HackSetDirty(renderContext);
}
private void SettingsUI(HDRenderPipeline renderContext)
{
EditorGUILayout.LabelField(styles.settingsLabel);

EditorGUI.indentLevel--;
}
/* private void TilePassUI(HDRenderPipeline renderContext)
{
EditorGUILayout.Space();
// TODO: we should call a virtual method or something similar to setup the UI, inspector should not know about it
var tilePass = renderContext.tileSettings;
if (tilePass != null)
{
EditorGUILayout.LabelField(styles.tileLightLoopSettings);
EditorGUI.indentLevel++;
EditorGUI.BeginChangeCheck();
tilePass.enableBigTilePrepass = EditorGUILayout.Toggle(styles.bigTilePrepass, tilePass.enableBigTilePrepass);
tilePass.enableClustered = EditorGUILayout.Toggle(styles.clustered, tilePass.enableClustered);
if (EditorGUI.EndChangeCheck())
{
HackSetDirty(renderContext); // Repaint
// SetAssetDirty will tell renderloop to rebuild
renderContext.DestroyCreatedInstances();
}
EditorGUI.BeginChangeCheck();
tilePass.debugViewTilesFlags = EditorGUILayout.MaskField("DebugView Tiles", tilePass.debugViewTilesFlags, styles.tileLightLoopDebugTileFlagStrings);
tilePass.enableSplitLightEvaluation = EditorGUILayout.Toggle(styles.splitLightEvaluation, tilePass.enableSplitLightEvaluation);
tilePass.enableTileAndCluster = EditorGUILayout.Toggle(styles.enableTileAndCluster, tilePass.enableTileAndCluster);
tilePass.enableComputeLightEvaluation = EditorGUILayout.Toggle(styles.enableComputeLightEvaluation, tilePass.enableComputeLightEvaluation);
if (EditorGUI.EndChangeCheck())
{
HackSetDirty(renderContext); // Repaint
UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
}
EditorGUI.indentLevel--;
}
}*/
public void OnEnable()
{
InitializeProperties();

EditorGUILayout.PropertyField(m_DefaultShader, Styles.defaultShader);
EditorGUI.indentLevel--;
DebuggingUI(renderContext, renderpipelineInstance);
SettingsUI(renderContext);
serializedObject.ApplyModifiedProperties();

20
Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.asset


m_EditorClassIdentifier:
m_LightLoopProducer: {fileID: 11400000, guid: bf8cd9ae03ff7d54c89603e67be0bfc5,
type: 2}
debugDisplaySettings:
debugOverlayRatio: 0.33
displayMaterialDebug: 1
displayRenderingDebug: 0
displayLightingDebug: 0
lightingDebugSettings:
debugLightingMode: 0
enableShadows: 1
shadowDebugMode: 0
shadowMapIndex: 0
overrideSmoothness: 0
overrideSmoothnessValue: 0.5
debugLightingAlbedo: {r: 0.5, g: 0.5, b: 0.5, a: 1}
displaySkyReflection: 0
skyReflectionMipmap: 0
renderingDebugSettings:
displayOpaqueObjects: 1
displayTransparentObjects: 1
enableDistortion: 1
enableSSS: 1
renderingSettings:
useForwardRenderingOnly: 0
useDepthPrepass: 0

325
Assets/ScriptableRenderPipeline/Core/Debugging/DebugItemHandler.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace UnityEngine.Experimental.Rendering
{
public abstract class DebugItemHandler
{
protected DebugMenuItem m_MenuItem = null;
public void SetDebugMenuItem(DebugMenuItem item)
{
m_MenuItem = item;
}
// Method user needs to override for specific value clamping.
public virtual void ClampValues(Func<object> getter, Action<object> setter) {}
// Method that will create UI items for runtime debug menu.
public abstract DebugMenuItemUI BuildGUI(GameObject parent);
// Method users need to override for editor specific UI
public abstract bool OnEditorGUI();
// Method users need to override for specific serialization of custom types.
public abstract DebugMenuItemState CreateDebugMenuItemState();
}
// This is the default debug item handler that handles all basic types.
public class DefaultDebugItemHandler
: DebugItemHandler
{
bool m_IsInitialized = false;
// Label for simple GUI items
protected GUIContent m_Label;
// Values and strings for Enum items
protected List<GUIContent> m_EnumStrings = null;
protected List<int> m_EnumValues = null;
public void Initialize()
{
if (m_IsInitialized)
return;
m_Label = new GUIContent(m_MenuItem.name);
Type itemType = m_MenuItem.GetItemType();
if(itemType.BaseType == typeof(System.Enum))
{
Array arr = Enum.GetValues(itemType);
m_EnumStrings = new List<GUIContent>(arr.Length);
m_EnumValues = new List<int>(arr.Length);
foreach(var value in arr)
{
m_EnumStrings.Add(new GUIContent(value.ToString()));
m_EnumValues.Add((int)value);
}
}
}
public override DebugMenuItemState CreateDebugMenuItemState()
{
DebugMenuItemState newItemState = null;
if (m_MenuItem.GetItemType() == typeof(bool))
{
newItemState = ScriptableObject.CreateInstance<DebugItemStateBool>();
}
else if (m_MenuItem.GetItemType() == typeof(int))
{
newItemState = ScriptableObject.CreateInstance<DebugItemStateInt>();
}
else if (m_MenuItem.GetItemType() == typeof(uint))
{
newItemState = ScriptableObject.CreateInstance<DebugItemStateUInt>();
}
else if (m_MenuItem.GetItemType() == typeof(float))
{
newItemState = ScriptableObject.CreateInstance<DebugItemStateFloat>();
}
else if (m_MenuItem.GetItemType() == typeof(Color))
{
newItemState = ScriptableObject.CreateInstance<DebugItemStateColor>();
}
else if (m_MenuItem.GetItemType().BaseType == typeof(System.Enum))
{
newItemState = ScriptableObject.CreateInstance<DebugItemStateInt>(); // Need to be serialized as int. For some reason serialization of the Enum directly just fails...
}
return newItemState;
}
public override DebugMenuItemUI BuildGUI(GameObject parent)
{
Initialize();
DebugMenuItemUI newItemUI = null;
if (m_MenuItem.GetItemType() == typeof(bool))
{
newItemUI = new DebugMenuBoolItemUI(parent, m_MenuItem, m_Label.text);
}
else if (m_MenuItem.GetItemType() == typeof(int))
{
newItemUI = new DebugMenuIntItemUI(parent, m_MenuItem, m_Label.text);
}
else if (m_MenuItem.GetItemType() == typeof(uint))
{
newItemUI = new DebugMenuUIntItemUI(parent, m_MenuItem, m_Label.text);
}
else if (m_MenuItem.GetItemType() == typeof(float))
{
newItemUI = new DebugMenuFloatItemUI(parent, m_MenuItem, m_Label.text);
}
else if (m_MenuItem.GetItemType() == typeof(Color))
{
newItemUI = new DebugMenuColorItemUI(parent, m_MenuItem, m_Label.text);
}
else if (m_MenuItem.GetItemType().BaseType == typeof(System.Enum))
{
newItemUI = new DebugMenuEnumItemUI(parent, m_MenuItem, m_Label.text, m_EnumStrings.ToArray(), m_EnumValues.ToArray());
}
return newItemUI;
}
#if UNITY_EDITOR
bool DrawBoolItem()
{
bool value = (bool)m_MenuItem.GetValue();
EditorGUI.BeginChangeCheck();
value = EditorGUILayout.Toggle(m_Label, value);
if (EditorGUI.EndChangeCheck())
{
m_MenuItem.SetValue(value);
return true;
}
return false;
}
bool DrawIntItem()
{
int value = (int)m_MenuItem.GetValue();
EditorGUI.BeginChangeCheck();
value = EditorGUILayout.IntField(m_Label, value);
if (EditorGUI.EndChangeCheck())
{
m_MenuItem.SetValue(value);
return true;
}
return false;
}
bool DrawUIntItem()
{
int value = (int)(uint)m_MenuItem.GetValue();
EditorGUI.BeginChangeCheck();
value = EditorGUILayout.IntField(m_Label, value);
if (EditorGUI.EndChangeCheck())
{
value = System.Math.Max(0, value);
m_MenuItem.SetValue((uint)value);
return true;
}
return false;
}
bool DrawFloatItem()
{
float value = (float)m_MenuItem.GetValue();
EditorGUI.BeginChangeCheck();
value = EditorGUILayout.FloatField(m_Label, value);
if (EditorGUI.EndChangeCheck())
{
m_MenuItem.SetValue(value);
return true;
}
return false;
}
bool DrawColorItem()
{
EditorGUI.BeginChangeCheck();
Color value = EditorGUILayout.ColorField(m_Label, (Color)m_MenuItem.GetValue());
if (EditorGUI.EndChangeCheck())
{
m_MenuItem.SetValue(value);
return true;
}
return false;
}
bool DrawEnumItem()
{
EditorGUI.BeginChangeCheck();
int value = EditorGUILayout.IntPopup(m_Label, (int)m_MenuItem.GetValue(), m_EnumStrings.ToArray(), m_EnumValues.ToArray());
if (EditorGUI.EndChangeCheck())
{
m_MenuItem.SetValue(value);
return true;
}
return false;
}
public override bool OnEditorGUI()
{
Initialize();
if (m_MenuItem.readOnly)
{
EditorGUILayout.LabelField(m_Label, new GUIContent(m_MenuItem.GetValue().ToString()));
return false;
}
if (m_MenuItem.GetItemType() == typeof(bool))
{
return DrawBoolItem();
}
else if (m_MenuItem.GetItemType() == typeof(int))
{
return DrawIntItem();
}
else if(m_MenuItem.GetItemType() == typeof(uint))
{
return DrawUIntItem();
}
else if (m_MenuItem.GetItemType() == typeof(float))
{
return DrawFloatItem();
}
else if (m_MenuItem.GetItemType() == typeof(Color))
{
return DrawColorItem();
}
else if (m_MenuItem.GetItemType().BaseType == typeof(System.Enum))
{
return DrawEnumItem();
}
return false;
}
#endif
}
public class DebugItemHandlerFloatMinMax
: DefaultDebugItemHandler
{
float m_Min = 0.0f;
float m_Max = 1.0f;
public DebugItemHandlerFloatMinMax(float min, float max)
{
m_Min = min;
m_Max = max;
}
public override void ClampValues(Func<object> getter, Action<object> setter)
{
setter(Mathf.Clamp((float)getter(), m_Min, m_Max));
}
#if UNITY_EDITOR
public override bool OnEditorGUI()
{
Initialize();
EditorGUI.BeginChangeCheck();
float value = EditorGUILayout.Slider(m_MenuItem.name, (float)m_MenuItem.GetValue(), m_Min, m_Max);
if (EditorGUI.EndChangeCheck())
{
m_MenuItem.SetValue(value);
return true;
}
return false;
}
#endif
}
public class DebugItemHandlerIntEnum
: DefaultDebugItemHandler
{
GUIContent[] m_IntEnumStrings = null;
int[] m_IntEnumValues = null;
public DebugItemHandlerIntEnum(GUIContent[] enumStrings, int[] enumValues)
{
m_IntEnumStrings = enumStrings;
m_IntEnumValues = enumValues;
}
public override DebugMenuItemUI BuildGUI(GameObject parent)
{
Initialize();
return new DebugMenuEnumItemUI(parent, m_MenuItem, m_Label.text, m_IntEnumStrings, m_IntEnumValues);
}
#if UNITY_EDITOR
public override bool OnEditorGUI()
{
Initialize();
UnityEditor.EditorGUI.BeginChangeCheck();
int value = UnityEditor.EditorGUILayout.IntPopup(m_Label, (int)m_MenuItem.GetValue(), m_IntEnumStrings, m_IntEnumValues);
if (UnityEditor.EditorGUI.EndChangeCheck())
{
m_MenuItem.SetValue(value);
return true;
}
return false;
}
#endif
}
}

143
Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuState.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
namespace UnityEngine.Experimental.Rendering
{
[Serializable]
public abstract class DebugMenuItemState
: ScriptableObject
{
public DebugMenuItemState()
{
}
public string menuName = "";
public string itemName = "";
public abstract void UpdateValue();
public abstract void SetValue(object value);
public void Initialize(string itemName, string menuName)
{
this.menuName = menuName;
this.itemName = itemName;
}
}
public class DebugMenuItemState<T> : DebugMenuItemState
{
public T value;
public override void SetValue(object value)
{
#if UNITY_EDITOR
UnityEditor.Undo.RecordObject(this, "DebugMenu State Update");
UnityEditor.EditorUtility.SetDirty(this);
#endif
this.value = (T)value;
}
public override void UpdateValue()
{
DebugMenuManager dmm = DebugMenuManager.instance;
DebugMenu menu = dmm.GetDebugMenu(menuName);
if (menu != null)
{
DebugMenuItem item = menu.GetDebugMenuItem(itemName);
if (item != null)
{
item.SetValue(value, false);
}
}
}
}
public class DebugMenuState
: ScriptableObject
{
[SerializeField]
List<DebugMenuItemState> m_ItemStateList = new List<DebugMenuItemState>();
public void OnEnable()
{
#if UNITY_EDITOR
UnityEditor.Undo.undoRedoPerformed += OnUndoRedoPerformed;
#endif
// We need to delay the actual update because at this point, some menus might not be created yet (depending on call order) so we can't update their values.
DebugMenuManager.instance.RequireUpdateFromDebugItemState();
}
public void OnDisable()
{
#if UNITY_EDITOR
UnityEditor.Undo.undoRedoPerformed -= OnUndoRedoPerformed;
#endif
// We check consistency in OnDisable instead of OnEnable because we compare the serialized state to the currently running debug menu so we need to make sure that all debug menu are properly created (which is not the case in OnEnable depending on call order)
CheckConsistency();
}
#if UNITY_EDITOR
void OnUndoRedoPerformed()
{
// Maybe check a hash or something? So that we don't do that at each redo...
UpdateAllItems();
UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
}
#endif
void CheckConsistency()
{
// Remove all objects that may have been removed from the debug menu.
DebugMenuManager dmm = DebugMenuManager.instance;
List<DebugMenuItemState> tempList = new List<DebugMenuItemState>();
foreach(var itemState in m_ItemStateList)
{
DebugMenuItem item = null;
DebugMenu menu = dmm.GetDebugMenu(itemState.menuName);
if(menu != null)
{
item = menu.GetDebugMenuItem(itemState.itemName);
}
// Item no longer exist, clean up its state from the asset.
if (item == null)
{
tempList.Add(itemState);
}
}
foreach(var itemState in tempList)
{
m_ItemStateList.Remove(itemState);
Object.DestroyImmediate(itemState, true);
}
}
public void AddDebugItemState(DebugMenuItemState state)
{
#if UNITY_EDITOR
UnityEditor.AssetDatabase.AddObjectToAsset(state, this);
#endif
m_ItemStateList.Add(state);
}
public DebugMenuItemState FindDebugItemState(string itemName, string menuName)
{
return m_ItemStateList.Find(x => x.itemName == itemName && x.menuName == menuName);
}
public void UpdateAllItems()
{
foreach (var itemState in m_ItemStateList)
{
itemState.UpdateValue();
}
}
}
}

12
Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuState.cs.meta


fileFormatVersion: 2
guid: d17031e345b144b4a887f66665be6a2b
timeCreated: 1495180913
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

9
Assets/ScriptableRenderPipeline/Core/Debugging/Serialization.meta


fileFormatVersion: 2
guid: a07168baba11f084daec1edd4032f153
folderAsset: yes
timeCreated: 1495456975
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

10
Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateBool.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UnityEngine.Experimental.Rendering
{
public class DebugItemStateBool : DebugMenuItemState<bool>
{
}
}

12
Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateBool.cs.meta


fileFormatVersion: 2
guid: b7b2843778281fb4bbd2a62a3e165c15
timeCreated: 1495456996
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

10
Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateColor.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UnityEngine.Experimental.Rendering
{
public class DebugItemStateColor : DebugMenuItemState<Color>
{
}
}

12
Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateColor.cs.meta


fileFormatVersion: 2
guid: 6e7cea1e2f04a344db1d12f0f1c98f3e
timeCreated: 1495456996
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

10
Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateFloat.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UnityEngine.Experimental.Rendering
{
public class DebugItemStateFloat : DebugMenuItemState<float>
{
}
}

12
Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateFloat.cs.meta


fileFormatVersion: 2
guid: dd5284e29e625f044be91737547ae28d
timeCreated: 1495456996
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

10
Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateInt.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UnityEngine.Experimental.Rendering
{
public class DebugItemStateInt : DebugMenuItemState<int>
{
}
}

12
Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateInt.cs.meta


fileFormatVersion: 2
guid: 7b805c6a0dad19144b48c3fe01b2775d
timeCreated: 1495456996
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

10
Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateUInt.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UnityEngine.Experimental.Rendering
{
public class DebugItemStateUInt : DebugMenuItemState<uint>
{
}
}

12
Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateUInt.cs.meta


fileFormatVersion: 2
guid: cdfed9a25a787094cbad07cb325b88e0
timeCreated: 1495456996
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

292
Assets/ScriptableRenderPipeline/Core/Debugging/DebugItemDrawer.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace UnityEngine.Experimental.Rendering
{
public class DebugItemDrawer
{
protected DebugMenuItem m_MenuItem = null;
// Label for simple GUI items
protected GUIContent m_Label;
protected List<GUIContent> m_EnumStrings = null;
protected List<int> m_EnumValues = null;
public DebugItemDrawer()
{
}
public void SetDebugItem(DebugMenuItem item)
{
m_MenuItem = item;
m_Label = new GUIContent(m_MenuItem.name);
Type itemType = m_MenuItem.GetItemType();
if(itemType.BaseType == typeof(System.Enum))
{
Array arr = Enum.GetValues(itemType);
m_EnumStrings = new List<GUIContent>(arr.Length);
m_EnumValues = new List<int>(arr.Length);
foreach(var value in arr)
{
m_EnumStrings.Add(new GUIContent(value.ToString()));
m_EnumValues.Add((int)value);
}
}
}
public virtual void ClampValues(Func<object> getter, Action<object> setter) {}
public virtual DebugMenuItemUI BuildGUI(GameObject parent, DebugMenuItem menuItem)
{
DebugMenuItemUI newItemUI = null;
if (menuItem.GetItemType() == typeof(bool))
{
newItemUI = new DebugMenuBoolItemUI(parent, menuItem, m_Label.text);
}
else if (menuItem.GetItemType() == typeof(int))
{
newItemUI = new DebugMenuIntItemUI(parent, menuItem, m_Label.text);
}
else if (menuItem.GetItemType() == typeof(uint))
{
newItemUI = new DebugMenuUIntItemUI(parent, menuItem, m_Label.text);
}
else if (menuItem.GetItemType() == typeof(float))
{
newItemUI = new DebugMenuFloatItemUI(parent, menuItem, m_Label.text);
}
else if (menuItem.GetItemType() == typeof(Color))
{
newItemUI = new DebugMenuColorItemUI(parent, menuItem, m_Label.text);
}
else if (m_MenuItem.GetItemType().BaseType == typeof(System.Enum))
{
newItemUI = new DebugMenuEnumItemUI(parent, menuItem, m_Label.text, m_EnumStrings.ToArray(), m_EnumValues.ToArray());
}
return newItemUI;
}
#if UNITY_EDITOR
bool DrawBoolItem()
{
bool value = (bool)m_MenuItem.GetValue();
if (m_MenuItem.readOnly)
{
EditorGUILayout.LabelField(m_Label, new GUIContent(value.ToString()));
}
else
{
EditorGUI.BeginChangeCheck();
value = EditorGUILayout.Toggle(m_Label, value);
if (EditorGUI.EndChangeCheck())
{
m_MenuItem.SetValue(value);
return true;
}
}
return false;
}
bool DrawIntItem()
{
int value = (int)m_MenuItem.GetValue();
if (m_MenuItem.readOnly)
{
EditorGUILayout.LabelField(m_Label, new GUIContent(value.ToString()));
}
else
{
EditorGUI.BeginChangeCheck();
value = EditorGUILayout.IntField(m_Label, value);
if (EditorGUI.EndChangeCheck())
{
m_MenuItem.SetValue(value);
return true;
}
}
return false;
}
bool DrawUIntItem()
{
int value = (int)(uint)m_MenuItem.GetValue();
if (m_MenuItem.readOnly)
{
EditorGUILayout.LabelField(m_Label, new GUIContent(value.ToString()));
}
else
{
EditorGUI.BeginChangeCheck();
value = EditorGUILayout.IntField(m_Label, value);
if (EditorGUI.EndChangeCheck())
{
value = System.Math.Max(0, value);
m_MenuItem.SetValue((uint)value);
return true;
}
}
return false;
}
bool DrawFloatItem()
{
float value = (float)m_MenuItem.GetValue();
if(m_MenuItem.readOnly)
{
EditorGUILayout.LabelField(m_Label, new GUIContent(value.ToString()));
}
else
{
EditorGUI.BeginChangeCheck();
value = EditorGUILayout.FloatField(m_Label, value);
if (EditorGUI.EndChangeCheck())
{
m_MenuItem.SetValue(value);
return true;
}
}
return false;
}
bool DrawColorItem()
{
EditorGUI.BeginChangeCheck();
Color value = EditorGUILayout.ColorField(m_Label, (Color)m_MenuItem.GetValue());
if (EditorGUI.EndChangeCheck())
{
m_MenuItem.SetValue(value);
return true;
}
return false;
}
bool DrawEnumItem()
{
EditorGUI.BeginChangeCheck();
int value = EditorGUILayout.IntPopup(m_Label, (int)m_MenuItem.GetValue(), m_EnumStrings.ToArray(), m_EnumValues.ToArray());
if (EditorGUI.EndChangeCheck())
{
m_MenuItem.SetValue(value);
return true;
}
return false;
}
public virtual bool OnEditorGUI()
{
if (m_MenuItem.GetItemType() == typeof(bool))
{
return DrawBoolItem();
}
else if (m_MenuItem.GetItemType() == typeof(int))
{
return DrawIntItem();
}
else if(m_MenuItem.GetItemType() == typeof(uint))
{
return DrawUIntItem();
}
else if (m_MenuItem.GetItemType() == typeof(float))
{
return DrawFloatItem();
}
else if (m_MenuItem.GetItemType() == typeof(Color))
{
return DrawColorItem();
}
else if (m_MenuItem.GetItemType().BaseType == typeof(System.Enum))
{
return DrawEnumItem();
}
return false;
}
#endif
}
public class DebugItemDrawFloatMinMax
: DebugItemDrawer
{
float m_Min = 0.0f;
float m_Max = 1.0f;
public DebugItemDrawFloatMinMax(float min, float max)
{
m_Min = min;
m_Max = max;
}
public override void ClampValues(Func<object> getter, Action<object> setter)
{
if (m_MenuItem == null)
return;
if(m_MenuItem.GetItemType() == typeof(float))
{
setter(Mathf.Clamp((float)getter(), m_Min, m_Max));
}
}
#if UNITY_EDITOR
public override bool OnEditorGUI()
{
EditorGUI.BeginChangeCheck();
float value = EditorGUILayout.Slider(m_MenuItem.name, (float)m_MenuItem.GetValue(), m_Min, m_Max);
if (EditorGUI.EndChangeCheck())
{
m_MenuItem.SetValue(value);
return true;
}
return false;
}
#endif
}
public class DebugItemDrawerIntEnum
: DebugItemDrawer
{
GUIContent[] m_EnumStrings = null;
int[] m_EnumValues = null;
public DebugItemDrawerIntEnum(GUIContent[] enumStrings, int[] enumValues)
{
m_EnumStrings = enumStrings;
m_EnumValues = enumValues;
}
public override DebugMenuItemUI BuildGUI(GameObject parent, DebugMenuItem menuItem)
{
return new DebugMenuEnumItemUI(parent, menuItem, m_Label.text, m_EnumStrings, m_EnumValues);
}
#if UNITY_EDITOR
public override bool OnEditorGUI()
{
UnityEditor.EditorGUI.BeginChangeCheck();
int value = UnityEditor.EditorGUILayout.IntPopup(m_Label, (int)m_MenuItem.GetValue(), m_EnumStrings, m_EnumValues);
if (UnityEditor.EditorGUI.EndChangeCheck())
{
m_MenuItem.SetValue(value);
return true;
}
return false;
}
#endif
}
}

/Assets/ScriptableRenderPipeline/Core/Debugging/DebugItemDrawer.cs.meta → /Assets/ScriptableRenderPipeline/Core/Debugging/DebugItemHandler.cs.meta

正在加载...
取消
保存