浏览代码

Correctly split UI from debug menu code.

/Branch_Batching2
Julien Ignace 8 年前
当前提交
dc01c46d
共有 8 个文件被更改,包括 374 次插入290 次删除
  1. 106
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuManager.cs
  2. 12
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuState.cs
  3. 152
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuUI.cs
  4. 16
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuUpdater.cs
  5. 163
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugPanel.cs
  6. 27
      Assets/ScriptableRenderPipeline/Core/Debugging/Editor/DebugMenuEditor.cs
  7. 176
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugPanelUI.cs
  8. 12
      Assets/ScriptableRenderPipeline/Core/Debugging/DebugPanelUI.cs.meta

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


}
}
bool m_Enabled = false;
int m_ActivePanelIndex = 0;
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; } }
public int panelCount { get { return m_DebugPanels.Count; } }
public DebugMenuUI menuUI { get { return m_DebugMenuUI; } }
LookUpDebugPanelClasses();
m_PersistentDebugPanel = new DebugPanel("Persistent");
m_PersistentDebugPanel = new DebugPanel<DebugPanelUI>("Persistent");
LookUpDebugPanelClasses();
var updater = GameObject.Find("DebugMenuUpdater");
if (updater == null)

foreach (var type in types)
{
m_DebugPanels.Add((DebugPanel)Activator.CreateInstance(type));
}
}
public void PreviousDebugPanel()
{
m_DebugPanels[m_ActivePanelIndex].SetSelected(false);
m_ActivePanelIndex = m_ActivePanelIndex - 1;
if (m_ActivePanelIndex == -1)
m_ActivePanelIndex = m_DebugPanels.Count - 1;
m_DebugPanels[m_ActivePanelIndex].SetSelected(true);
//m_DebugMenuUI.Toggle();
//m_DebugMenuUI.Toggle();
}
public void NextDebugPanel()
{
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_Enabled = !m_Enabled;
m_DebugMenuUI.BuildGUI();
m_DebugMenuUI.Toggle();
m_DebugPanels[m_ActivePanelIndex].SetSelected(m_Enabled);
}
public void OnValidate()
{
m_DebugPanels[m_ActivePanelIndex].OnValidate();
}
public void OnMakePersistent()
{
DebugItem selectedItem = m_DebugPanels[m_ActivePanelIndex].GetSelectedDebugItem();
if(selectedItem != null && selectedItem.readOnly)
{
if(m_PersistentDebugPanel.HasDebugItem(selectedItem))
{
m_PersistentDebugPanel.RemoveDebugItem(selectedItem);
}
else
{
m_PersistentDebugPanel.AddDebugItem(selectedItem);
}
}
if(m_PersistentDebugPanel.itemCount == 0)
{
m_PersistentDebugPanel.SetSelected(false);
m_DebugMenuUI.EnablePersistentView(false); // Temp, should just need the above. Wait for background UI to be moved to menu itself
}
else
{
m_PersistentDebugPanel.SetSelected(true);
m_DebugMenuUI.EnablePersistentView(true);
if(!type.IsGenericTypeDefinition)
AddDebugPanel((DebugPanel)Activator.CreateInstance(type));
public void OnMoveHorizontal(float value)
{
m_DebugPanels[m_ActivePanelIndex].OnMoveHorizontal(value);
}
public void OnMoveVertical(float value)
{
m_DebugPanels[m_ActivePanelIndex].OnMoveVertical(value);
}
T GetDebugPanel<T>() where T:DebugPanel
{
foreach(DebugPanel menu in m_DebugPanels)

public void Update()
{
if (m_ActivePanelIndex != -1)
m_DebugPanels[m_ActivePanelIndex].Update();
m_PersistentDebugPanel.Update();
m_DebugMenuUI.Update();
m_DebugMenuState.UpdateAllItems();
m_DebugMenuState.UpdateAllDebugItems();
}
private void AddDebugPanel(DebugPanel panel)
{
m_DebugPanels.Add(panel);
}
public void AddDebugItem<DebugPanelType, DebugItemType>(string name, Func<object> getter, Action<object> setter = null, bool dynamicDisplay = false, DebugItemHandler handler = null) where DebugPanelType : DebugPanel

// 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(debugPanel == null)
{
debugPanel = new DebugPanel(debugPanelName);
m_DebugPanels.Add(debugPanel);
debugPanel = new DebugPanel<DebugPanelUI>(debugPanelName);
AddDebugPanel(debugPanel);
}
if (debugPanel != null)

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


public string panelName = "";
public string itemName = "";
public abstract void UpdateValue();
public abstract void UpdateDebugItemValue();
public abstract void SetValue(object value);
public void Initialize(string itemName, string panelName)

this.value = (T)value;
}
public override void UpdateValue()
public override void UpdateDebugItemValue()
{
DebugMenuManager dmm = DebugMenuManager.instance;
DebugPanel menu = dmm.GetDebugPanel(panelName);

void OnUndoRedoPerformed()
{
// Maybe check a hash or something? So that we don't do that at each redo...
UpdateAllItems();
UpdateAllDebugItems();
UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
}
#endif

// Remove all objects that may have been removed from the debug menu.
// Remove all objects that may have been removed from the debug menu since last serialization
DebugMenuManager dmm = DebugMenuManager.instance;
List<DebugItemState> tempList = new List<DebugItemState>();
foreach(var itemState in m_ItemStateList)

return m_ItemStateList.Find(x => x.itemName == itemName && x.panelName == menuName);
}
public void UpdateAllItems()
public void UpdateAllDebugItems()
itemState.UpdateValue();
itemState.UpdateDebugItemValue();
}
}
}

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


public static Color kBackgroundColor = new Color(0.5f, 0.5f, 0.5f, 0.4f);
public static float kDebugItemNameWidth = 150.0f;
bool m_Enabled = false;
int m_ActivePanelIndex = 0;
GameObject[] m_MenuRoots = null;
GameObject m_MainPanelLayout = null;
GameObject m_PersistentPanelLayout = null;
List<DebugPanelUI> m_DebugPanelUIs = new List<DebugPanelUI>();
DebugPanelUI m_PersistentDebugPanelUI = null;
GameObject m_PersistentMenuRoot = null;
bool m_Enabled = false;
GameObject m_PersistentPanelRoot = null;
public int panelCount { get { return m_DebugPanelUIs.Count; } }
public bool isEnabled { get { return m_Enabled; } }
public int activePanelIndex { get { return m_ActivePanelIndex; } set { m_ActivePanelIndex = value; } }
public void Toggle()
public void EnablePersistentView(bool value)
{
m_PersistentPanelRoot.SetActive(value);
}
public void PreviousDebugPanel()
{
m_DebugPanelUIs[m_ActivePanelIndex].SetSelected(false);
m_ActivePanelIndex = m_ActivePanelIndex - 1;
if (m_ActivePanelIndex == -1)
m_ActivePanelIndex = m_DebugPanelUIs.Count - 1;
m_DebugPanelUIs[m_ActivePanelIndex].SetSelected(true);
// HACK: for some reason, the layout of the selected menu may fail if the previous menu in the list is disabled
// Disabling and re-enabling everything seems to fix the issue...
m_MainMenuRoot.SetActive(false);
m_MainMenuRoot.SetActive(true);
}
public void NextDebugPanel()
{
m_DebugPanelUIs[m_ActivePanelIndex].SetSelected(false);
m_ActivePanelIndex = (m_ActivePanelIndex + 1) % m_DebugPanelUIs.Count;
m_DebugPanelUIs[m_ActivePanelIndex].SetSelected(true);
// HACK: for some reason, the layout of the selected menu may fail if the previous menu in the list is disabled
// Disabling and re-enabling everything seems to fix the issue...
m_MainMenuRoot.SetActive(false);
m_MainMenuRoot.SetActive(true);
}
public void ToggleMenu()
m_MainMenuRoot.SetActive(m_Enabled);
if(m_Enabled)
{
BuildGUI();
m_MainMenuRoot.SetActive(true);
m_DebugPanelUIs[m_ActivePanelIndex].SetSelected(m_Enabled);
}
else
{
m_MainMenuRoot.SetActive(false);
}
public void EnablePersistentView(bool value)
public void OnValidate()
m_PersistentMenuRoot.SetActive(value);
m_DebugPanelUIs[m_ActivePanelIndex].OnValidate();
}
public void OnMoveHorizontal(float value)
{
m_DebugPanelUIs[m_ActivePanelIndex].OnMoveHorizontal(value);
void CleanUpGUI()
public void OnMoveVertical(float value)
Object.Destroy(m_Root);
m_DebugPanelUIs[m_ActivePanelIndex].OnMoveVertical(value);
}
public void Update()
{
if(m_PersistentDebugPanelUI != null)
m_PersistentDebugPanelUI.Update();
if (!m_Enabled)
return;
if (m_ActivePanelIndex != -1)
m_DebugPanelUIs[m_ActivePanelIndex].Update();
}
public void OnMakePersistent()
{
DebugPanel persistentPanel = DebugMenuManager.instance.GetPersistentDebugPanel();
DebugItem selectedItem = m_DebugPanelUIs[m_ActivePanelIndex].GetSelectedDebugItem();
if (selectedItem != null && selectedItem.readOnly)
{
if (persistentPanel.HasDebugItem(selectedItem))
{
persistentPanel.RemoveDebugItem(selectedItem);
}
else
{
persistentPanel.AddDebugItem(selectedItem);
}
}
if (m_PersistentDebugPanelUI.itemCount == 0)
{
m_PersistentDebugPanelUI.SetSelected(false);
EnablePersistentView(false); // Temp, should just need the above. Wait for background UI to be moved to menu itself
}
else
{
m_PersistentDebugPanelUI.SetSelected(true);
EnablePersistentView(true);
}
}
public void BuildGUI()

image.rectTransform.sizeDelta = new Vector2(-(kBorderSize * 2.0f), -(kBorderSize * 2.0f));
image.color = kBackgroundColor;
GameObject goVL = DebugMenuUI.CreateVerticalLayoutGroup("DebugMenu VLayout", true, true, true, false, 5.0f, m_MainMenuRoot);
RectTransform menuVLRectTransform = goVL.GetComponent<RectTransform>();
m_MainPanelLayout = DebugMenuUI.CreateVerticalLayoutGroup("DebugMenu VLayout", true, true, true, false, 5.0f, m_MainMenuRoot);
RectTransform menuVLRectTransform = m_MainPanelLayout.GetComponent<RectTransform>();
menuVLRectTransform.pivot = new Vector2(0.0f, 0.0f);
menuVLRectTransform.localPosition = Vector3.zero;
menuVLRectTransform.localScale = Vector3.one;

menuVLRectTransform.sizeDelta = new Vector2(-(kBorderSize * 2.0f), -(kBorderSize * 2.0f));
// TODO: Move background an layout to the menu itself.
m_PersistentMenuRoot = new GameObject("Background_Persistent");
m_PersistentMenuRoot.AddComponent<CanvasRenderer>();
image = m_PersistentMenuRoot.AddComponent<UI.Image>();
m_PersistentMenuRoot.transform.SetParent(m_Root.transform, false);
m_PersistentPanelRoot = new GameObject("Background_Persistent");
m_PersistentPanelRoot.AddComponent<CanvasRenderer>();
image = m_PersistentPanelRoot.AddComponent<UI.Image>();
m_PersistentPanelRoot.transform.SetParent(m_Root.transform, false);
image.rectTransform.pivot = new Vector2(0.0f, 0.0f);
image.rectTransform.localPosition = Vector3.zero;
image.rectTransform.localScale = Vector3.one;

image.rectTransform.sizeDelta = new Vector2(-(kBorderSize * 2.0f), -(kBorderSize * 2.0f));
image.color = kBackgroundColor;
GameObject goVL2 = DebugMenuUI.CreateVerticalLayoutGroup("DebugMenu VLayout", true, true, true, false, 5.0f, m_PersistentMenuRoot);
menuVLRectTransform = goVL2.GetComponent<RectTransform>();
m_PersistentPanelLayout = DebugMenuUI.CreateVerticalLayoutGroup("DebugMenu VLayout", true, true, true, false, 5.0f, m_PersistentPanelRoot);
menuVLRectTransform = m_PersistentPanelLayout.GetComponent<RectTransform>();
menuVLRectTransform.pivot = new Vector2(0.0f, 0.0f);
menuVLRectTransform.localPosition = Vector3.zero;
menuVLRectTransform.localScale = Vector3.one;

menuVLRectTransform.sizeDelta = new Vector2(-(kBorderSize * 2.0f), -(kBorderSize * 2.0f));
m_PersistentMenuRoot.SetActive(false);
m_PersistentPanelRoot.SetActive(false);
DebugMenuUI.CreateTextElement("DebugMenuTitle", "Debug Menu", 14, TextAnchor.MiddleCenter, goVL);
DebugMenuUI.CreateTextElement("DebugMenuTitle", "Debug Menu", 14, TextAnchor.MiddleCenter, m_MainPanelLayout);
int menuCount = m_DebugMenuManager.panelCount;
m_MenuRoots = new GameObject[menuCount];
for (int i = 0; i < menuCount; ++i)
m_DebugMenuManager.GetPersistentDebugPanel().panelUI.BuildGUI(m_PersistentPanelLayout);
m_PersistentDebugPanelUI = m_DebugMenuManager.GetPersistentDebugPanel().panelUI;
m_DebugPanelUIs.Clear();
for (int i = 0; i < m_DebugMenuManager.panelCount; ++i)
m_MenuRoots[i] = m_DebugMenuManager.GetDebugPanel(i).BuildGUI(goVL);
m_DebugPanelUIs.Add(m_DebugMenuManager.GetDebugPanel(i).panelUI);
m_DebugMenuManager.GetDebugPanel(i).panelUI.BuildGUI(m_MainPanelLayout);
m_DebugPanelUIs[i].SetSelected(false);
}
m_DebugMenuManager.GetPersistentDebugPanel().BuildGUI(goVL2);
#if UNITY_EDITOR
public void OnEditorGUI()
{
m_DebugPanelUIs[m_ActivePanelIndex].OnEditorGUI();
#endif
public static GameObject CreateVerticalLayoutGroup(string name, bool controlWidth, bool controlHeight, bool forceExpandWidth, bool forceExpandHeight, GameObject parent = null )
{

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


if (DebugActionManager.instance.GetAction(DebugActionManager.DebugAction.EnableDebugMenu) != 0.0f)
{
DebugMenuManager.instance.ToggleMenu();
DebugMenuManager.instance.menuUI.ToggleMenu();
if (DebugMenuManager.instance.isEnabled)
if (DebugMenuManager.instance.menuUI.isEnabled)
DebugMenuManager.instance.PreviousDebugPanel();
DebugMenuManager.instance.menuUI.PreviousDebugPanel();
DebugMenuManager.instance.NextDebugPanel();
DebugMenuManager.instance.menuUI.NextDebugPanel();
DebugMenuManager.instance.OnValidate();
DebugMenuManager.instance.menuUI.OnValidate();
DebugMenuManager.instance.OnMakePersistent();
DebugMenuManager.instance.menuUI.OnMakePersistent();
DebugMenuManager.instance.OnMoveHorizontal(moveHorizontal);
DebugMenuManager.instance.menuUI.OnMoveHorizontal(moveHorizontal);
DebugMenuManager.instance.OnMoveVertical(moveVertical);
DebugMenuManager.instance.menuUI.OnMoveVertical(moveVertical);
}
}
}

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


string m_Name;
DebugItemHandler m_Handler = null;
bool m_DynamicDisplay = false;
DebugItemState m_State = null;
DebugItemState m_State = null;
public string name { get { return m_Name; } }
public int itemCount { get { return m_Items.Count; } }
public string name { get { return m_Name; } }
public DebugPanelUI panelUI { get { return m_DebugPanelUI; } }
public int itemCount { get { return m_Items.Count; } }
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;
protected List<DebugItem> m_Items = new List<DebugItem>();
protected DebugPanelUI m_DebugPanelUI = null;
public DebugPanel(string name)
protected DebugPanel(string name)
{
m_Name = 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)

public void RemoveDebugItem(DebugItem debugItem)
{
m_Items.Remove(debugItem);
RebuildGUI();
m_DebugPanelUI.RebuildGUI();
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();
m_DebugPanelUI.RebuildGUI();
}
public void AddDebugItem<ItemType>(string name, Func<object> getter, Action<object> setter, bool dynamicDisplay = false, DebugItemHandler handler = null)

}
newItem.SetDebugItemState(itemState);
//m_DebugPanelUI.RebuildGUI();
}
public void Update()
public class DebugPanel<DebugPanelUIClass>
: DebugPanel where DebugPanelUIClass:DebugPanelUI, new()
{
public DebugPanel(string name)
: base(name)
// 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();
}
m_DebugPanelUI = new DebugPanelUIClass();
m_DebugPanelUI.SetDebugPanel(this);
: DebugPanel
: DebugPanel<DebugPanelUI>
{
public LightingDebugPanel()
: base("Lighting")

27
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.panelCount;
int activeMenuIndex = m_DebugMenu.activePanelIndex;
DebugMenuUI debugMenuUI = m_DebugMenu.menuUI;
int debugMenuCount = debugMenuUI.panelCount;
int activePanelIndex = debugMenuUI.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.GetDebugPanel(i).name), style))
activeMenuIndex = i;
string name = m_DebugMenu.GetDebugPanel(i).name;
if (GUILayout.Toggle(i == activePanelIndex, new GUIContent(name), style))
activePanelIndex = i;
m_DebugMenu.activePanelIndex = activeMenuIndex;
debugMenuUI.activePanelIndex = activePanelIndex;
using(new EditorGUILayout.VerticalScope())
{
DebugPanel activePanel = m_DebugMenu.GetDebugPanel(m_DebugMenu.activePanelIndex);
bool needRepaint = false;
for (int i = 0; i < activePanel.itemCount; ++i)
{
DebugItem debugItem = activePanel.GetDebugItem(i);
needRepaint = needRepaint || debugItem.handler.OnEditorGUI();
}
if (needRepaint)
UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
}
debugMenuUI.OnEditorGUI();
}
}

176
Assets/ScriptableRenderPipeline/Core/Debugging/DebugPanelUI.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
namespace UnityEngine.Experimental.Rendering
{
public class DebugPanelUI
{
protected GameObject m_Root = null;
protected DebugPanel m_DebugPanel = null;
protected List<DebugItemUI> m_ItemsUI = new List<DebugItemUI>();
protected int m_SelectedItem = -1;
public int itemCount { get { return m_ItemsUI.Count; } }
public DebugPanelUI()
{
}
public void SetDebugPanel(DebugPanel panel)
{
m_DebugPanel = panel;
}
public void BuildGUI(GameObject parent)
{
m_Root = new GameObject(string.Format("{0}", m_DebugPanel.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);
DebugMenuUI.CreateTextElement(string.Format("{0} Title", m_DebugPanel.name), m_DebugPanel.name, 14, TextAnchor.MiddleLeft, m_Root);
BuildGUIImpl(m_Root);
}
public void RebuildGUI()
{
BuildGUIImpl(m_Root);
}
// Default Implementation: just build all items with provided handler.
public virtual void BuildGUIImpl(GameObject parent)
{
m_ItemsUI.Clear();
for (int i = 0; i < m_DebugPanel.itemCount; i++)
{
DebugItemHandler handler = m_DebugPanel.GetDebugItem(i).handler; // Should never be null, we have at least the default handler
m_ItemsUI.Add(handler.BuildGUI(parent));
}
}
#if UNITY_EDITOR
// Default implementation for editor UI of a debug panel. Users may override this behavior.
// This will just display all items via their specific handlers in a vertical layout.
public virtual void OnEditorGUI()
{
using (new UnityEditor.EditorGUILayout.VerticalScope())
{
bool needRepaint = false;
for (int i = 0; i < m_DebugPanel.itemCount; ++i)
{
needRepaint = needRepaint || m_DebugPanel.GetDebugItem(i).handler.OnEditorGUI();
}
if (needRepaint)
UnityEditorInternal.InternalEditorUtility.RepaintAllViews();
}
}
#endif
public DebugItem GetSelectedDebugItem()
{
if (m_SelectedItem != -1)
{
return m_DebugPanel.GetDebugItem(m_SelectedItem);
}
return null;
}
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_ItemsUI.Count != 0)
{
int newSelected = (m_SelectedItem + 1) % m_ItemsUI.Count;
SetSelectedItem(newSelected);
}
}
void PreviousItem()
{
if (m_ItemsUI.Count != 0)
{
int newSelected = m_SelectedItem - 1;
if (newSelected == -1)
newSelected = m_ItemsUI.Count - 1;
SetSelectedItem(newSelected);
}
}
public void OnMoveHorizontal(float value)
{
if (m_SelectedItem != -1 && !m_DebugPanel.GetDebugItem(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_DebugPanel.GetDebugItem(m_SelectedItem).readOnly)
m_ItemsUI[m_SelectedItem].OnValidate();
}
public void Update()
{
foreach (var itemUI in m_ItemsUI)
{
if (itemUI.dynamicDisplay)
itemUI.Update();
}
}
}
}

12
Assets/ScriptableRenderPipeline/Core/Debugging/DebugPanelUI.cs.meta


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