浏览代码

- Debug item can be added to a menu given by name (no need to create a new class anymore)

- Implemented int/uint debug items.
/Branch_Batching2
Julien Ignace 8 年前
当前提交
0339b072
共有 5 个文件被更改,包括 208 次插入20 次删除
  1. 8
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/HDRenderPipelineDebug.cs
  2. 29
      Assets/ScriptableRenderPipeline/common/Debugging/DebugItemDrawer.cs
  3. 33
      Assets/ScriptableRenderPipeline/common/Debugging/DebugMenu.cs
  4. 131
      Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuItemUI.cs
  5. 27
      Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuManager.cs

8
Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/HDRenderPipelineDebug.cs


public void RegisterDebug()
{
DebugMenuManager.instance.AddDebugItem<LightingDebugMenu, bool>("Enable Shadows", () => lightingDebugSettings.enableShadows, (value) => lightingDebugSettings.enableShadows = (bool)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugMenu, bool>("Display Sky Reflection", () => lightingDebugSettings.displaySkyReflection, (value) => lightingDebugSettings.displaySkyReflection = (bool)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugMenu, int>("Shadow Map Index", () => lightingDebugSettings.shadowMapIndex, (value) => lightingDebugSettings.shadowMapIndex = (uint)value);
DebugMenuManager.instance.AddDebugItem<bool>("Lighting", "Display Sky Reflection", () => lightingDebugSettings.displaySkyReflection, (value) => lightingDebugSettings.displaySkyReflection = (bool)value);
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);
DebugMenuManager.instance.AddDebugItem<bool>("Rendering", "Enable Distortion",() => renderingDebugSettings.enableDistortion, (value) => renderingDebugSettings.enableDistortion = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>("Rendering", "Enable Subsurface Scattering",() => renderingDebugSettings.enableSSS, (value) => renderingDebugSettings.enableSSS = (bool)value);
}
public void OnValidate()

29
Assets/ScriptableRenderPipeline/common/Debugging/DebugItemDrawer.cs


}
}
void DrawIntItem()
{
EditorGUI.BeginChangeCheck();
int value = EditorGUILayout.IntField(m_MenuItem.name, (int)m_MenuItem.GetValue());
if (EditorGUI.EndChangeCheck())
{
m_MenuItem.SetValue(value);
}
}
void DrawUIntItem()
{
EditorGUI.BeginChangeCheck();
int value = EditorGUILayout.IntField(m_MenuItem.name, (int)(uint)m_MenuItem.GetValue());
if (EditorGUI.EndChangeCheck())
{
value = System.Math.Max(0, value);
m_MenuItem.SetValue((uint)value);
}
}
void DrawFloatItem()
{
EditorGUI.BeginChangeCheck();

if (m_MenuItem.GetItemType() == typeof(bool))
{
DrawBoolItem();
}
else if (m_MenuItem.GetItemType() == typeof(int))
{
DrawIntItem();
}
else if(m_MenuItem.GetItemType() == typeof(uint))
{
DrawUIntItem();
}
else if (m_MenuItem.GetItemType() == typeof(float))
{

33
Assets/ScriptableRenderPipeline/common/Debugging/DebugMenu.cs


private List<DebugMenuItemUI> m_ItemsUI = new List<DebugMenuItemUI>();
private int m_SelectedItem = -1;
public DebugMenu(string name)
{
m_Name = name;
}
public DebugMenuItem GetDebugMenuItem(int index)
{
if (index >= m_Items.Count || index < 0)

if(menuItem.GetItemType() == typeof(bool))
{
newItemUI = new DebugMenuBoolItemUI(m_Root, menuItem);
}
else if (menuItem.GetItemType() == typeof(int))
{
newItemUI = new DebugMenuIntItemUI(m_Root, menuItem);
}
else if (menuItem.GetItemType() == typeof(uint))
{
newItemUI = new DebugMenuUIntItemUI(m_Root, menuItem);
}
else if(menuItem.GetItemType() == typeof(float))
{

: DebugMenu
{
public LightingDebugMenu()
{
m_Name = "Lighting";
}
}
public class RenderingDebugMenu
: DebugMenu
{
public RenderingDebugMenu()
{
m_Name = "Rendering";
}
}
public class PwetteDebugMenu
: DebugMenu
{
public PwetteDebugMenu()
: base("Lighting")
m_Name = "Pwette";
}
}
}

131
Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuItemUI.cs


UpdateText();
}
}
// Everything is done with int. We don't really care about values > 2b for debugging.
public class DebugMenuIntegerItemUI : DebugMenuSimpleItemUI
{
bool m_SelectIncrementMode = false;
int m_CurrentIncrementIndex = 0;
public DebugMenuIntegerItemUI(GameObject parent, DebugMenuItem menuItem)
: base(parent, menuItem)
{
}
protected void UpdateText(int value)
{
bool isNegative = value < 0f;
// Easier to format the string without caring about the '-' sign. We add it back at the end
value = System.Math.Abs(value);
string finalValue = string.Format("{0}", value);
// Add leading zeros until we reach where the current order is being edited.
if(m_CurrentIncrementIndex > 0)
{
int incrementValue = (int)System.Math.Pow(10, m_CurrentIncrementIndex);
if(incrementValue > value)
{
int compareValue = System.Math.Max(value, 1);
while (incrementValue > compareValue)
{
finalValue = finalValue.Insert(0, "0");
compareValue *= 10;
}
}
}
// When selecting which decimal/order you want to edit, we show brackets around the figure to show the user.
if(m_SelectIncrementMode)
{
int bracketIndex = finalValue.Length - 1 - m_CurrentIncrementIndex;
finalValue = finalValue.Insert(bracketIndex, "[");
finalValue = finalValue.Insert(bracketIndex + 2, "]");
}
if(isNegative)
finalValue = finalValue.Insert(0, "-");
m_Value.GetComponent<UI.Text>().text = finalValue;
}
protected virtual int GetIntegerValue()
{
throw new System.NotImplementedException();
}
protected virtual void SetIntegerValue(int value)
{
throw new System.NotImplementedException();
}
public override void OnValidate()
{
m_SelectIncrementMode = !m_SelectIncrementMode;
UpdateText(GetIntegerValue());
}
public override void OnIncrement()
{
if (!m_SelectIncrementMode)
{
SetIntegerValue(GetIntegerValue() + (int)Mathf.Pow(10.0f, (float)m_CurrentIncrementIndex));
}
else
{
m_CurrentIncrementIndex -= 1; // *= 0.1 (10^m_CurrentIncrementIndex)
m_CurrentIncrementIndex = System.Math.Max(0, m_CurrentIncrementIndex);
}
UpdateText(GetIntegerValue());
}
public override void OnDecrement()
{
if (!m_SelectIncrementMode)
{
SetIntegerValue(GetIntegerValue() - (int)Mathf.Pow(10.0f, (float)m_CurrentIncrementIndex));
}
else
{
m_CurrentIncrementIndex += 1; // *= 10 (10^m_CurrentIncrementIndex)
m_CurrentIncrementIndex = System.Math.Max(0, m_CurrentIncrementIndex);
}
UpdateText(GetIntegerValue());
}
}
public class DebugMenuIntItemUI : DebugMenuIntegerItemUI
{
public DebugMenuIntItemUI(GameObject parent, DebugMenuItem menuItem)
: base(parent, menuItem)
{
UpdateText((int)m_MenuItem.GetValue());
}
protected override int GetIntegerValue()
{
return (int)m_MenuItem.GetValue();
}
protected override void SetIntegerValue(int value)
{
m_MenuItem.SetValue(value);
}
}
public class DebugMenuUIntItemUI : DebugMenuIntegerItemUI
{
public DebugMenuUIntItemUI(GameObject parent, DebugMenuItem menuItem)
: base(parent, menuItem)
{
UpdateText((int)(uint)m_MenuItem.GetValue());
}
protected override int GetIntegerValue()
{
return (int)(uint)m_MenuItem.GetValue();
}
protected override void SetIntegerValue(int value)
{
m_MenuItem.SetValue((uint)System.Math.Max(0, value));
}
}
}

27
Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuManager.cs


return null;
}
DebugMenu GetDebugMenu(string name)
{
foreach(DebugMenu menu in m_DebugMenus)
{
if (menu.name == name)
return menu;
}
return null;
}
if (debugMenu != null)
{
debugMenu.AddDebugMenuItem<ItemType>(name, getter, setter, drawer);
}
}
public void AddDebugItem<ItemType>(string debugMenuName, string name, Func<object> getter, Action<object> setter, DebugItemDrawer drawer = 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 = new DebugMenu(debugMenuName);
m_DebugMenus.Add(debugMenu);
}
if (debugMenu != null)
{
debugMenu.AddDebugMenuItem<ItemType>(name, getter, setter, drawer);

正在加载...
取消
保存