浏览代码

Added support for readonly and dynamically displayed debug items.

/Branch_Batching2
Julien Ignace 8 年前
当前提交
fb1650c5
共有 7 个文件被更改,包括 152 次插入59 次删除
  1. 7
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/HDRenderPipelineDebug.cs
  2. 66
      Assets/ScriptableRenderPipeline/common/Debugging/DebugItemDrawer.cs
  3. 76
      Assets/ScriptableRenderPipeline/common/Debugging/DebugMenu.cs
  4. 45
      Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuItemUI.cs
  5. 15
      Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuManager.cs
  6. 1
      Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuUI.cs
  7. 1
      Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuUpdater.cs

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


public void RegisterDebug()
{
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<LightingDebugMenu, float>("Override Smoothness Value", () => lightingDebugSettings.overrideSmoothnessValue, (value) => lightingDebugSettings.overrideSmoothnessValue = (float)value, new DebugItemDrawFloatMinMax(0.0f, 1.0f));
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>("Sky Reflection Mipmap", () => lightingDebugSettings.skyReflectionMipmap, (value) => lightingDebugSettings.skyReflectionMipmap = (float)value, new DebugItemDrawFloatMinMax(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<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);

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


#if UNITY_EDITOR
void DrawBoolItem()
{
EditorGUI.BeginChangeCheck();
bool value = EditorGUILayout.Toggle(m_Label, (bool)m_MenuItem.GetValue());
if (EditorGUI.EndChangeCheck())
bool value = (bool)m_MenuItem.GetValue();
if (m_MenuItem.readOnly)
{
EditorGUILayout.LabelField(m_Label, new GUIContent(value.ToString()));
}
else
m_MenuItem.SetValue(value);
EditorGUI.BeginChangeCheck();
value = EditorGUILayout.Toggle(m_Label, value);
if (EditorGUI.EndChangeCheck())
{
m_MenuItem.SetValue(value);
}
EditorGUI.BeginChangeCheck();
int value = EditorGUILayout.IntField(m_Label, (int)m_MenuItem.GetValue());
if (EditorGUI.EndChangeCheck())
int value = (int)m_MenuItem.GetValue();
if (m_MenuItem.readOnly)
m_MenuItem.SetValue(value);
EditorGUILayout.LabelField(m_Label, new GUIContent(value.ToString()));
}
else
{
EditorGUI.BeginChangeCheck();
value = EditorGUILayout.IntField(m_Label, value);
if (EditorGUI.EndChangeCheck())
{
m_MenuItem.SetValue(value);
}
EditorGUI.BeginChangeCheck();
int value = EditorGUILayout.IntField(m_Label, (int)(uint)m_MenuItem.GetValue());
if (EditorGUI.EndChangeCheck())
int value = (int)(uint)m_MenuItem.GetValue();
if (m_MenuItem.readOnly)
{
EditorGUILayout.LabelField(m_Label, new GUIContent(value.ToString()));
}
else
value = System.Math.Max(0, value);
m_MenuItem.SetValue((uint)value);
EditorGUI.BeginChangeCheck();
value = EditorGUILayout.IntField(m_Label, value);
if (EditorGUI.EndChangeCheck())
{
value = System.Math.Max(0, value);
m_MenuItem.SetValue((uint)value);
}
EditorGUI.BeginChangeCheck();
float value = EditorGUILayout.FloatField(m_Label, (float)m_MenuItem.GetValue());
if (EditorGUI.EndChangeCheck())
float value = (float)m_MenuItem.GetValue();
if(m_MenuItem.readOnly)
m_MenuItem.SetValue(value);
EditorGUILayout.LabelField(m_Label, new GUIContent(value.ToString()));
}
else
{
EditorGUI.BeginChangeCheck();
value = EditorGUILayout.FloatField(m_Label, value);
if (EditorGUI.EndChangeCheck())
{
m_MenuItem.SetValue(value);
}
}
}

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


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

m_DynamicDisplay = dynamicDisplay;
}
public Type GetItemType()

public void SetValue(object value)
{
m_Setter(value);
m_Drawer.ClampValues(m_Getter, m_Setter);
// Setter can be null for readonly items
if(m_Setter != null)
{
m_Setter(value);
m_Drawer.ClampValues(m_Getter, m_Setter);
}
}
public object GetValue()

Type m_Type;
string m_Name;
DebugItemDrawer m_Drawer = null;
bool m_DynamicDisplay = false;
}
public class DebugMenu

private List<DebugMenuItem> m_Items = new List<DebugMenuItem>();
private List<DebugMenuItemUI> m_ItemsUI = new List<DebugMenuItemUI>();
private int m_SelectedItem = -1;
private bool m_AllItemsReadOnly = true;
public DebugMenu(string name)
{

void SetSelectedItem(int index)
{
if (m_AllItemsReadOnly)
return;
if(m_SelectedItem != -1)
{
m_ItemsUI[m_SelectedItem].SetSelected(false);

{
if (m_SelectedItem == -1)
{
if(m_Items.Count != 0)
SetSelectedItem(0);
NextItem();
}
else
SetSelectedItem(m_SelectedItem);

int NextItemIndex(int current)
{
return (current + 1) % m_Items.Count;
}
if(m_Items.Count != 0)
if(m_Items.Count != 0 && !m_AllItemsReadOnly)
int newSelected = (m_SelectedItem + 1) % m_Items.Count;
int newSelected = NextItemIndex(m_SelectedItem);
while(m_Items[newSelected].readOnly) // There should always be at least one item that is not readonly because m_AllItemsReadOnly is false.
newSelected = NextItemIndex(newSelected);
int PreviousItemIndex(int current)
{
int newSelected = current - 1;
if (newSelected == -1)
newSelected = m_Items.Count - 1;
return newSelected;
}
if(m_Items.Count != 0)
if(m_Items.Count != 0 && !m_AllItemsReadOnly)
int newSelected = m_SelectedItem - 1;
if (newSelected == -1)
newSelected = m_Items.Count - 1;
int newSelected = PreviousItemIndex(m_SelectedItem);
while (m_Items[newSelected].readOnly) // There should always be at least one item that is not readonly because m_AllItemsReadOnly is false.
newSelected = PreviousItemIndex(newSelected);
SetSelectedItem(newSelected);
}
}

if(m_SelectedItem != -1)
if(m_SelectedItem != -1 && !m_Items[m_SelectedItem].readOnly)
{
if (value > 0.0f)
m_ItemsUI[m_SelectedItem].OnIncrement();

public void OnValidate()
{
if (m_SelectedItem != -1)
if (m_SelectedItem != -1 && !m_Items[m_SelectedItem].readOnly)
public void AddDebugMenuItem<ItemType>(string name, Func<object> getter, Action<object> setter, DebugItemDrawer drawer = null)
public void AddDebugMenuItem<ItemType>(string name, Func<object> getter, Action<object> setter, bool dynamicDisplay = false, DebugItemDrawer drawer = null)
DebugMenuItem newItem = new DebugMenuItem(name, typeof(ItemType), getter, setter, drawer);
DebugMenuItem newItem = new DebugMenuItem(name, typeof(ItemType), getter, setter, dynamicDisplay, drawer);
m_AllItemsReadOnly = m_AllItemsReadOnly && newItem.readOnly;
}
public void Update()
{
// Can happen if the debug menu has been disabled (all UI is destroyed). We can't test DebugMenuManager directly though because of the persistant debug menu (which is always displayed no matter what)
if (m_Root == null)
return;
foreach(var itemUI in m_ItemsUI)
{
if(itemUI.dynamicDisplay)
itemUI.Update();
}
}
}

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


protected GameObject m_Root = null;
protected DebugMenuItem m_MenuItem = null;
public bool dynamicDisplay { get { return m_MenuItem.dynamicDisplay; } }
protected DebugMenuItemUI(DebugMenuItem menuItem)
{
m_MenuItem = menuItem;

public abstract void OnValidate();
public abstract void OnIncrement();
public abstract void OnDecrement();
public abstract void Update();
}
public class DebugMenuSimpleItemUI : DebugMenuItemUI

{
throw new System.NotImplementedException();
}
public override void Update()
{
throw new System.NotImplementedException();
}
}
public class DebugMenuBoolItemUI : DebugMenuSimpleItemUI

{
UpdateText();
Update();
private void UpdateText()
public override void Update()
{
m_Value.GetComponent<UI.Text>().text = (bool)m_MenuItem.GetValue() ? "True" : "False";
}

{
m_MenuItem.SetValue(!(bool)m_MenuItem.GetValue());
UpdateText();
Update();
}
public override void OnIncrement()

public DebugMenuFloatItemUI(GameObject parent, DebugMenuItem menuItem, string name)
: base(parent, menuItem, name)
{
UpdateText();
Update();
private void UpdateText()
public override void Update()
{
float currentValue = (float)m_MenuItem.GetValue();
bool isNegative = currentValue < 0.0f;

public override void OnValidate()
{
m_SelectIncrementMode = !m_SelectIncrementMode;
UpdateText();
Update();
}
public override void OnIncrement()

m_CurrentIncrementIndex -= 1; // * 0.1 (10^m_CurrentIncrementIndex)
m_CurrentIncrementIndex = System.Math.Max(-5, m_CurrentIncrementIndex);
}
UpdateText();
Update();
}
public override void OnDecrement()

{
m_CurrentIncrementIndex += 1; // * 10 (10^m_CurrentIncrementIndex)
}
UpdateText();
Update();
}
}

throw new System.NotImplementedException();
}
public override void Update()
{
UpdateText(GetIntegerValue());
}
UpdateText(GetIntegerValue());
Update();
}
public override void OnIncrement()

m_CurrentIncrementIndex -= 1; // *= 0.1 (10^m_CurrentIncrementIndex)
m_CurrentIncrementIndex = System.Math.Max(0, m_CurrentIncrementIndex);
}
UpdateText(GetIntegerValue());
Update();
}
public override void OnDecrement()

m_CurrentIncrementIndex += 1; // *= 10 (10^m_CurrentIncrementIndex)
m_CurrentIncrementIndex = System.Math.Max(0, m_CurrentIncrementIndex);
}
UpdateText(GetIntegerValue());
Update();
}
}
public class DebugMenuIntItemUI : DebugMenuIntegerItemUI

m_ValueNames = valueNames;
m_CurrentValueIndex = FindIndexForValue((int)m_MenuItem.GetValue());
UpdateText();
Update();
}
private int FindIndexForValue(int value)

return -1;
}
private void UpdateText()
public override void Update()
{
if(m_CurrentValueIndex != -1)
{

{
m_CurrentValueIndex = (m_CurrentValueIndex + 1) % m_Values.Count;
m_MenuItem.SetValue(m_CurrentValueIndex);
UpdateText();
Update();
}
public override void OnDecrement()

m_CurrentValueIndex = m_Values.Count - 1;
m_MenuItem.SetValue(m_CurrentValueIndex);
UpdateText();
Update();
}
}

Update();
}
void Update()
public override void Update()
{
Color currentValue = (Color)m_MenuItem.GetValue();
UI.Image image = m_ColorRect.GetComponent<UI.Image>();

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


T GetDebugMenu<T>() where T:DebugMenu
{
Type debugMenuType = typeof(T);
foreach(DebugMenu menu in m_DebugMenus)
{
if (menu is T)

return null;
}
public void AddDebugItem<DebugMenuType, ItemType>(string name, Func<object> getter, Action<object> setter, DebugItemDrawer drawer = null) where DebugMenuType : DebugMenu
public void Update()
{
if (m_ActiveMenuIndex != -1)
m_DebugMenus[m_ActiveMenuIndex].Update();
}
public void AddDebugItem<DebugMenuType, ItemType>(string name, Func<object> getter, Action<object> setter = null, bool dynamicDisplay = false, DebugItemDrawer drawer = null) where DebugMenuType : DebugMenu
debugMenu.AddDebugMenuItem<ItemType>(name, getter, setter, drawer);
debugMenu.AddDebugMenuItem<ItemType>(name, getter, setter, dynamicDisplay, drawer);
public void AddDebugItem<ItemType>(string debugMenuName, string name, Func<object> getter, Action<object> setter, DebugItemDrawer drawer = null)
public void AddDebugItem<ItemType>(string debugMenuName, string name, Func<object> getter, Action<object> setter = null, bool dynamicDisplay = false, 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.AddDebugMenuItem<ItemType>(name, getter, setter, drawer);
debugMenu.AddDebugMenuItem<ItemType>(name, getter, setter, dynamicDisplay, drawer);
}
}
}

1
Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuUI.cs


GameObject m_Root = null;
GameObject[] m_MenuRoots = null;
bool m_Enabled = false;
int m_ActiveMenuIndex = 0;
DebugMenuManager m_DebugMenuManager = null;
public DebugMenuUI(DebugMenuManager manager)

1
Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuUpdater.cs


void Update()
{
DebugMenuManager.instance.Update();
DebugActionManager.instance.Update();
if (DebugActionManager.instance.GetAction(DebugActionManager.DebugAction.EnableDebugMenu) != 0.0f)

正在加载...
取消
保存