浏览代码

Added support for Enum Debug Items

/Branch_Batching2
Julien Ignace 8 年前
当前提交
f2d353ad
共有 4 个文件被更改,包括 143 次插入39 次删除
  1. 6
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/HDRenderPipelineDebug.cs
  2. 69
      Assets/ScriptableRenderPipeline/common/Debugging/DebugItemDrawer.cs
  3. 21
      Assets/ScriptableRenderPipeline/common/Debugging/DebugMenu.cs
  4. 86
      Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuItemUI.cs

6
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, int>("Shadow Map Index", () => lightingDebugSettings.shadowMapIndex, (value) => lightingDebugSettings.shadowMapIndex = (uint)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugMenu, ShadowMapDebugMode>("Shadow Debug Mode", () => lightingDebugSettings.shadowDebugMode, (value) => lightingDebugSettings.shadowDebugMode = (ShadowMapDebugMode)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugMenu, uint>("Shadow Map Index", () => lightingDebugSettings.shadowMapIndex, (value) => lightingDebugSettings.shadowMapIndex = (uint)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugMenu, LightingDebugMode>("Lighting Debug Mode", () => lightingDebugSettings.lightingDebugMode, (value) => lightingDebugSettings.lightingDebugMode = (LightingDebugMode)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugMenu, bool>("Override Smoothness", () => lightingDebugSettings.overrideSmoothness, (value) => lightingDebugSettings.overrideSmoothness = (bool)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugMenu, float>("Override Smoothness Value", () => lightingDebugSettings.overrideSmoothnessValue, (value) => lightingDebugSettings.overrideSmoothnessValue = (float)value, new DebugItemDrawFloatMinMax(0.0f, 1.0f));
DebugMenuManager.instance.AddDebugItem<bool>("Lighting", "Display Sky Reflection", () => lightingDebugSettings.displaySkyReflection, (value) => lightingDebugSettings.displaySkyReflection = (bool)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugMenu, float>("Sky Reflection Mipmap", () => lightingDebugSettings.skyReflectionMipmap, (value) => lightingDebugSettings.skyReflectionMipmap = (float)value, new DebugItemDrawFloatMinMax(0.0f, 1.0f));

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


{
protected DebugMenuItem m_MenuItem = null;
// Label for simple GUI items
GUIContent m_Label;
List<GUIContent> m_EnumStrings = null;
List<int> m_EnumValues = null;
public DebugItemDrawer()
{
}

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 BuildGUI() {}
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 (m_MenuItem.GetItemType().BaseType == typeof(System.Enum))
{
newItemUI = new DebugMenuEnumItemUI(parent, menuItem, m_Label.text, m_EnumStrings, m_EnumValues);
}
return newItemUI;
}
bool value = EditorGUILayout.Toggle(m_MenuItem.name, (bool)m_MenuItem.GetValue());
bool value = EditorGUILayout.Toggle(m_Label, (bool)m_MenuItem.GetValue());
if (EditorGUI.EndChangeCheck())
{
m_MenuItem.SetValue(value);

void DrawIntItem()
{
EditorGUI.BeginChangeCheck();
int value = EditorGUILayout.IntField(m_MenuItem.name, (int)m_MenuItem.GetValue());
int value = EditorGUILayout.IntField(m_Label, (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());
int value = EditorGUILayout.IntField(m_Label, (int)(uint)m_MenuItem.GetValue());
if (EditorGUI.EndChangeCheck())
{
value = System.Math.Max(0, value);

void DrawFloatItem()
{
EditorGUI.BeginChangeCheck();
float value = EditorGUILayout.FloatField(m_MenuItem.name, (float)m_MenuItem.GetValue());
float value = EditorGUILayout.FloatField(m_Label, (float)m_MenuItem.GetValue());
if (EditorGUI.EndChangeCheck())
{
m_MenuItem.SetValue(value);
}
}
void 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);

else if (m_MenuItem.GetItemType() == typeof(float))
{
DrawFloatItem();
}
else if (m_MenuItem.GetItemType().BaseType == typeof(System.Enum))
{
DrawEnumItem();
}
}
#endif

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


m_ItemsUI.Clear();
foreach(DebugMenuItem menuItem in m_Items)
{
DebugMenuItemUI newItemUI = null;
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))
{
newItemUI = new DebugMenuFloatItemUI(m_Root, menuItem);
}
m_ItemsUI.Add(newItemUI);
DebugItemDrawer drawer = menuItem.drawer; // Should never be null, we have at least the default drawer
m_ItemsUI.Add(drawer.BuildGUI(m_Root, menuItem));
}
m_Root.SetActive(false);

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


protected GameObject m_Name = null;
protected GameObject m_Value = null;
protected DebugMenuSimpleItemUI(GameObject parent, DebugMenuItem menuItem)
protected DebugMenuSimpleItemUI(GameObject parent, DebugMenuItem menuItem, string name)
{
m_MenuItem = menuItem;

horizontalLayout.childForceExpandHeight = false;
horizontalLayout.childForceExpandWidth = false;
m_Name = DebugMenuUI.CreateTextDebugElement(m_MenuItem.name, m_MenuItem.name, 10, TextAnchor.MiddleLeft, m_Root);
m_Name = DebugMenuUI.CreateTextDebugElement(m_MenuItem.name, name, 10, TextAnchor.MiddleLeft, m_Root);
m_Value = DebugMenuUI.CreateTextDebugElement(string.Format("{0} value", m_MenuItem.name), "", 10, TextAnchor.MiddleLeft, m_Root);
m_Value = DebugMenuUI.CreateTextDebugElement(string.Format("{0} value", name), "", 10, TextAnchor.MiddleLeft, m_Root);
}
public override void SetSelected(bool value)

public class DebugMenuBoolItemUI : DebugMenuSimpleItemUI
{
public DebugMenuBoolItemUI(GameObject parent, DebugMenuItem menuItem)
: base(parent, menuItem)
public DebugMenuBoolItemUI(GameObject parent, DebugMenuItem menuItem, string name)
: base(parent, menuItem, name)
{
UpdateText();
}

{
OnValidate();
}
}
}
public class DebugMenuFloatItemUI : DebugMenuSimpleItemUI
{

public DebugMenuFloatItemUI(GameObject parent, DebugMenuItem menuItem)
: base(parent, menuItem)
public DebugMenuFloatItemUI(GameObject parent, DebugMenuItem menuItem, string name)
: base(parent, menuItem, name)
{
UpdateText();
}

bool m_SelectIncrementMode = false;
int m_CurrentIncrementIndex = 0;
public DebugMenuIntegerItemUI(GameObject parent, DebugMenuItem menuItem)
: base(parent, menuItem)
public DebugMenuIntegerItemUI(GameObject parent, DebugMenuItem menuItem, string name)
: base(parent, menuItem, name)
{
}

}
public class DebugMenuIntItemUI : DebugMenuIntegerItemUI
{
public DebugMenuIntItemUI(GameObject parent, DebugMenuItem menuItem)
: base(parent, menuItem)
public DebugMenuIntItemUI(GameObject parent, DebugMenuItem menuItem, string name)
: base(parent, menuItem, name)
{
UpdateText((int)m_MenuItem.GetValue());
}

public class DebugMenuUIntItemUI : DebugMenuIntegerItemUI
{
public DebugMenuUIntItemUI(GameObject parent, DebugMenuItem menuItem)
: base(parent, menuItem)
public DebugMenuUIntItemUI(GameObject parent, DebugMenuItem menuItem, string name)
: base(parent, menuItem, name)
{
UpdateText((int)(uint)m_MenuItem.GetValue());
}

protected override void SetIntegerValue(int value)
{
m_MenuItem.SetValue((uint)System.Math.Max(0, value));
}
}
public class DebugMenuEnumItemUI : DebugMenuSimpleItemUI
{
int m_CurrentValueIndex = 0;
List<GUIContent> m_ValueNames;
List<int> m_Values;
public DebugMenuEnumItemUI(GameObject parent, DebugMenuItem menuItem, string name, List<GUIContent> valueNames, List<int> values)
: base(parent, menuItem, name)
{
m_Values = values;
m_ValueNames = valueNames;
m_CurrentValueIndex = FindIndexForValue((int)m_MenuItem.GetValue());
UpdateText();
}
private int FindIndexForValue(int value)
{
for(int i = 0 ; i < m_Values.Count ; ++i)
{
if (m_Values[i] == value)
return i;
}
return -1;
}
private void UpdateText()
{
if(m_CurrentValueIndex != -1)
{
m_Value.GetComponent<UI.Text>().text = m_ValueNames[m_CurrentValueIndex].text;
}
}
public override void OnValidate()
{
OnIncrement();
}
public override void OnIncrement()
{
m_CurrentValueIndex = (m_CurrentValueIndex + 1) % m_Values.Count;
m_MenuItem.SetValue(m_CurrentValueIndex);
UpdateText();
}
public override void OnDecrement()
{
m_CurrentValueIndex -= 1;
if (m_CurrentValueIndex < 0)
m_CurrentValueIndex = m_Values.Count - 1;
m_MenuItem.SetValue(m_CurrentValueIndex);
UpdateText();
}
}
}
正在加载...
取消
保存