浏览代码

Renamed debug menu classes for consistency

- DebugMenuItem => DebugItem
- DebugMenu => DebugPanel
/Branch_Batching2
Julien Ignace 7 年前
当前提交
6fd2dc66
共有 19 个文件被更改,包括 921 次插入927 次删除
  1. 24
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugActionManager.cs
  2. 110
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugItemHandler.cs
  3. 129
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuManager.cs
  4. 32
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuState.cs
  5. 6
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuUI.cs
  6. 10
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuUpdater.cs
  7. 16
      Assets/ScriptableRenderPipeline/Core/Debugging/Editor/DebugMenuEditor.cs
  8. 2
      Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateBool.cs
  9. 2
      Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateColor.cs
  10. 2
      Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateFloat.cs
  11. 2
      Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateInt.cs
  12. 2
      Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateUInt.cs
  13. 16
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/DebugDisplay.cs
  14. 460
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugItemUI.cs
  15. 281
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugPanel.cs
  16. 294
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenu.cs
  17. 460
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuItemUI.cs
  18. 0
      /Assets/ScriptableRenderPipeline/Core/Debugging/DebugPanel.cs.meta
  19. 0
      /Assets/ScriptableRenderPipeline/Core/Debugging/DebugItemUI.cs.meta

24
Assets/ScriptableRenderPipeline/Core/Debugging/DebugActionManager.cs


public enum DebugAction
{
EnableDebugMenu,
PreviousDebugMenu,
NextDebugMenu,
PreviousDebugPanel,
NextDebugPanel,
Persistent,
MakePersistent,
MoveVertical,
MoveHorizontal,
DebugActionCount

enableDebugMenu.repeatMode = DebugActionRepeatMode.Never;
AddAction(DebugAction.EnableDebugMenu, enableDebugMenu);
DebugActionDesc nextDebugMenu = new DebugActionDesc();
nextDebugMenu.buttonTriggerList.Add(new[] { kDebugNextBtn });
nextDebugMenu.repeatMode = DebugActionRepeatMode.Never;
AddAction(DebugAction.NextDebugMenu, nextDebugMenu);
DebugActionDesc nextDebugPanel = new DebugActionDesc();
nextDebugPanel.buttonTriggerList.Add(new[] { kDebugNextBtn });
nextDebugPanel.repeatMode = DebugActionRepeatMode.Never;
AddAction(DebugAction.NextDebugPanel, nextDebugPanel);
DebugActionDesc previousDebugMenu = new DebugActionDesc();
previousDebugMenu.buttonTriggerList.Add(new[] { kDebugPreviousBtn });
previousDebugMenu.repeatMode = DebugActionRepeatMode.Never;
AddAction(DebugAction.PreviousDebugMenu, previousDebugMenu);
DebugActionDesc previousDebugPanel = new DebugActionDesc();
previousDebugPanel.buttonTriggerList.Add(new[] { kDebugPreviousBtn });
previousDebugPanel.repeatMode = DebugActionRepeatMode.Never;
AddAction(DebugAction.PreviousDebugPanel, previousDebugPanel);
DebugActionDesc validate = new DebugActionDesc();
validate.buttonTriggerList.Add(new[] { kValidateBtn });

DebugActionDesc persistent = new DebugActionDesc();
persistent.buttonTriggerList.Add(new[] { kPersistentBtn });
persistent.repeatMode = DebugActionRepeatMode.Never;
AddAction(DebugAction.Persistent, persistent);
AddAction(DebugAction.MakePersistent, persistent);
AddAction(DebugAction.MoveVertical, new DebugActionDesc { axisTrigger = kDPadVertical, repeatMode = DebugActionRepeatMode.Delay, repeatDelay = 0.2f } );
AddAction(DebugAction.MoveHorizontal, new DebugActionDesc { axisTrigger = kDPadHorizontal, repeatMode = DebugActionRepeatMode.Delay, repeatDelay = 0.2f } );

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


{
public abstract class DebugItemHandler
{
protected DebugMenuItem m_MenuItem = null;
protected DebugItem m_DebugItem = null;
public void SetDebugMenuItem(DebugMenuItem item)
public void SetDebugItem(DebugItem item)
m_MenuItem = item;
m_DebugItem = item;
public abstract DebugMenuItemUI BuildGUI(GameObject parent);
public abstract DebugItemUI BuildGUI(GameObject parent);
public abstract DebugMenuItemState CreateDebugMenuItemState();
public abstract DebugItemState CreateDebugItemState();
}
// This is the default debug item handler that handles all basic types.

if (m_IsInitialized)
return;
m_Label = new GUIContent(m_MenuItem.name);
Type itemType = m_MenuItem.GetItemType();
m_Label = new GUIContent(m_DebugItem.name);
Type itemType = m_DebugItem.GetItemType();
if(itemType.BaseType == typeof(System.Enum))
{
Array arr = Enum.GetValues(itemType);

}
}
public override DebugMenuItemState CreateDebugMenuItemState()
public override DebugItemState CreateDebugItemState()
DebugMenuItemState newItemState = null;
if (m_MenuItem.GetItemType() == typeof(bool))
DebugItemState newItemState = null;
if (m_DebugItem.GetItemType() == typeof(bool))
else if (m_MenuItem.GetItemType() == typeof(int))
else if (m_DebugItem.GetItemType() == typeof(int))
else if (m_MenuItem.GetItemType() == typeof(uint))
else if (m_DebugItem.GetItemType() == typeof(uint))
else if (m_MenuItem.GetItemType() == typeof(float))
else if (m_DebugItem.GetItemType() == typeof(float))
else if (m_MenuItem.GetItemType() == typeof(Color))
else if (m_DebugItem.GetItemType() == typeof(Color))
else if (m_MenuItem.GetItemType().BaseType == typeof(System.Enum))
else if (m_DebugItem.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...
}

public override DebugMenuItemUI BuildGUI(GameObject parent)
public override DebugItemUI BuildGUI(GameObject parent)
DebugMenuItemUI newItemUI = null;
if (m_MenuItem.GetItemType() == typeof(bool))
DebugItemUI newItemUI = null;
if (m_DebugItem.GetItemType() == typeof(bool))
newItemUI = new DebugMenuBoolItemUI(parent, m_MenuItem, m_Label.text);
newItemUI = new DebugBoolItemUI(parent, m_DebugItem, m_Label.text);
else if (m_MenuItem.GetItemType() == typeof(int))
else if (m_DebugItem.GetItemType() == typeof(int))
newItemUI = new DebugMenuIntItemUI(parent, m_MenuItem, m_Label.text);
newItemUI = new DebugIntItemUI(parent, m_DebugItem, m_Label.text);
else if (m_MenuItem.GetItemType() == typeof(uint))
else if (m_DebugItem.GetItemType() == typeof(uint))
newItemUI = new DebugMenuUIntItemUI(parent, m_MenuItem, m_Label.text);
newItemUI = new DebugUIntItemUI(parent, m_DebugItem, m_Label.text);
else if (m_MenuItem.GetItemType() == typeof(float))
else if (m_DebugItem.GetItemType() == typeof(float))
newItemUI = new DebugMenuFloatItemUI(parent, m_MenuItem, m_Label.text);
newItemUI = new DebugFloatItemUI(parent, m_DebugItem, m_Label.text);
else if (m_MenuItem.GetItemType() == typeof(Color))
else if (m_DebugItem.GetItemType() == typeof(Color))
newItemUI = new DebugMenuColorItemUI(parent, m_MenuItem, m_Label.text);
newItemUI = new DebugColorItemUI(parent, m_DebugItem, m_Label.text);
else if (m_MenuItem.GetItemType().BaseType == typeof(System.Enum))
else if (m_DebugItem.GetItemType().BaseType == typeof(System.Enum))
newItemUI = new DebugMenuEnumItemUI(parent, m_MenuItem, m_Label.text, m_EnumStrings.ToArray(), m_EnumValues.ToArray());
newItemUI = new DebugEnumItemUI(parent, m_DebugItem, m_Label.text, m_EnumStrings.ToArray(), m_EnumValues.ToArray());
}
return newItemUI;

bool DrawBoolItem()
{
bool value = (bool)m_MenuItem.GetValue();
bool value = (bool)m_DebugItem.GetValue();
m_MenuItem.SetValue(value);
m_DebugItem.SetValue(value);
return true;
}

bool DrawIntItem()
{
int value = (int)m_MenuItem.GetValue();
int value = (int)m_DebugItem.GetValue();
m_MenuItem.SetValue(value);
m_DebugItem.SetValue(value);
return true;
}

bool DrawUIntItem()
{
int value = (int)(uint)m_MenuItem.GetValue();
int value = (int)(uint)m_DebugItem.GetValue();
m_MenuItem.SetValue((uint)value);
m_DebugItem.SetValue((uint)value);
return true;
}

bool DrawFloatItem()
{
float value = (float)m_MenuItem.GetValue();
float value = (float)m_DebugItem.GetValue();
m_MenuItem.SetValue(value);
m_DebugItem.SetValue(value);
return true;
}

bool DrawColorItem()
{
EditorGUI.BeginChangeCheck();
Color value = EditorGUILayout.ColorField(m_Label, (Color)m_MenuItem.GetValue());
Color value = EditorGUILayout.ColorField(m_Label, (Color)m_DebugItem.GetValue());
m_MenuItem.SetValue(value);
m_DebugItem.SetValue(value);
return true;
}

bool DrawEnumItem()
{
EditorGUI.BeginChangeCheck();
int value = EditorGUILayout.IntPopup(m_Label, (int)m_MenuItem.GetValue(), m_EnumStrings.ToArray(), m_EnumValues.ToArray());
int value = EditorGUILayout.IntPopup(m_Label, (int)m_DebugItem.GetValue(), m_EnumStrings.ToArray(), m_EnumValues.ToArray());
m_MenuItem.SetValue(value);
m_DebugItem.SetValue(value);
return true;
}

{
Initialize();
if (m_MenuItem.readOnly)
if (m_DebugItem.readOnly)
EditorGUILayout.LabelField(m_Label, new GUIContent(m_MenuItem.GetValue().ToString()));
EditorGUILayout.LabelField(m_Label, new GUIContent(m_DebugItem.GetValue().ToString()));
if (m_MenuItem.GetItemType() == typeof(bool))
if (m_DebugItem.GetItemType() == typeof(bool))
else if (m_MenuItem.GetItemType() == typeof(int))
else if (m_DebugItem.GetItemType() == typeof(int))
else if(m_MenuItem.GetItemType() == typeof(uint))
else if(m_DebugItem.GetItemType() == typeof(uint))
else if (m_MenuItem.GetItemType() == typeof(float))
else if (m_DebugItem.GetItemType() == typeof(float))
else if (m_MenuItem.GetItemType() == typeof(Color))
else if (m_DebugItem.GetItemType() == typeof(Color))
else if (m_MenuItem.GetItemType().BaseType == typeof(System.Enum))
else if (m_DebugItem.GetItemType().BaseType == typeof(System.Enum))
{
return DrawEnumItem();
}

Initialize();
EditorGUI.BeginChangeCheck();
float value = EditorGUILayout.Slider(m_MenuItem.name, (float)m_MenuItem.GetValue(), m_Min, m_Max);
float value = EditorGUILayout.Slider(m_DebugItem.name, (float)m_DebugItem.GetValue(), m_Min, m_Max);
m_MenuItem.SetValue(value);
m_DebugItem.SetValue(value);
return true;
}

m_IntEnumValues = enumValues;
}
public override DebugMenuItemUI BuildGUI(GameObject parent)
public override DebugItemUI BuildGUI(GameObject parent)
return new DebugMenuEnumItemUI(parent, m_MenuItem, m_Label.text, m_IntEnumStrings, m_IntEnumValues);
return new DebugEnumItemUI(parent, m_DebugItem, m_Label.text, m_IntEnumStrings, m_IntEnumValues);
}
#if UNITY_EDITOR

UnityEditor.EditorGUI.BeginChangeCheck();
int value = UnityEditor.EditorGUILayout.IntPopup(m_Label, (int)m_MenuItem.GetValue(), m_IntEnumStrings, m_IntEnumValues);
int value = UnityEditor.EditorGUILayout.IntPopup(m_Label, (int)m_DebugItem.GetValue(), m_IntEnumStrings, m_IntEnumValues);
m_MenuItem.SetValue(value);
m_DebugItem.SetValue(value);
return true;
}

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


}
}
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;
bool m_Enabled = false;
int m_ActivePanelIndex = 0;
List<DebugPanel> m_DebugPanels = new List<DebugPanel>();
DebugPanel m_PersistentDebugPanel = 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; } }
public bool isEnabled { get { return m_Enabled; } }
public int activePanelIndex { get { return m_ActivePanelIndex; } set { m_ActivePanelIndex = value; } }
public int panelCount { get { return m_DebugPanels.Count; } }
LookUpDebugMenuClasses();
m_PersistentDebugMenu = new DebugMenu("Persistent");
LookUpDebugPanelClasses();
m_PersistentDebugPanel = new DebugPanel("Persistent");
m_DebugMenuUI = new DebugMenuUI(this);
var updater = GameObject.Find("DebugMenuUpdater");

m_UpdateFromItemStateRequired = true;
}
public DebugMenuItemState FindDebugItemState(string itemName, string menuName)
public DebugItemState FindDebugItemState(string itemName, string menuName)
public void AddDebugMenuItemState(DebugMenuItemState state)
public void AddDebugItemState(DebugItemState state)
public DebugMenu GetDebugMenu(int index)
public DebugPanel GetDebugPanel(int index)
if (index < m_DebugMenus.Count)
return m_DebugMenus[index];
if (index < m_DebugPanels.Count)
return m_DebugPanels[index];
public DebugMenu GetPersistentDebugMenu()
public DebugPanel GetPersistentDebugPanel()
return m_PersistentDebugMenu;
return m_PersistentDebugPanel;
void LookUpDebugMenuClasses()
void LookUpDebugPanelClasses()
var types = Assembly.GetAssembly(typeof(DebugMenu)).GetTypes()
.Where(t => t.IsSubclassOf(typeof(DebugMenu)));
var types = Assembly.GetAssembly(typeof(DebugPanel)).GetTypes()
.Where(t => t.IsSubclassOf(typeof(DebugPanel)));
m_DebugMenus.Clear();
m_DebugPanels.Clear();
m_DebugMenus.Add((DebugMenu)Activator.CreateInstance(type));
m_DebugPanels.Add((DebugPanel)Activator.CreateInstance(type));
public void PreviousDebugMenu()
public void PreviousDebugPanel()
m_DebugMenus[m_ActiveMenuIndex].SetSelected(false);
m_ActiveMenuIndex = m_ActiveMenuIndex - 1;
if (m_ActiveMenuIndex == -1)
m_ActiveMenuIndex = m_DebugMenus.Count - 1;
m_DebugPanels[m_ActivePanelIndex].SetSelected(false);
m_ActivePanelIndex = m_ActivePanelIndex - 1;
if (m_ActivePanelIndex == -1)
m_ActivePanelIndex = m_DebugPanels.Count - 1;
m_DebugMenus[m_ActiveMenuIndex].SetSelected(true);
m_DebugPanels[m_ActivePanelIndex].SetSelected(true);
//m_DebugMenuUI.Toggle();
//m_DebugMenuUI.Toggle();
public void NextDebugMenu()
public void NextDebugPanel()
m_DebugMenus[m_ActiveMenuIndex].SetSelected(false);
m_ActiveMenuIndex = (m_ActiveMenuIndex + 1) % m_DebugMenus.Count;
m_DebugMenus[m_ActiveMenuIndex].SetSelected(true);
m_DebugPanels[m_ActivePanelIndex].SetSelected(false);
m_ActivePanelIndex = (m_ActivePanelIndex + 1) % m_DebugPanels.Count;
m_DebugPanels[m_ActivePanelIndex].SetSelected(true);
//m_DebugMenuUI.Toggle();
//m_DebugMenuUI.Toggle();
}
public void ToggleMenu()

m_DebugMenuUI.BuildGUI();
m_DebugMenuUI.Toggle();
m_DebugMenus[m_ActiveMenuIndex].SetSelected(m_Enabled);
m_DebugPanels[m_ActivePanelIndex].SetSelected(m_Enabled);
m_DebugMenus[m_ActiveMenuIndex].OnValidate();
m_DebugPanels[m_ActivePanelIndex].OnValidate();
DebugMenuItem selectedItem = m_DebugMenus[m_ActiveMenuIndex].GetSelectedDebugMenuItem();
DebugItem selectedItem = m_DebugPanels[m_ActivePanelIndex].GetSelectedDebugItem();
if(m_PersistentDebugMenu.HasItem(selectedItem))
if(m_PersistentDebugPanel.HasDebugItem(selectedItem))
m_PersistentDebugMenu.RemoveDebugItem(selectedItem);
m_PersistentDebugPanel.RemoveDebugItem(selectedItem);
m_PersistentDebugMenu.AddDebugItem(selectedItem);
m_PersistentDebugPanel.AddDebugItem(selectedItem);
if(m_PersistentDebugMenu.itemCount == 0)
if(m_PersistentDebugPanel.itemCount == 0)
m_PersistentDebugMenu.SetSelected(false);
m_PersistentDebugPanel.SetSelected(false);
m_PersistentDebugMenu.SetSelected(true);
m_PersistentDebugPanel.SetSelected(true);
m_DebugMenuUI.EnablePersistentView(true);
}
}

m_DebugMenus[m_ActiveMenuIndex].OnMoveHorizontal(value);
m_DebugPanels[m_ActivePanelIndex].OnMoveHorizontal(value);
m_DebugMenus[m_ActiveMenuIndex].OnMoveVertical(value);
m_DebugPanels[m_ActivePanelIndex].OnMoveVertical(value);
T GetDebugMenu<T>() where T:DebugMenu
T GetDebugPanel<T>() where T:DebugPanel
foreach(DebugMenu menu in m_DebugMenus)
foreach(DebugPanel menu in m_DebugPanels)
{
if (menu is T)
return menu as T;

}
public DebugMenu GetDebugMenu(string name)
public DebugPanel GetDebugPanel(string name)
foreach(DebugMenu menu in m_DebugMenus)
foreach(DebugPanel menu in m_DebugPanels)
{
if (menu.name == name)
return menu;

public void Update()
{
if (m_ActiveMenuIndex != -1)
m_DebugMenus[m_ActiveMenuIndex].Update();
if (m_ActivePanelIndex != -1)
m_DebugPanels[m_ActivePanelIndex].Update();
m_PersistentDebugMenu.Update();
m_PersistentDebugPanel.Update();
if(m_UpdateFromItemStateRequired)
{

}
public void AddDebugItem<DebugMenuType, ItemType>(string name, Func<object> getter, Action<object> setter = null, bool dynamicDisplay = false, DebugItemHandler handler = null) where DebugMenuType : DebugMenu
public void AddDebugItem<DebugPanelType, DebugItemType>(string name, Func<object> getter, Action<object> setter = null, bool dynamicDisplay = false, DebugItemHandler handler = null) where DebugPanelType : DebugPanel
DebugMenuType debugMenu = GetDebugMenu<DebugMenuType>();
DebugPanelType debugMenu = GetDebugPanel<DebugPanelType>();
debugMenu.AddDebugMenuItem<ItemType>(name, getter, setter, dynamicDisplay, handler);
debugMenu.AddDebugItem<DebugItemType>(name, getter, setter, dynamicDisplay, handler);
public void AddDebugItem<ItemType>(string debugMenuName, string name, Func<object> getter, Action<object> setter = null, bool dynamicDisplay = false, DebugItemHandler handler = null)
public void AddDebugItem<DebugItemType>(string debugPanelName, string name, Func<object> getter, Action<object> setter = null, bool dynamicDisplay = false, DebugItemHandler handler = null)
DebugMenu debugMenu = GetDebugMenu(debugMenuName);
DebugPanel debugPanel = GetDebugPanel(debugPanelName);
if(debugMenu == null)
if(debugPanel == null)
debugMenu = new DebugMenu(debugMenuName);
m_DebugMenus.Add(debugMenu);
debugPanel = new DebugPanel(debugPanelName);
m_DebugPanels.Add(debugPanel);
if (debugMenu != null)
if (debugPanel != null)
debugMenu.AddDebugMenuItem<ItemType>(name, getter, setter, dynamicDisplay, handler);
debugPanel.AddDebugItem<DebugItemType>(name, getter, setter, dynamicDisplay, handler);
}
}
}

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


namespace UnityEngine.Experimental.Rendering
{
[Serializable]
public abstract class DebugMenuItemState
public abstract class DebugItemState
public DebugMenuItemState()
public DebugItemState()
public string menuName = "";
public string panelName = "";
public void Initialize(string itemName, string menuName)
public void Initialize(string itemName, string panelName)
this.menuName = menuName;
this.panelName = panelName;
public class DebugMenuItemState<T> : DebugMenuItemState
public class DebugItemState<T> : DebugItemState
{
public T value;

public override void UpdateValue()
{
DebugMenuManager dmm = DebugMenuManager.instance;
DebugMenu menu = dmm.GetDebugMenu(menuName);
DebugPanel menu = dmm.GetDebugPanel(panelName);
DebugMenuItem item = menu.GetDebugMenuItem(itemName);
DebugItem item = menu.GetDebugItem(itemName);
if (item != null)
{
item.SetValue(value, false);

: ScriptableObject
{
[SerializeField]
List<DebugMenuItemState> m_ItemStateList = new List<DebugMenuItemState>();
List<DebugItemState> m_ItemStateList = new List<DebugItemState>();
public void OnEnable()
{

{
// Remove all objects that may have been removed from the debug menu.
DebugMenuManager dmm = DebugMenuManager.instance;
List<DebugMenuItemState> tempList = new List<DebugMenuItemState>();
List<DebugItemState> tempList = new List<DebugItemState>();
DebugMenuItem item = null;
DebugMenu menu = dmm.GetDebugMenu(itemState.menuName);
DebugItem item = null;
DebugPanel menu = dmm.GetDebugPanel(itemState.panelName);
item = menu.GetDebugMenuItem(itemState.itemName);
item = menu.GetDebugItem(itemState.itemName);
}
// Item no longer exist, clean up its state from the asset.

}
}
public void AddDebugItemState(DebugMenuItemState state)
public void AddDebugItemState(DebugItemState state)
{
#if UNITY_EDITOR
UnityEditor.AssetDatabase.AddObjectToAsset(state, this);

public DebugMenuItemState FindDebugItemState(string itemName, string menuName)
public DebugItemState FindDebugItemState(string itemName, string menuName)
return m_ItemStateList.Find(x => x.itemName == itemName && x.menuName == menuName);
return m_ItemStateList.Find(x => x.itemName == itemName && x.panelName == menuName);
}
public void UpdateAllItems()

6
Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuUI.cs


DebugMenuUI.CreateTextElement("DebugMenuTitle", "Debug Menu", 14, TextAnchor.MiddleCenter, goVL);
int menuCount = m_DebugMenuManager.menuCount;
int menuCount = m_DebugMenuManager.panelCount;
m_MenuRoots[i] = m_DebugMenuManager.GetDebugMenu(i).BuildGUI(goVL);
m_MenuRoots[i] = m_DebugMenuManager.GetDebugPanel(i).BuildGUI(goVL);
m_DebugMenuManager.GetPersistentDebugMenu().BuildGUI(goVL2);
m_DebugMenuManager.GetPersistentDebugPanel().BuildGUI(goVL2);
}
public static GameObject CreateVerticalLayoutGroup(string name, bool controlWidth, bool controlHeight, bool forceExpandWidth, bool forceExpandHeight, GameObject parent = null )

10
Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuUpdater.cs


if (DebugMenuManager.instance.isEnabled)
{
if (DebugActionManager.instance.GetAction(DebugActionManager.DebugAction.PreviousDebugMenu) != 0.0f)
if (DebugActionManager.instance.GetAction(DebugActionManager.DebugAction.PreviousDebugPanel) != 0.0f)
DebugMenuManager.instance.PreviousDebugMenu();
DebugMenuManager.instance.PreviousDebugPanel();
if (DebugActionManager.instance.GetAction(DebugActionManager.DebugAction.NextDebugMenu) != 0.0f)
if (DebugActionManager.instance.GetAction(DebugActionManager.DebugAction.NextDebugPanel) != 0.0f)
DebugMenuManager.instance.NextDebugMenu();
DebugMenuManager.instance.NextDebugPanel();
}
if (DebugActionManager.instance.GetAction(DebugActionManager.DebugAction.Validate) != 0.0f)

if (DebugActionManager.instance.GetAction(DebugActionManager.DebugAction.Persistent) != 0.0f)
if (DebugActionManager.instance.GetAction(DebugActionManager.DebugAction.MakePersistent) != 0.0f)
{
DebugMenuManager.instance.OnMakePersistent();
}

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


// Contrary to the menu in the player, here we always render the menu wether it's enabled or not. This is a separate window so user can manage it however they want.
EditorGUI.BeginChangeCheck();
int debugMenuCount = m_DebugMenu.menuCount;
int activeMenuIndex = m_DebugMenu.activeMenuIndex;
int debugMenuCount = m_DebugMenu.panelCount;
int activeMenuIndex = m_DebugMenu.activePanelIndex;
using (new EditorGUILayout.HorizontalScope())
{
for(int i = 0 ; i < debugMenuCount ; ++i)

style = EditorStyles.miniButtonLeft;
if (i == debugMenuCount - 1)
style = EditorStyles.miniButtonRight;
if (GUILayout.Toggle(i == activeMenuIndex, new GUIContent(m_DebugMenu.GetDebugMenu(i).name), style))
if (GUILayout.Toggle(i == activeMenuIndex, new GUIContent(m_DebugMenu.GetDebugPanel(i).name), style))
m_DebugMenu.activeMenuIndex = activeMenuIndex;
m_DebugMenu.activePanelIndex = activeMenuIndex;
DebugMenu activeMenu = m_DebugMenu.GetDebugMenu(m_DebugMenu.activeMenuIndex);
DebugPanel activePanel = m_DebugMenu.GetDebugPanel(m_DebugMenu.activePanelIndex);
for (int i = 0; i < activeMenu.itemCount; ++i)
for (int i = 0; i < activePanel.itemCount; ++i)
DebugMenuItem menuItem = activeMenu.GetDebugMenuItem(i);
needRepaint = needRepaint || menuItem.handler.OnEditorGUI();
DebugItem debugItem = activePanel.GetDebugItem(i);
needRepaint = needRepaint || debugItem.handler.OnEditorGUI();
}
if (needRepaint)

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


namespace UnityEngine.Experimental.Rendering
{
public class DebugItemStateBool : DebugMenuItemState<bool>
public class DebugItemStateBool : DebugItemState<bool>
{
}
}

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


namespace UnityEngine.Experimental.Rendering
{
public class DebugItemStateColor : DebugMenuItemState<Color>
public class DebugItemStateColor : DebugItemState<Color>
{
}
}

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


namespace UnityEngine.Experimental.Rendering
{
public class DebugItemStateFloat : DebugMenuItemState<float>
public class DebugItemStateFloat : DebugItemState<float>
{
}
}

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


namespace UnityEngine.Experimental.Rendering
{
public class DebugItemStateInt : DebugMenuItemState<int>
public class DebugItemStateInt : DebugItemState<int>
{
}
}

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


namespace UnityEngine.Experimental.Rendering
{
public class DebugItemStateUInt : DebugMenuItemState<uint>
public class DebugItemStateUInt : DebugItemState<uint>
{
}
}

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


DebugMenuManager.instance.AddDebugItem<Attributes.DebugViewVarying>("Material", "Attributes",() => materialDebugSettings.debugViewVarying, (value) => SetDebugViewVarying((Attributes.DebugViewVarying)value));
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, uint>("Shadow Map Index", () => lightingDebugSettings.shadowMapIndex, (value) => lightingDebugSettings.shadowMapIndex = (uint)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugMenu, DebugLightingMode>("Lighting Debug Mode", () => lightingDebugSettings.debugLightingMode, (value) => SetDebugLightingMode((DebugLightingMode)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, false, new DebugItemHandlerFloatMinMax(0.0f, 1.0f));
DebugMenuManager.instance.AddDebugItem<LightingDebugMenu, Color>("Debug Lighting Albedo", () => lightingDebugSettings.debugLightingAlbedo, (value) => lightingDebugSettings.debugLightingAlbedo = (Color)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, bool>("Enable Shadows", () => lightingDebugSettings.enableShadows, (value) => lightingDebugSettings.enableShadows = (bool)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, ShadowMapDebugMode>("Shadow Debug Mode", () => lightingDebugSettings.shadowDebugMode, (value) => lightingDebugSettings.shadowDebugMode = (ShadowMapDebugMode)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, uint>("Shadow Map Index", () => lightingDebugSettings.shadowMapIndex, (value) => lightingDebugSettings.shadowMapIndex = (uint)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, DebugLightingMode>("Lighting Debug Mode", () => lightingDebugSettings.debugLightingMode, (value) => SetDebugLightingMode((DebugLightingMode)value));
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, bool>("Override Smoothness", () => lightingDebugSettings.overrideSmoothness, (value) => lightingDebugSettings.overrideSmoothness = (bool)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, float>("Override Smoothness Value", () => lightingDebugSettings.overrideSmoothnessValue, (value) => lightingDebugSettings.overrideSmoothnessValue = (float)value, false, new DebugItemHandlerFloatMinMax(0.0f, 1.0f));
DebugMenuManager.instance.AddDebugItem<LightingDebugPanel, Color>("Debug Lighting Albedo", () => lightingDebugSettings.debugLightingAlbedo, (value) => lightingDebugSettings.debugLightingAlbedo = (Color)value);
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<LightingDebugPanel, 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);

460
Assets/ScriptableRenderPipeline/Core/Debugging/DebugItemUI.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UnityEngine.Experimental.Rendering
{
// Class that users need to extend for runtime debug menu item UI
public abstract class DebugItemUI
{
protected GameObject m_Root = null;
protected DebugItem m_DebugItem = null;
public bool dynamicDisplay { get { return m_DebugItem.dynamicDisplay; } }
protected DebugItemUI(DebugItem debugItem)
{
m_DebugItem = debugItem;
}
// Implement for selection specific beahavior (like changing color for example)
public abstract void SetSelected(bool value);
// Implement behavior when user execute the "Validate" action
public abstract void OnValidate();
// Implement behavior when user execute the "Increment" action
public abstract void OnIncrement();
// Implement behavior when user execute the "Decrement" action
public abstract void OnDecrement();
// 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();
}
public class DebugSimpleItemUI : DebugItemUI
{
protected GameObject m_Name = null;
protected GameObject m_Value = null;
protected DebugSimpleItemUI(GameObject parent, DebugItem debugItem, string name)
: base(debugItem)
{
m_Root = DebugMenuUI.CreateHorizontalLayoutGroup("", true, true, false, false, parent);
m_Name = DebugMenuUI.CreateTextElement(m_DebugItem.name, name, 10, TextAnchor.MiddleLeft, m_Root);
var layoutElem = m_Name.AddComponent<UI.LayoutElement>();
layoutElem.minWidth = DebugMenuUI.kDebugItemNameWidth;
m_Value = DebugMenuUI.CreateTextElement(string.Format("{0} value", name), "", 10, TextAnchor.MiddleLeft, m_Root);
}
public override void SetSelected(bool value)
{
m_Name.GetComponent<UI.Text>().color = value ? DebugMenuUI.kColorSelected : DebugMenuUI.kColorUnSelected;
m_Value.GetComponent<UI.Text>().color = value ? DebugMenuUI.kColorSelected : DebugMenuUI.kColorUnSelected;
}
public override void OnValidate()
{
throw new System.NotImplementedException();
}
public override void OnIncrement()
{
throw new System.NotImplementedException();
}
public override void OnDecrement()
{
throw new System.NotImplementedException();
}
public override void Update()
{
throw new System.NotImplementedException();
}
}
public class DebugBoolItemUI : DebugSimpleItemUI
{
public DebugBoolItemUI(GameObject parent, DebugItem debugItem, string name)
: base(parent, debugItem, name)
{
Update();
}
public override void Update()
{
m_Value.GetComponent<UI.Text>().text = (bool)m_DebugItem.GetValue() ? "True" : "False";
}
public override void OnValidate()
{
m_DebugItem.SetValue(!(bool)m_DebugItem.GetValue());
Update();
}
public override void OnIncrement()
{
OnValidate();
}
public override void OnDecrement()
{
OnValidate();
}
}
public class DebugFloatItemUI : DebugSimpleItemUI
{
bool m_SelectIncrementMode = false;
int m_CurrentIncrementIndex = -1;
public DebugFloatItemUI(GameObject parent, DebugItem debugItem, string name)
: base(parent, debugItem, name)
{
Update();
}
public override void Update()
{
float currentValue = (float)m_DebugItem.GetValue();
bool isNegative = currentValue < 0.0f;
// Easier to format the string without caring about the '-' sign. We add it back at the end
currentValue = Mathf.Abs(currentValue);
char separator = System.Convert.ToChar(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator);
// Start with the maximum amount of trailing zeros
string valueWithMaxDecimals = string.Format("{0:0.00000}", currentValue);
// Remove trailing zeros until we reach the separator or we reach the decimal we are currently editing.
int separatorIndex = valueWithMaxDecimals.LastIndexOf(separator);
int index = valueWithMaxDecimals.Length - 1;
while (
valueWithMaxDecimals[index] == '0' // Remove trailing zeros
&& index > (separatorIndex + 1) // until we reach the separator
&& index > (System.Math.Abs(m_CurrentIncrementIndex) + separatorIndex)) // Or it's the index of the current decimal being edited (so as to display the last trailing zero in this case)
{
index--;
}
string finalValue = new string(valueWithMaxDecimals.ToCharArray(), 0, index + 1);
// Add leading zeros until we reach where the current order is being edited.
if(m_CurrentIncrementIndex > 0)
{
float incrementValue = Mathf.Pow(10.0f, (float)m_CurrentIncrementIndex);
if(incrementValue > currentValue)
{
float compareValue = currentValue + 1.0f; // Start at 1.0f because we know that we are going to increment by 10 or more
while (incrementValue > compareValue)
{
finalValue = finalValue.Insert(0, "0");
compareValue *= 10.0f;
}
}
}
// When selecting which decimal/order you want to edit, we show brackets around the figure to show the user.
if(m_SelectIncrementMode)
{
separatorIndex = finalValue.LastIndexOf(separator); // separator may have changed place if we added leading zeros
int bracketIndex = separatorIndex - m_CurrentIncrementIndex;
if(m_CurrentIncrementIndex >= 0) // Skip separator
bracketIndex -= 1;
finalValue = finalValue.Insert(bracketIndex, "[");
finalValue = finalValue.Insert(bracketIndex + 2, "]");
}
if(isNegative)
finalValue = finalValue.Insert(0, "-");
m_Value.GetComponent<UI.Text>().text = finalValue;
}
public override void OnValidate()
{
m_SelectIncrementMode = !m_SelectIncrementMode;
Update();
}
public override void OnIncrement()
{
if(!m_SelectIncrementMode)
{
m_DebugItem.SetValue((float)m_DebugItem.GetValue() + Mathf.Pow(10.0f, (float)m_CurrentIncrementIndex));
}
else
{
m_CurrentIncrementIndex -= 1; // * 0.1 (10^m_CurrentIncrementIndex)
m_CurrentIncrementIndex = System.Math.Max(-5, m_CurrentIncrementIndex);
}
Update();
}
public override void OnDecrement()
{
if (!m_SelectIncrementMode)
{
m_DebugItem.SetValue((float)m_DebugItem.GetValue() - Mathf.Pow(10.0f, (float)m_CurrentIncrementIndex));
}
else
{
m_CurrentIncrementIndex += 1; // * 10 (10^m_CurrentIncrementIndex)
}
Update();
}
}
// Everything is done with int. We don't really care about values > 2b for debugging.
public class DebugIntegerItemUI : DebugSimpleItemUI
{
bool m_SelectIncrementMode = false;
int m_CurrentIncrementIndex = 0;
public DebugIntegerItemUI(GameObject parent, DebugItem debugItem, string name)
: base(parent, debugItem, name)
{
}
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 Update()
{
UpdateText(GetIntegerValue());
}
public override void OnValidate()
{
m_SelectIncrementMode = !m_SelectIncrementMode;
Update();
}
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);
}
Update();
}
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);
}
Update();
}
}
public class DebugIntItemUI : DebugIntegerItemUI
{
public DebugIntItemUI(GameObject parent, DebugItem debugItem, string name)
: base(parent, debugItem, name)
{
UpdateText((int)m_DebugItem.GetValue());
}
protected override int GetIntegerValue()
{
return (int)m_DebugItem.GetValue();
}
protected override void SetIntegerValue(int value)
{
m_DebugItem.SetValue(value);
}
}
public class DebugUIntItemUI : DebugIntegerItemUI
{
public DebugUIntItemUI(GameObject parent, DebugItem debugItem, string name)
: base(parent, debugItem, name)
{
UpdateText((int)(uint)m_DebugItem.GetValue());
}
protected override int GetIntegerValue()
{
return (int)(uint)m_DebugItem.GetValue();
}
protected override void SetIntegerValue(int value)
{
m_DebugItem.SetValue((uint)System.Math.Max(0, value));
}
}
public class DebugEnumItemUI : DebugSimpleItemUI
{
int m_CurrentValueIndex = 0;
GUIContent[] m_ValueNames;
int[] m_Values;
public DebugEnumItemUI(GameObject parent, DebugItem debugItem, string name, GUIContent[] valueNames, int[] values)
: base(parent, debugItem, name)
{
m_Values = values;
m_ValueNames = valueNames;
m_CurrentValueIndex = FindIndexForValue((int)m_DebugItem.GetValue());
Update();
}
private int FindIndexForValue(int value)
{
for(int i = 0 ; i < m_Values.Length ; ++i)
{
if (m_Values[i] == value)
return i;
}
return -1;
}
public override void Update()
{
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.Length;
m_DebugItem.SetValue(m_Values[m_CurrentValueIndex]);
Update();
}
public override void OnDecrement()
{
m_CurrentValueIndex -= 1;
if (m_CurrentValueIndex < 0)
m_CurrentValueIndex = m_Values.Length - 1;
m_DebugItem.SetValue(m_Values[m_CurrentValueIndex]);
Update();
}
}
public class DebugColorItemUI : DebugItemUI
{
protected GameObject m_Name = null;
protected GameObject m_ColorRect = null;
public DebugColorItemUI(GameObject parent, DebugItem debugItem, string name)
: base(debugItem)
{
m_DebugItem = debugItem;
m_Root = DebugMenuUI.CreateHorizontalLayoutGroup(name, true, true, false, false, parent);
m_Name = DebugMenuUI.CreateTextElement(m_DebugItem.name, name, 10, TextAnchor.MiddleLeft, m_Root);
var layoutElemName = m_Name.AddComponent<UI.LayoutElement>();
layoutElemName.minWidth = DebugMenuUI.kDebugItemNameWidth;
// Force layout because we need the right height for the color rect element afterward.
UI.LayoutRebuilder.ForceRebuildLayoutImmediate(m_Root.GetComponent<RectTransform>());
RectTransform nameRect = m_Name.GetComponent<RectTransform>();
m_ColorRect = new GameObject();
m_ColorRect.transform.SetParent(m_Root.transform, false);
m_ColorRect.AddComponent<UI.Image>();
UI.LayoutElement layoutElem = m_ColorRect.AddComponent<UI.LayoutElement>();
// We need to set min width/height because without an image, the size would be zero.
layoutElem.minHeight = nameRect.rect.height;
layoutElem.minWidth = 40.0f;
Update();
}
public override void Update()
{
Color currentValue = (Color)m_DebugItem.GetValue();
UI.Image image = m_ColorRect.GetComponent<UI.Image>();
image.color = currentValue;
}
public override void SetSelected(bool value)
{
m_Name.GetComponent<UI.Text>().color = value ? DebugMenuUI.kColorSelected : DebugMenuUI.kColorUnSelected;
}
// TODO: Edit mode!
public override void OnValidate()
{
}
public override void OnIncrement()
{
}
public override void OnDecrement()
{
}
}
}

281
Assets/ScriptableRenderPipeline/Core/Debugging/DebugPanel.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
namespace UnityEngine.Experimental.Rendering
{
public class DebugItem
{
public Type type { get { return m_Type; } }
public string name { get { return m_Name; } }
public DebugItemHandler handler { get { return m_Handler; } }
public bool dynamicDisplay { get { return m_DynamicDisplay; } }
public bool readOnly { get { return m_Setter == null; } }
public DebugItem(string name, Type type, Func<object> getter, Action<object> setter, bool dynamicDisplay = false, DebugItemHandler handler = null)
{
m_Type = type;
m_Setter = setter;
m_Getter = getter;
m_Name = name;
m_Handler = handler;
m_DynamicDisplay = dynamicDisplay;
}
public Type GetItemType()
{
return m_Type;
}
public void SetValue(object value, bool record = true)
{
// Setter can be null for readonly items
if(m_Setter != null)
{
m_Setter(value);
m_Handler.ClampValues(m_Getter, m_Setter);
// Update state for serialization/undo
if(record)
m_State.SetValue(m_Getter());
}
}
public object GetValue()
{
return m_Getter();
}
public void SetDebugItemState(DebugItemState 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;
DebugItemState m_State = null;
}
public class DebugPanel
{
public string name { get { return m_Name; } }
public int itemCount { get { return m_Items.Count; } }
protected string m_Name = "Unknown Debug Menu";
private GameObject m_Root = null;
private List<DebugItem> m_Items = new List<DebugItem>();
private List<DebugItemUI> m_ItemsUI = new List<DebugItemUI>();
private int m_SelectedItem = -1;
public DebugPanel(string name)
{
m_Name = name;
}
public DebugItem GetDebugItem(int index)
{
if (index >= m_Items.Count || index < 0)
return null;
return m_Items[index];
}
public DebugItem GetDebugItem(string name)
{
return m_Items.Find(x => x.name == name);
}
public DebugItem GetSelectedDebugItem()
{
if(m_SelectedItem != -1)
{
return m_Items[m_SelectedItem];
}
return null;
}
public bool HasDebugItem(DebugItem debugItem)
{
foreach(var item in m_Items)
{
if (debugItem == item)
return true;
}
return false;
}
public void RemoveDebugItem(DebugItem debugItem)
{
m_Items.Remove(debugItem);
RebuildGUI();
}
public void AddDebugItem(DebugItem debugItem)
{
m_Items.Add(debugItem);
RebuildGUI();
}
// TODO: Move this to UI classes
public GameObject BuildGUI(GameObject parent)
{
m_Root = new GameObject(string.Format("{0}", m_Name));
m_Root.transform.SetParent(parent.transform);
m_Root.transform.localPosition = Vector3.zero;
m_Root.transform.localScale = Vector3.one;
UI.VerticalLayoutGroup menuVL = m_Root.AddComponent<UI.VerticalLayoutGroup>();
menuVL.spacing = 5.0f;
menuVL.childControlWidth = true;
menuVL.childControlHeight = true;
menuVL.childForceExpandWidth = true;
menuVL.childForceExpandHeight = false;
RectTransform menuVLRectTransform = m_Root.GetComponent<RectTransform>();
menuVLRectTransform.pivot = new Vector2(0.0f, 0.0f);
menuVLRectTransform.localPosition = new Vector3(0.0f, 0.0f);
menuVLRectTransform.anchorMin = new Vector2(0.0f, 0.0f);
menuVLRectTransform.anchorMax = new Vector2(1.0f, 1.0f);
RebuildGUI();
m_Root.SetActive(false);
return m_Root;
}
private void RebuildGUI()
{
m_Root.transform.DetachChildren();
DebugMenuUI.CreateTextElement(string.Format("{0} Title", m_Name), m_Name, 14, TextAnchor.MiddleLeft, m_Root);
m_ItemsUI.Clear();
foreach (DebugItem debugItem in m_Items)
{
DebugItemHandler handler = debugItem.handler; // Should never be null, we have at least the default handler
m_ItemsUI.Add(handler.BuildGUI(m_Root));
}
}
void SetSelectedItem(int index)
{
if(m_SelectedItem != -1)
{
m_ItemsUI[m_SelectedItem].SetSelected(false);
}
m_SelectedItem = index;
m_ItemsUI[m_SelectedItem].SetSelected(true);
}
public void SetSelected(bool value)
{
m_Root.SetActive(value);
if(value)
{
if (m_SelectedItem == -1)
{
NextItem();
}
else
SetSelectedItem(m_SelectedItem);
}
}
void NextItem()
{
if(m_Items.Count != 0)
{
int newSelected = (m_SelectedItem + 1) % m_Items.Count;
SetSelectedItem(newSelected);
}
}
void PreviousItem()
{
if(m_Items.Count != 0)
{
int newSelected = m_SelectedItem - 1;
if (newSelected == -1)
newSelected = m_Items.Count - 1;
SetSelectedItem(newSelected);
}
}
public void OnMoveHorizontal(float value)
{
if(m_SelectedItem != -1 && !m_Items[m_SelectedItem].readOnly)
{
if (value > 0.0f)
m_ItemsUI[m_SelectedItem].OnIncrement();
else
m_ItemsUI[m_SelectedItem].OnDecrement();
}
}
public void OnMoveVertical(float value)
{
if (value > 0.0f)
PreviousItem();
else
NextItem();
}
public void OnValidate()
{
if (m_SelectedItem != -1 && !m_Items[m_SelectedItem].readOnly)
m_ItemsUI[m_SelectedItem].OnValidate();
}
public void AddDebugItem<ItemType>(string name, Func<object> getter, Action<object> setter, bool dynamicDisplay = false, DebugItemHandler handler = null)
{
if (handler == null)
handler = new DefaultDebugItemHandler();
DebugItem newItem = new DebugItem(name, typeof(ItemType), getter, setter, dynamicDisplay, handler);
handler.SetDebugItem(newItem);
m_Items.Add(newItem);
DebugMenuManager dmm = DebugMenuManager.instance;
DebugItemState itemState = dmm.FindDebugItemState(name, m_Name);
if(itemState == null)
{
itemState = handler.CreateDebugItemState();
itemState.Initialize(name, m_Name);
itemState.SetValue(getter());
dmm.AddDebugItemState(itemState);
}
newItem.SetDebugItemState(itemState);
}
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();
}
}
}
public class LightingDebugPanel
: DebugPanel
{
public LightingDebugPanel()
: base("Lighting")
{
}
}
}

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


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
namespace UnityEngine.Experimental.Rendering
{
public class DebugMenuItem
{
public Type type { get { return m_Type; } }
public string name { get { return m_Name; } }
public DebugItemHandler handler { get { return m_Handler; } }
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, bool dynamicDisplay = false, DebugItemHandler handler = null)
{
m_Type = type;
m_Setter = setter;
m_Getter = getter;
m_Name = name;
m_Handler = handler;
m_DynamicDisplay = dynamicDisplay;
}
public Type GetItemType()
{
return m_Type;
}
public void SetValue(object value, bool record = true)
{
// Setter can be null for readonly items
if(m_Setter != null)
{
m_Setter(value);
m_Handler.ClampValues(m_Getter, m_Setter);
// Update state for serialization/undo
if(record)
m_State.SetValue(m_Getter());
}
}
public object GetValue()
{
return m_Getter();
}
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
{
public string name { get { return m_Name; } }
public int itemCount { get { return m_Items.Count; } }
protected string m_Name = "Unknown Debug Menu";
private GameObject m_Root = null;
private List<DebugMenuItem> m_Items = new List<DebugMenuItem>();
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)
return null;
return m_Items[index];
}
public DebugMenuItem GetDebugMenuItem(string name)
{
return m_Items.Find(x => x.name == name);
}
public DebugMenuItem GetSelectedDebugMenuItem()
{
if(m_SelectedItem != -1)
{
return m_Items[m_SelectedItem];
}
return null;
}
public bool HasItem(DebugMenuItem debugItem)
{
foreach(var item in m_Items)
{
if (debugItem == item)
return true;
}
return false;
}
public void RemoveDebugItem(DebugMenuItem debugItem)
{
m_Items.Remove(debugItem);
RebuildGUI();
}
public void AddDebugItem(DebugMenuItem debugItem)
{
m_Items.Add(debugItem);
RebuildGUI();
}
// TODO: Move this to UI classes
public GameObject BuildGUI(GameObject parent)
{
m_Root = new GameObject(string.Format("{0}", m_Name));
m_Root.transform.SetParent(parent.transform);
m_Root.transform.localPosition = Vector3.zero;
m_Root.transform.localScale = Vector3.one;
UI.VerticalLayoutGroup menuVL = m_Root.AddComponent<UI.VerticalLayoutGroup>();
menuVL.spacing = 5.0f;
menuVL.childControlWidth = true;
menuVL.childControlHeight = true;
menuVL.childForceExpandWidth = true;
menuVL.childForceExpandHeight = false;
RectTransform menuVLRectTransform = m_Root.GetComponent<RectTransform>();
menuVLRectTransform.pivot = new Vector2(0.0f, 0.0f);
menuVLRectTransform.localPosition = new Vector3(0.0f, 0.0f);
menuVLRectTransform.anchorMin = new Vector2(0.0f, 0.0f);
menuVLRectTransform.anchorMax = new Vector2(1.0f, 1.0f);
RebuildGUI();
m_Root.SetActive(false);
return m_Root;
}
private void RebuildGUI()
{
m_Root.transform.DetachChildren();
DebugMenuUI.CreateTextElement(string.Format("{0} Title", m_Name), m_Name, 14, TextAnchor.MiddleLeft, m_Root);
m_ItemsUI.Clear();
foreach (DebugMenuItem menuItem in m_Items)
{
DebugItemHandler handler = menuItem.handler; // Should never be null, we have at least the default handler
m_ItemsUI.Add(handler.BuildGUI(m_Root));
}
}
void SetSelectedItem(int index)
{
if(m_SelectedItem != -1)
{
m_ItemsUI[m_SelectedItem].SetSelected(false);
}
m_SelectedItem = index;
m_ItemsUI[m_SelectedItem].SetSelected(true);
}
public void SetSelected(bool value)
{
m_Root.SetActive(value);
if(value)
{
if (m_SelectedItem == -1)
{
NextItem();
}
else
SetSelectedItem(m_SelectedItem);
}
}
int NextItemIndex(int current)
{
return (current + 1) % m_Items.Count;
}
void NextItem()
{
if(m_Items.Count != 0)
{
int newSelected = (m_SelectedItem + 1) % m_Items.Count;
SetSelectedItem(newSelected);
}
}
int PreviousItemIndex(int current)
{
int newSelected = current - 1;
if (newSelected == -1)
newSelected = m_Items.Count - 1;
return newSelected;
}
void PreviousItem()
{
if(m_Items.Count != 0)
{
int newSelected = m_SelectedItem - 1;
if (newSelected == -1)
newSelected = m_Items.Count - 1;
SetSelectedItem(newSelected);
}
}
public void OnMoveHorizontal(float value)
{
if(m_SelectedItem != -1 && !m_Items[m_SelectedItem].readOnly)
{
if (value > 0.0f)
m_ItemsUI[m_SelectedItem].OnIncrement();
else
m_ItemsUI[m_SelectedItem].OnDecrement();
}
}
public void OnMoveVertical(float value)
{
if (value > 0.0f)
PreviousItem();
else
NextItem();
}
public void OnValidate()
{
if (m_SelectedItem != -1 && !m_Items[m_SelectedItem].readOnly)
m_ItemsUI[m_SelectedItem].OnValidate();
}
public void AddDebugMenuItem<ItemType>(string name, Func<object> getter, Action<object> setter, bool dynamicDisplay = false, DebugItemHandler handler = null)
{
if (handler == null)
handler = new DefaultDebugItemHandler();
DebugMenuItem newItem = new DebugMenuItem(name, typeof(ItemType), getter, setter, dynamicDisplay, handler);
handler.SetDebugMenuItem(newItem);
m_Items.Add(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()
{
// 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();
}
}
}
public class LightingDebugMenu
: DebugMenu
{
public LightingDebugMenu()
: base("Lighting")
{
}
}
}

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


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
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;
protected DebugMenuItem m_MenuItem = null;
public bool dynamicDisplay { get { return m_MenuItem.dynamicDisplay; } }
protected DebugMenuItemUI(DebugMenuItem menuItem)
{
m_MenuItem = menuItem;
}
// Implement for selection specific beahavior (like changing color for example)
public abstract void SetSelected(bool value);
// Implement behavior when user execute the "Validate" action
public abstract void OnValidate();
// Implement behavior when user execute the "Increment" action
public abstract void OnIncrement();
// Implement behavior when user execute the "Decrement" action
public abstract void OnDecrement();
// 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();
}
public class DebugMenuSimpleItemUI : DebugMenuItemUI
{
protected GameObject m_Name = null;
protected GameObject m_Value = null;
protected DebugMenuSimpleItemUI(GameObject parent, DebugMenuItem menuItem, string name)
: base(menuItem)
{
m_Root = DebugMenuUI.CreateHorizontalLayoutGroup("", true, true, false, false, parent);
m_Name = DebugMenuUI.CreateTextElement(m_MenuItem.name, name, 10, TextAnchor.MiddleLeft, m_Root);
var layoutElem = m_Name.AddComponent<UI.LayoutElement>();
layoutElem.minWidth = DebugMenuUI.kDebugItemNameWidth;
m_Value = DebugMenuUI.CreateTextElement(string.Format("{0} value", name), "", 10, TextAnchor.MiddleLeft, m_Root);
}
public override void SetSelected(bool value)
{
m_Name.GetComponent<UI.Text>().color = value ? DebugMenuUI.kColorSelected : DebugMenuUI.kColorUnSelected;
m_Value.GetComponent<UI.Text>().color = value ? DebugMenuUI.kColorSelected : DebugMenuUI.kColorUnSelected;
}
public override void OnValidate()
{
throw new System.NotImplementedException();
}
public override void OnIncrement()
{
throw new System.NotImplementedException();
}
public override void OnDecrement()
{
throw new System.NotImplementedException();
}
public override void Update()
{
throw new System.NotImplementedException();
}
}
public class DebugMenuBoolItemUI : DebugMenuSimpleItemUI
{
public DebugMenuBoolItemUI(GameObject parent, DebugMenuItem menuItem, string name)
: base(parent, menuItem, name)
{
Update();
}
public override void Update()
{
m_Value.GetComponent<UI.Text>().text = (bool)m_MenuItem.GetValue() ? "True" : "False";
}
public override void OnValidate()
{
m_MenuItem.SetValue(!(bool)m_MenuItem.GetValue());
Update();
}
public override void OnIncrement()
{
OnValidate();
}
public override void OnDecrement()
{
OnValidate();
}
}
public class DebugMenuFloatItemUI : DebugMenuSimpleItemUI
{
bool m_SelectIncrementMode = false;
int m_CurrentIncrementIndex = -1;
public DebugMenuFloatItemUI(GameObject parent, DebugMenuItem menuItem, string name)
: base(parent, menuItem, name)
{
Update();
}
public override void Update()
{
float currentValue = (float)m_MenuItem.GetValue();
bool isNegative = currentValue < 0.0f;
// Easier to format the string without caring about the '-' sign. We add it back at the end
currentValue = Mathf.Abs(currentValue);
char separator = System.Convert.ToChar(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator);
// Start with the maximum amount of trailing zeros
string valueWithMaxDecimals = string.Format("{0:0.00000}", currentValue);
// Remove trailing zeros until we reach the separator or we reach the decimal we are currently editing.
int separatorIndex = valueWithMaxDecimals.LastIndexOf(separator);
int index = valueWithMaxDecimals.Length - 1;
while (
valueWithMaxDecimals[index] == '0' // Remove trailing zeros
&& index > (separatorIndex + 1) // until we reach the separator
&& index > (System.Math.Abs(m_CurrentIncrementIndex) + separatorIndex)) // Or it's the index of the current decimal being edited (so as to display the last trailing zero in this case)
{
index--;
}
string finalValue = new string(valueWithMaxDecimals.ToCharArray(), 0, index + 1);
// Add leading zeros until we reach where the current order is being edited.
if(m_CurrentIncrementIndex > 0)
{
float incrementValue = Mathf.Pow(10.0f, (float)m_CurrentIncrementIndex);
if(incrementValue > currentValue)
{
float compareValue = currentValue + 1.0f; // Start at 1.0f because we know that we are going to increment by 10 or more
while (incrementValue > compareValue)
{
finalValue = finalValue.Insert(0, "0");
compareValue *= 10.0f;
}
}
}
// When selecting which decimal/order you want to edit, we show brackets around the figure to show the user.
if(m_SelectIncrementMode)
{
separatorIndex = finalValue.LastIndexOf(separator); // separator may have changed place if we added leading zeros
int bracketIndex = separatorIndex - m_CurrentIncrementIndex;
if(m_CurrentIncrementIndex >= 0) // Skip separator
bracketIndex -= 1;
finalValue = finalValue.Insert(bracketIndex, "[");
finalValue = finalValue.Insert(bracketIndex + 2, "]");
}
if(isNegative)
finalValue = finalValue.Insert(0, "-");
m_Value.GetComponent<UI.Text>().text = finalValue;
}
public override void OnValidate()
{
m_SelectIncrementMode = !m_SelectIncrementMode;
Update();
}
public override void OnIncrement()
{
if(!m_SelectIncrementMode)
{
m_MenuItem.SetValue((float)m_MenuItem.GetValue() + Mathf.Pow(10.0f, (float)m_CurrentIncrementIndex));
}
else
{
m_CurrentIncrementIndex -= 1; // * 0.1 (10^m_CurrentIncrementIndex)
m_CurrentIncrementIndex = System.Math.Max(-5, m_CurrentIncrementIndex);
}
Update();
}
public override void OnDecrement()
{
if (!m_SelectIncrementMode)
{
m_MenuItem.SetValue((float)m_MenuItem.GetValue() - Mathf.Pow(10.0f, (float)m_CurrentIncrementIndex));
}
else
{
m_CurrentIncrementIndex += 1; // * 10 (10^m_CurrentIncrementIndex)
}
Update();
}
}
// 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, string name)
: base(parent, menuItem, name)
{
}
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 Update()
{
UpdateText(GetIntegerValue());
}
public override void OnValidate()
{
m_SelectIncrementMode = !m_SelectIncrementMode;
Update();
}
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);
}
Update();
}
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);
}
Update();
}
}
public class DebugMenuIntItemUI : DebugMenuIntegerItemUI
{
public DebugMenuIntItemUI(GameObject parent, DebugMenuItem menuItem, string name)
: base(parent, menuItem, name)
{
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, string name)
: base(parent, menuItem, name)
{
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));
}
}
public class DebugMenuEnumItemUI : DebugMenuSimpleItemUI
{
int m_CurrentValueIndex = 0;
GUIContent[] m_ValueNames;
int[] m_Values;
public DebugMenuEnumItemUI(GameObject parent, DebugMenuItem menuItem, string name, GUIContent[] valueNames, int[] values)
: base(parent, menuItem, name)
{
m_Values = values;
m_ValueNames = valueNames;
m_CurrentValueIndex = FindIndexForValue((int)m_MenuItem.GetValue());
Update();
}
private int FindIndexForValue(int value)
{
for(int i = 0 ; i < m_Values.Length ; ++i)
{
if (m_Values[i] == value)
return i;
}
return -1;
}
public override void Update()
{
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.Length;
m_MenuItem.SetValue(m_Values[m_CurrentValueIndex]);
Update();
}
public override void OnDecrement()
{
m_CurrentValueIndex -= 1;
if (m_CurrentValueIndex < 0)
m_CurrentValueIndex = m_Values.Length - 1;
m_MenuItem.SetValue(m_Values[m_CurrentValueIndex]);
Update();
}
}
public class DebugMenuColorItemUI : DebugMenuItemUI
{
protected GameObject m_Name = null;
protected GameObject m_ColorRect = null;
public DebugMenuColorItemUI(GameObject parent, DebugMenuItem menuItem, string name)
: base(menuItem)
{
m_MenuItem = menuItem;
m_Root = DebugMenuUI.CreateHorizontalLayoutGroup(name, true, true, false, false, parent);
m_Name = DebugMenuUI.CreateTextElement(m_MenuItem.name, name, 10, TextAnchor.MiddleLeft, m_Root);
var layoutElemName = m_Name.AddComponent<UI.LayoutElement>();
layoutElemName.minWidth = DebugMenuUI.kDebugItemNameWidth;
// Force layout because we need the right height for the color rect element afterward.
UI.LayoutRebuilder.ForceRebuildLayoutImmediate(m_Root.GetComponent<RectTransform>());
RectTransform nameRect = m_Name.GetComponent<RectTransform>();
m_ColorRect = new GameObject();
m_ColorRect.transform.SetParent(m_Root.transform, false);
m_ColorRect.AddComponent<UI.Image>();
UI.LayoutElement layoutElem = m_ColorRect.AddComponent<UI.LayoutElement>();
// We need to set min width/height because without an image, the size would be zero.
layoutElem.minHeight = nameRect.rect.height;
layoutElem.minWidth = 40.0f;
Update();
}
public override void Update()
{
Color currentValue = (Color)m_MenuItem.GetValue();
UI.Image image = m_ColorRect.GetComponent<UI.Image>();
image.color = currentValue;
}
public override void SetSelected(bool value)
{
m_Name.GetComponent<UI.Text>().color = value ? DebugMenuUI.kColorSelected : DebugMenuUI.kColorUnSelected;
}
// TODO: Edit mode!
public override void OnValidate()
{
}
public override void OnIncrement()
{
}
public override void OnDecrement()
{
}
}
}

/Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenu.cs.meta → /Assets/ScriptableRenderPipeline/Core/Debugging/DebugPanel.cs.meta

/Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuItemUI.cs.meta → /Assets/ScriptableRenderPipeline/Core/Debugging/DebugItemUI.cs.meta

正在加载...
取消
保存