浏览代码

First version of DebugItemDrawer

/Branch_Batching2
Julien Ignace 8 年前
当前提交
54b035df
共有 6 个文件被更改,包括 125 次插入41 次删除
  1. 2
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/HDRenderPipelineDebug.cs
  2. 17
      Assets/ScriptableRenderPipeline/common/Debugging/DebugMenu.cs
  3. 4
      Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuManager.cs
  4. 34
      Assets/ScriptableRenderPipeline/common/Debugging/Editor/DebugMenuEditor.cs
  5. 97
      Assets/ScriptableRenderPipeline/common/Debugging/DebugItemDrawer.cs
  6. 12
      Assets/ScriptableRenderPipeline/common/Debugging/DebugItemDrawer.cs.meta

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


{
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, float>("Sky Reflection Mipmap", () => lightingDebugSettings.skyReflectionMipmap, (value) => lightingDebugSettings.skyReflectionMipmap = (float)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugMenu, float>("Sky Reflection Mipmap", () => lightingDebugSettings.skyReflectionMipmap, (value) => lightingDebugSettings.skyReflectionMipmap = (float)value, new DebugItemDrawFloatMinMax(0.0f, 1.0f));
}
public void OnValidate()

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


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

public void SetValue(object value)
{
m_Setter(value);
m_Drawer.ClampValues(m_Getter, m_Setter);
}
public object GetValue()

Action<object> m_Setter;
Type m_Type;
string m_Name;
DebugItemDrawer m_Drawer = null;
}
public class DebugMenu

m_ItemsUI[m_SelectedItem].OnValidate();
}
public void AddDebugMenuItem<ItemType>(string name, Func<object> getter, Action<object> setter)
public void AddDebugMenuItem<ItemType>(string name, Func<object> getter, Action<object> setter, DebugItemDrawer drawer = null)
DebugMenuItem newItem = new DebugMenuItem(name, typeof(ItemType), getter, setter);
if (drawer == null)
drawer = new DebugItemDrawer();
DebugMenuItem newItem = new DebugMenuItem(name, typeof(ItemType), getter, setter, drawer);
drawer.SetDebugItem(newItem);
m_Items.Add(newItem);
}
}

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


return null;
}
public void AddDebugItem<DebugMenuType, ItemType>(string name, Func<object> getter, Action<object> setter) where DebugMenuType : DebugMenu
public void AddDebugItem<DebugMenuType, ItemType>(string name, Func<object> getter, Action<object> setter, DebugItemDrawer drawer = null) where DebugMenuType : DebugMenu
debugMenu.AddDebugMenuItem<ItemType>(name, getter, setter);
debugMenu.AddDebugMenuItem<ItemType>(name, getter, setter, drawer);
}
}
}

34
Assets/ScriptableRenderPipeline/common/Debugging/Editor/DebugMenuEditor.cs


m_DebugMenu = DebugMenuManager.instance;
}
void DrawBoolItem(DebugMenuItem item)
{
EditorGUI.BeginChangeCheck();
bool value = EditorGUILayout.Toggle(item.name, (bool)item.GetValue());
if(EditorGUI.EndChangeCheck())
{
item.SetValue(value);
}
}
void DrawFloatItem(DebugMenuItem item)
{
EditorGUI.BeginChangeCheck();
float value = EditorGUILayout.FloatField(item.name, (float)item.GetValue());
if (EditorGUI.EndChangeCheck())
{
item.SetValue(value);
}
}
void OnMenuItemGUI(DebugMenuItem item)
{
if(item.GetItemType() == typeof(bool))
{
DrawBoolItem(item);
}
else if(item.GetItemType() == typeof(float))
{
DrawFloatItem(item);
}
}
void OnGUI()
{
if (m_DebugMenu == null)

DebugMenu activeMenu = m_DebugMenu.GetDebugMenu(m_DebugMenu.activeMenuIndex);
for (int i = 0; i < activeMenu.itemCount; ++i)
{
OnMenuItemGUI(activeMenu.GetDebugMenuItem(i));
activeMenu.GetDebugMenuItem(i).drawer.OnEditorGUI();
}
}
}

97
Assets/ScriptableRenderPipeline/common/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;
public DebugItemDrawer()
{
}
public void SetDebugItem(DebugMenuItem item)
{
m_MenuItem = item;
}
public virtual void ClampValues(Func<object> getter, Action<object> setter) {}
public virtual void BuildGUI() {}
#if UNITY_EDITOR
void DrawBoolItem()
{
EditorGUI.BeginChangeCheck();
bool value = EditorGUILayout.Toggle(m_MenuItem.name, (bool)m_MenuItem.GetValue());
if (EditorGUI.EndChangeCheck())
{
m_MenuItem.SetValue(value);
}
}
void DrawFloatItem()
{
EditorGUI.BeginChangeCheck();
float value = EditorGUILayout.FloatField(m_MenuItem.name, (float)m_MenuItem.GetValue());
if (EditorGUI.EndChangeCheck())
{
m_MenuItem.SetValue(value);
}
}
public virtual void OnEditorGUI()
{
if (m_MenuItem.GetItemType() == typeof(bool))
{
DrawBoolItem();
}
else if (m_MenuItem.GetItemType() == typeof(float))
{
DrawFloatItem();
}
}
#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 void 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);
}
}
#endif
}
}

12
Assets/ScriptableRenderPipeline/common/Debugging/DebugItemDrawer.cs.meta


fileFormatVersion: 2
guid: 7e413732cbed94f4688d5c59709a4556
timeCreated: 1492787007
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存