浏览代码

Merge pull request #236 from Unity-Technologies/Branch_DebugMenu

Branch debugmenu
/Branch_batcher
GitHub 8 年前
当前提交
96d89b41
共有 26 个文件被更改,包括 2116 次插入140 次删除
  1. 25
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/DebugDisplay.cs
  2. 5
      Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  3. 96
      ProjectSettings/InputManager.asset
  4. 9
      Assets/ScriptableRenderPipeline/common/Debugging.meta
  5. 288
      Assets/ScriptableRenderPipeline/common/Debugging/DebugActionManager.cs
  6. 12
      Assets/ScriptableRenderPipeline/common/Debugging/DebugActionManager.cs.meta
  7. 235
      Assets/ScriptableRenderPipeline/common/Debugging/DebugItemDrawer.cs
  8. 12
      Assets/ScriptableRenderPipeline/common/Debugging/DebugItemDrawer.cs.meta
  9. 267
      Assets/ScriptableRenderPipeline/common/Debugging/DebugMenu.cs
  10. 12
      Assets/ScriptableRenderPipeline/common/Debugging/DebugMenu.cs.meta
  11. 453
      Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuItemUI.cs
  12. 12
      Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuItemUI.cs.meta
  13. 194
      Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuManager.cs
  14. 12
      Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuManager.cs.meta
  15. 178
      Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuUI.cs
  16. 12
      Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuUI.cs.meta
  17. 57
      Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuUpdater.cs
  18. 12
      Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuUpdater.cs.meta
  19. 138
      Assets/ScriptableRenderPipeline/common/Debugging/Debugging.cs
  20. 9
      Assets/ScriptableRenderPipeline/common/Debugging/Editor.meta
  21. 12
      Assets/ScriptableRenderPipeline/common/Debugging/Editor/DebugMenuEditor.cs.meta
  22. 68
      Assets/ScriptableRenderPipeline/common/Debugging/Editor/DebugMenuEditor.cs
  23. 138
      Assets/ScriptableRenderPipeline/common/Debugging.cs
  24. 0
      /Assets/ScriptableRenderPipeline/common/Debugging/Debugging.cs.meta

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


using System.Collections;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;

return debugDisplayMode != DebugDisplayMode.None;
}
public void RegisterDebug()
{
DebugMenuManager.instance.AddDebugItem<float>("Display Stats", "Frame Rate", () => 1.0f / Time.deltaTime, null, true);
DebugMenuManager.instance.AddDebugItem<float>("Display Stats", "Frame Time", () => Time.deltaTime * 1000.0f, null, true);
DebugMenuManager.instance.AddDebugItem<LightingDebugMenu, 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, LightingDebugMode>("Lighting Debug Mode", () => lightingDebugSettings.lightingDebugMode, (value) => lightingDebugSettings.lightingDebugMode = (LightingDebugMode)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugMenu, bool>("Override Smoothness", () => lightingDebugSettings.overrideSmoothness, (value) => lightingDebugSettings.overrideSmoothness = (bool)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugMenu, float>("Override Smoothness Value", () => lightingDebugSettings.overrideSmoothnessValue, (value) => lightingDebugSettings.overrideSmoothnessValue = (float)value, false, new DebugItemDrawFloatMinMax(0.0f, 1.0f));
DebugMenuManager.instance.AddDebugItem<LightingDebugMenu, Color>("Debug Lighting Albedo", () => lightingDebugSettings.debugLightingAlbedo, (value) => lightingDebugSettings.debugLightingAlbedo = (Color)value);
DebugMenuManager.instance.AddDebugItem<bool>("Lighting", "Display Sky Reflection", () => lightingDebugSettings.displaySkyReflection, (value) => lightingDebugSettings.displaySkyReflection = (bool)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugMenu, float>("Sky Reflection Mipmap", () => lightingDebugSettings.skyReflectionMipmap, (value) => lightingDebugSettings.skyReflectionMipmap = (float)value, false, new DebugItemDrawFloatMinMax(0.0f, 1.0f));
DebugMenuManager.instance.AddDebugItem<bool>("Rendering", "Display Opaque",() => renderingDebugSettings.displayOpaqueObjects, (value) => renderingDebugSettings.displayOpaqueObjects = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>("Rendering", "Display Transparency",() => renderingDebugSettings.displayTransparentObjects, (value) => renderingDebugSettings.displayTransparentObjects = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>("Rendering", "Enable Distortion",() => renderingDebugSettings.enableDistortion, (value) => renderingDebugSettings.enableDistortion = (bool)value);
DebugMenuManager.instance.AddDebugItem<bool>("Rendering", "Enable Subsurface Scattering",() => renderingDebugSettings.enableSSS, (value) => renderingDebugSettings.enableSSS = (bool)value);
}
public void OnValidate()
{

public bool enableShadows = true;
public ShadowMapDebugMode shadowDebugMode = ShadowMapDebugMode.None;
public uint shadowMapIndex = 0;
public bool overrideSmoothness = false;
public float overrideSmoothnessValue = 0.5f;
public Color debugLightingAlbedo = new Color(0.5f, 0.5f, 0.5f);

5
Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


debugDisplaySettings.OnValidate();
sssSettings.OnValidate();
}
void OnEnable()
{
debugDisplaySettings.RegisterDebug();
}
}
[Serializable]

96
ProjectSettings/InputManager.asset


type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Debug Horizontal
descriptiveName:
descriptiveNegativeName:
negativeButton: left
positiveButton: right
altNegativeButton:
altPositiveButton:
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 2
axis: 5
joyNum: 0
- serializedVersion: 3
m_Name: Debug Vertical
descriptiveName:
descriptiveNegativeName:
negativeButton: down
positiveButton: up
altNegativeButton:
altPositiveButton:
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 2
axis: 6
joyNum: 0
- serializedVersion: 3
m_Name: Debug Horizontal
descriptiveName:
descriptiveNegativeName:
negativeButton: left
positiveButton: right
altNegativeButton:
altPositiveButton:
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 6
joyNum: 0
- serializedVersion: 3
m_Name: Debug Vertical
descriptiveName:
descriptiveNegativeName:
negativeButton: down
positiveButton: up
altNegativeButton:
altPositiveButton:
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 6
joyNum: 0
- serializedVersion: 3
m_Name: Debug Validate
descriptiveName:
descriptiveNegativeName:
negativeButton: return
positiveButton:
altNegativeButton: joystick button 0
altPositiveButton:
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 6
joyNum: 0
- serializedVersion: 3
m_Name: Debug Persistent
descriptiveName:
descriptiveNegativeName:
negativeButton: right shift
positiveButton:
altNegativeButton: joystick button 2
altPositiveButton:
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 6
joyNum: 0

9
Assets/ScriptableRenderPipeline/common/Debugging.meta


fileFormatVersion: 2
guid: 58a02e8711d94134393b2a8ac22b96ca
folderAsset: yes
timeCreated: 1491989728
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

288
Assets/ScriptableRenderPipeline/common/Debugging/DebugActionManager.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UnityEngine.Experimental.Rendering
{
public class DebugActionManager
{
static private DebugActionManager s_Instance = null;
static public DebugActionManager instance
{
get
{
if (s_Instance == null)
s_Instance = new DebugActionManager();
return s_Instance;
}
}
private static string kEnableDebugBtn1 = "Enable Debug Button 1";
private static string kEnableDebugBtn2 = "Enable Debug Button 2";
private static string kDebugPreviousBtn = "Debug Previous";
private static string kDebugNextBtn = "Debug Next";
private static string kValidateBtn = "Debug Validate";
private static string kPersistentBtn = "Debug Persistent";
private static string kDPadVertical = "Debug Vertical";
private static string kDPadHorizontal = "Debug Horizontal";
private string[] m_RequiredInputButtons = { kEnableDebugBtn1, kEnableDebugBtn2, kDebugPreviousBtn, kDebugNextBtn, kValidateBtn, kPersistentBtn, kDPadVertical, kDPadHorizontal };
public enum DebugAction
{
EnableDebugMenu,
PreviousDebugMenu,
NextDebugMenu,
Validate,
Persistent,
MoveVertical,
MoveHorizontal,
DebugActionCount
}
enum DebugActionRepeatMode
{
Never,
Delay
}
class DebugActionDesc
{
public List<string[]> buttonTriggerList = new List<string[]>();
public string axisTrigger = "";
public List<KeyCode[]> keyTriggerList = new List<KeyCode[]>();
public DebugActionRepeatMode repeatMode = DebugActionRepeatMode.Never;
public float repeatDelay = 0.0f;
}
class DebugActionState
{
enum DebugActionKeyType
{
Button,
Axis,
Key
}
DebugActionKeyType m_Type;
string[] m_PressedButtons;
string m_PressedAxis = "";
KeyCode[] m_PressedKeys;
bool[] m_TriggerPressedUp = null;
float m_Timer;
bool m_RunningAction = false;
float m_ActionState = 0.0f;
public bool runningAction { get { return m_RunningAction; } }
public float actionState { get { return m_ActionState; } }
public float timer{ get { return m_Timer; } }
private void Trigger(int triggerCount, float state)
{
m_ActionState = state;
m_RunningAction = true;
m_Timer = 0.0f;
m_TriggerPressedUp = new bool[triggerCount];
for (int i = 0; i < m_TriggerPressedUp.Length; ++i)
m_TriggerPressedUp[i] = false;
}
public void TriggerWithButton(string[] buttons, float state)
{
m_Type = DebugActionKeyType.Button;
m_PressedButtons = buttons;
m_PressedAxis = "";
Trigger(buttons.Length, state);
}
public void TriggerWithAxis(string axis, float state)
{
m_Type = DebugActionKeyType.Axis;
m_PressedAxis = axis;
Trigger(1, state);
}
public void TriggerWithKey(KeyCode[] keys, float state)
{
m_Type = DebugActionKeyType.Key;
m_PressedKeys = keys;
m_PressedAxis = "";
Trigger(keys.Length, state);
}
private void Reset()
{
m_RunningAction = false;
m_Timer = 0.0f;
m_TriggerPressedUp = null;
}
public void Update(DebugActionDesc desc)
{
// Always reset this so that the action can only be caught once until repeat/reset
m_ActionState = 0.0f;
if (m_TriggerPressedUp != null)
{
m_Timer += Time.deltaTime;
for(int i = 0 ; i < m_TriggerPressedUp.Length ; ++i)
{
if (m_Type == DebugActionKeyType.Button)
m_TriggerPressedUp[i] |= Input.GetButtonUp(m_PressedButtons[i]);
else if(m_Type == DebugActionKeyType.Axis)
m_TriggerPressedUp[i] |= (Input.GetAxis(m_PressedAxis) == 0.0f);
else
m_TriggerPressedUp[i] |= Input.GetKeyUp(m_PressedKeys[i]);
}
bool allTriggerUp = true;
foreach (bool value in m_TriggerPressedUp)
allTriggerUp &= value;
if(allTriggerUp || (m_Timer > desc.repeatDelay && desc.repeatMode == DebugActionRepeatMode.Delay))
{
Reset();
}
}
}
}
bool m_Valid = false;
DebugActionDesc[] m_DebugActions = null;
DebugActionState[] m_DebugActionStates = null;
DebugActionManager()
{
m_Valid = Debugging.CheckRequiredInputButtonMapping(m_RequiredInputButtons);
m_DebugActions = new DebugActionDesc[(int)DebugAction.DebugActionCount];
m_DebugActionStates = new DebugActionState[(int)DebugAction.DebugActionCount];
DebugActionDesc enableDebugMenu = new DebugActionDesc();
enableDebugMenu.buttonTriggerList.Add(new[] { kEnableDebugBtn1, kEnableDebugBtn2 });
enableDebugMenu.keyTriggerList.Add(new[] { KeyCode.LeftControl, KeyCode.Backspace });
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 previousDebugMenu = new DebugActionDesc();
previousDebugMenu.buttonTriggerList.Add(new[] { kDebugPreviousBtn });
previousDebugMenu.repeatMode = DebugActionRepeatMode.Never;
AddAction(DebugAction.PreviousDebugMenu, previousDebugMenu);
DebugActionDesc validate = new DebugActionDesc();
validate.buttonTriggerList.Add(new[] { kValidateBtn });
validate.repeatMode = DebugActionRepeatMode.Delay;
validate.repeatDelay = 0.25f;
AddAction(DebugAction.Validate, validate);
DebugActionDesc persistent = new DebugActionDesc();
persistent.buttonTriggerList.Add(new[] { kPersistentBtn });
persistent.repeatMode = DebugActionRepeatMode.Never;
AddAction(DebugAction.Persistent, 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 } );
}
void AddAction(DebugAction action, DebugActionDesc desc)
{
int index = (int)action;
m_DebugActions[index] = desc;
m_DebugActionStates[index] = new DebugActionState();
}
void SampleAction(int actionIndex)
{
DebugActionDesc desc = m_DebugActions[actionIndex];
DebugActionState state = m_DebugActionStates[actionIndex];
//bool canSampleAction = (state.actionTriggered == false) || (desc.repeatMode == DebugActionRepeatMode.Delay && state.timer > desc.repeatDelay);
if(state.runningAction == false)
{
// Check button triggers
for (int buttonListIndex = 0; buttonListIndex < desc.buttonTriggerList.Count; ++buttonListIndex)
{
string[] buttons = desc.buttonTriggerList[buttonListIndex];
bool allButtonPressed = true;
foreach (string button in buttons)
{
allButtonPressed = allButtonPressed && Input.GetButton(button);
if (!allButtonPressed)
break;
}
if (allButtonPressed)
{
state.TriggerWithButton(buttons, 1.0f);
break;
}
}
// Check axis triggers
if(desc.axisTrigger != "")
{
float axisValue = Input.GetAxis(desc.axisTrigger);
if(axisValue != 0.0f)
{
state.TriggerWithAxis(desc.axisTrigger, axisValue);
}
}
// Check key triggers
for (int keyListIndex = 0; keyListIndex < desc.keyTriggerList.Count; ++keyListIndex)
{
KeyCode[] keys = desc.keyTriggerList[keyListIndex];
bool allKeyPressed = true;
foreach (KeyCode key in keys)
{
allKeyPressed = allKeyPressed && Input.GetKey(key);
if (!allKeyPressed)
break;
}
if (allKeyPressed)
{
state.TriggerWithKey(keys, 1.0f);
break;
}
}
}
}
void UpdateAction(int actionIndex)
{
DebugActionDesc desc = m_DebugActions[actionIndex];
DebugActionState state = m_DebugActionStates[actionIndex];
if(state.runningAction)
{
state.Update(desc);
}
}
public void Update()
{
if (!m_Valid)
return;
for(int actionIndex = 0 ; actionIndex < m_DebugActions.Length ; ++actionIndex)
{
UpdateAction(actionIndex);
SampleAction(actionIndex);
}
}
public float GetAction(DebugAction action)
{
return m_DebugActionStates[(int)action].actionState;
}
}
}

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


fileFormatVersion: 2
guid: 7e580489e9758c4429e4048beba3792e
timeCreated: 1492088391
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

235
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;
// Label for simple GUI items
GUIContent m_Label;
List<GUIContent> m_EnumStrings = null;
List<int> m_EnumValues = null;
public DebugItemDrawer()
{
}
public void SetDebugItem(DebugMenuItem item)
{
m_MenuItem = item;
m_Label = new GUIContent(m_MenuItem.name);
Type itemType = m_MenuItem.GetItemType();
if(itemType.BaseType == typeof(System.Enum))
{
Array arr = Enum.GetValues(itemType);
m_EnumStrings = new List<GUIContent>(arr.Length);
m_EnumValues = new List<int>(arr.Length);
foreach(var value in arr)
{
m_EnumStrings.Add(new GUIContent(value.ToString()));
m_EnumValues.Add((int)value);
}
}
}
public virtual void ClampValues(Func<object> getter, Action<object> setter) {}
public virtual DebugMenuItemUI BuildGUI(GameObject parent, DebugMenuItem menuItem)
{
DebugMenuItemUI newItemUI = null;
if (menuItem.GetItemType() == typeof(bool))
{
newItemUI = new DebugMenuBoolItemUI(parent, menuItem, m_Label.text);
}
else if (menuItem.GetItemType() == typeof(int))
{
newItemUI = new DebugMenuIntItemUI(parent, menuItem, m_Label.text);
}
else if (menuItem.GetItemType() == typeof(uint))
{
newItemUI = new DebugMenuUIntItemUI(parent, menuItem, m_Label.text);
}
else if (menuItem.GetItemType() == typeof(float))
{
newItemUI = new DebugMenuFloatItemUI(parent, menuItem, m_Label.text);
}
else if (menuItem.GetItemType() == typeof(Color))
{
newItemUI = new DebugMenuColorItemUI(parent, menuItem, m_Label.text);
}
else if (m_MenuItem.GetItemType().BaseType == typeof(System.Enum))
{
newItemUI = new DebugMenuEnumItemUI(parent, menuItem, m_Label.text, m_EnumStrings, m_EnumValues);
}
return newItemUI;
}
#if UNITY_EDITOR
void DrawBoolItem()
{
bool value = (bool)m_MenuItem.GetValue();
if (m_MenuItem.readOnly)
{
EditorGUILayout.LabelField(m_Label, new GUIContent(value.ToString()));
}
else
{
EditorGUI.BeginChangeCheck();
value = EditorGUILayout.Toggle(m_Label, value);
if (EditorGUI.EndChangeCheck())
{
m_MenuItem.SetValue(value);
}
}
}
void DrawIntItem()
{
int value = (int)m_MenuItem.GetValue();
if (m_MenuItem.readOnly)
{
EditorGUILayout.LabelField(m_Label, new GUIContent(value.ToString()));
}
else
{
EditorGUI.BeginChangeCheck();
value = EditorGUILayout.IntField(m_Label, value);
if (EditorGUI.EndChangeCheck())
{
m_MenuItem.SetValue(value);
}
}
}
void DrawUIntItem()
{
int value = (int)(uint)m_MenuItem.GetValue();
if (m_MenuItem.readOnly)
{
EditorGUILayout.LabelField(m_Label, new GUIContent(value.ToString()));
}
else
{
EditorGUI.BeginChangeCheck();
value = EditorGUILayout.IntField(m_Label, value);
if (EditorGUI.EndChangeCheck())
{
value = System.Math.Max(0, value);
m_MenuItem.SetValue((uint)value);
}
}
}
void DrawFloatItem()
{
float value = (float)m_MenuItem.GetValue();
if(m_MenuItem.readOnly)
{
EditorGUILayout.LabelField(m_Label, new GUIContent(value.ToString()));
}
else
{
EditorGUI.BeginChangeCheck();
value = EditorGUILayout.FloatField(m_Label, value);
if (EditorGUI.EndChangeCheck())
{
m_MenuItem.SetValue(value);
}
}
}
void DrawColorItem()
{
EditorGUI.BeginChangeCheck();
Color value = EditorGUILayout.ColorField(m_Label, (Color)m_MenuItem.GetValue());
if (EditorGUI.EndChangeCheck())
{
m_MenuItem.SetValue(value);
}
}
void DrawEnumItem()
{
EditorGUI.BeginChangeCheck();
int value = EditorGUILayout.IntPopup(m_Label, (int)m_MenuItem.GetValue(), m_EnumStrings.ToArray(), m_EnumValues.ToArray());
if (EditorGUI.EndChangeCheck())
{
m_MenuItem.SetValue(value);
}
}
public virtual void OnEditorGUI()
{
if (m_MenuItem.GetItemType() == typeof(bool))
{
DrawBoolItem();
}
else if (m_MenuItem.GetItemType() == typeof(int))
{
DrawIntItem();
}
else if(m_MenuItem.GetItemType() == typeof(uint))
{
DrawUIntItem();
}
else if (m_MenuItem.GetItemType() == typeof(float))
{
DrawFloatItem();
}
else if (m_MenuItem.GetItemType() == typeof(Color))
{
DrawColorItem();
}
else if (m_MenuItem.GetItemType().BaseType == typeof(System.Enum))
{
DrawEnumItem();
}
}
#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:

267
Assets/ScriptableRenderPipeline/common/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 DebugItemDrawer drawer { get { return m_Drawer; } }
public bool dynamicDisplay { get { return m_DynamicDisplay; } }
public bool readOnly { get { return m_Setter == null; } }
public DebugMenuItem(string name, Type type, Func<object> getter, Action<object> setter, bool dynamicDisplay = false, DebugItemDrawer drawer = null)
{
m_Type = type;
m_Setter = setter;
m_Getter = getter;
m_Name = name;
m_Drawer = drawer;
m_DynamicDisplay = dynamicDisplay;
}
public Type GetItemType()
{
return m_Type;
}
public void SetValue(object value)
{
// Setter can be null for readonly items
if(m_Setter != null)
{
m_Setter(value);
m_Drawer.ClampValues(m_Getter, m_Setter);
}
}
public object GetValue()
{
return m_Getter();
}
Func<object> m_Getter;
Action<object> m_Setter;
Type m_Type;
string m_Name;
DebugItemDrawer m_Drawer = null;
bool m_DynamicDisplay = false;
}
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 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)
{
DebugItemDrawer drawer = menuItem.drawer; // Should never be null, we have at least the default drawer
m_ItemsUI.Add(drawer.BuildGUI(m_Root, menuItem));
}
}
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, DebugItemDrawer drawer = null)
{
if (drawer == null)
drawer = new DebugItemDrawer();
DebugMenuItem newItem = new DebugMenuItem(name, typeof(ItemType), getter, setter, dynamicDisplay, drawer);
drawer.SetDebugItem(newItem);
m_Items.Add(newItem);
}
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")
{
}
}
}

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


fileFormatVersion: 2
guid: 8275ad749cb4c4344ba07749bfc7d9d1
timeCreated: 1492075547
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

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


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UnityEngine.Experimental.Rendering
{
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;
}
public abstract void SetSelected(bool value);
public abstract void OnValidate();
public abstract void OnIncrement();
public abstract void OnDecrement();
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;
List<GUIContent> m_ValueNames;
List<int> m_Values;
public DebugMenuEnumItemUI(GameObject parent, DebugMenuItem menuItem, string name, List<GUIContent> valueNames, List<int> values)
: base(parent, menuItem, name)
{
m_Values = values;
m_ValueNames = valueNames;
m_CurrentValueIndex = FindIndexForValue((int)m_MenuItem.GetValue());
Update();
}
private int FindIndexForValue(int value)
{
for(int i = 0 ; i < m_Values.Count ; ++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.Count;
m_MenuItem.SetValue(m_CurrentValueIndex);
Update();
}
public override void OnDecrement()
{
m_CurrentValueIndex -= 1;
if (m_CurrentValueIndex < 0)
m_CurrentValueIndex = m_Values.Count - 1;
m_MenuItem.SetValue(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()
{
}
}
}

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


fileFormatVersion: 2
guid: 2af8a6ada82d1994d9cfd79a8b92eebc
timeCreated: 1492702176
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

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


using System;
using System.Linq;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UnityEngine.Experimental.Rendering
{
public class DebugMenuManager
{
static private DebugMenuManager s_Instance = null;
static public DebugMenuManager instance
{
get
{
if (s_Instance == null)
{
s_Instance = new DebugMenuManager();
}
return s_Instance;
}
}
DebugMenuManager()
{
LookUpDebugMenuClasses();
m_PersistentDebugMenu = new DebugMenu("Persistent");
m_DebugMenuUI = new DebugMenuUI(this);
}
bool m_Enabled = false;
int m_ActiveMenuIndex = 0;
List<DebugMenu> m_DebugMenus = new List<DebugMenu>();
DebugMenu m_PersistentDebugMenu = null;
DebugMenuUI m_DebugMenuUI = null;
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 DebugMenu GetDebugMenu(int index)
{
if (index < m_DebugMenus.Count)
return m_DebugMenus[index];
else
return null;
}
public DebugMenu GetPersistentDebugMenu()
{
return m_PersistentDebugMenu;
}
void LookUpDebugMenuClasses()
{
// Prepare all debug menus
var types = Assembly.GetAssembly(typeof(DebugMenu)).GetTypes()
.Where(t => t.IsSubclassOf(typeof(DebugMenu)));
m_DebugMenus.Clear();
foreach (var type in types)
{
m_DebugMenus.Add((DebugMenu)Activator.CreateInstance(type));
}
}
public void PreviousDebugMenu()
{
m_DebugMenus[m_ActiveMenuIndex].SetSelected(false);
m_ActiveMenuIndex = m_ActiveMenuIndex - 1;
if (m_ActiveMenuIndex == -1)
m_ActiveMenuIndex = m_DebugMenus.Count - 1;
m_DebugMenus[m_ActiveMenuIndex].SetSelected(true);
}
public void NextDebugMenu()
{
m_DebugMenus[m_ActiveMenuIndex].SetSelected(false);
m_ActiveMenuIndex = (m_ActiveMenuIndex + 1) % m_DebugMenus.Count;
m_DebugMenus[m_ActiveMenuIndex].SetSelected(true);
}
public void ToggleMenu()
{
m_Enabled = !m_Enabled;
m_DebugMenuUI.BuildGUI();
m_DebugMenuUI.Toggle();
m_DebugMenus[m_ActiveMenuIndex].SetSelected(m_Enabled);
}
public void OnValidate()
{
m_DebugMenus[m_ActiveMenuIndex].OnValidate();
}
public void OnMakePersistent()
{
DebugMenuItem selectedItem = m_DebugMenus[m_ActiveMenuIndex].GetSelectedDebugMenuItem();
if(selectedItem != null && selectedItem.readOnly)
{
if(m_PersistentDebugMenu.HasItem(selectedItem))
{
m_PersistentDebugMenu.RemoveDebugItem(selectedItem);
}
else
{
m_PersistentDebugMenu.AddDebugItem(selectedItem);
}
}
if(m_PersistentDebugMenu.itemCount == 0)
{
m_PersistentDebugMenu.SetSelected(false);
m_DebugMenuUI.EnablePersistentView(false); // Temp, should just need the above. Wait for background UI to be moved to menu itself
}
else
{
m_PersistentDebugMenu.SetSelected(true);
m_DebugMenuUI.EnablePersistentView(true);
}
}
public void OnMoveHorizontal(float value)
{
m_DebugMenus[m_ActiveMenuIndex].OnMoveHorizontal(value);
}
public void OnMoveVertical(float value)
{
m_DebugMenus[m_ActiveMenuIndex].OnMoveVertical(value);
}
T GetDebugMenu<T>() where T:DebugMenu
{
foreach(DebugMenu menu in m_DebugMenus)
{
if (menu is T)
return menu as T;
}
return null;
}
DebugMenu GetDebugMenu(string name)
{
foreach(DebugMenu menu in m_DebugMenus)
{
if (menu.name == name)
return menu;
}
return null;
}
public void Update()
{
if (m_ActiveMenuIndex != -1)
m_DebugMenus[m_ActiveMenuIndex].Update();
m_PersistentDebugMenu.Update();
}
public void AddDebugItem<DebugMenuType, ItemType>(string name, Func<object> getter, Action<object> setter = null, bool dynamicDisplay = false, DebugItemDrawer drawer = null) where DebugMenuType : DebugMenu
{
DebugMenuType debugMenu = GetDebugMenu<DebugMenuType>();
if (debugMenu != null)
{
debugMenu.AddDebugMenuItem<ItemType>(name, getter, setter, dynamicDisplay, drawer);
}
}
public void AddDebugItem<ItemType>(string debugMenuName, string name, Func<object> getter, Action<object> setter = null, bool dynamicDisplay = false, DebugItemDrawer drawer = null)
{
DebugMenu debugMenu = GetDebugMenu(debugMenuName);
// If the menu does not exist, create a generic one. This way, users don't have to explicitely create a new DebugMenu class if they don't need any particular overriding of default behavior.
if(debugMenu == null)
{
debugMenu = new DebugMenu(debugMenuName);
m_DebugMenus.Add(debugMenu);
}
if (debugMenu != null)
{
debugMenu.AddDebugMenuItem<ItemType>(name, getter, setter, dynamicDisplay, drawer);
}
}
}
}

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


fileFormatVersion: 2
guid: 0d82eeff53030774abf4d8d510717fad
timeCreated: 1491995655
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

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


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UnityEngine.Experimental.Rendering
{
public class DebugMenuUI
{
public static Color kColorSelected = new Color(1.0f, 1.0f, 1.0f, 1.0f);
public static Color kColorUnSelected = new Color(0.25f, 0.25f, 0.25f, 1.0f);
public static Color kBackgroundColor = new Color(0.5f, 0.5f, 0.5f, 0.4f);
public static float kDebugItemNameWidth = 150.0f;
GameObject m_Root = null;
GameObject[] m_MenuRoots = null;
GameObject m_MainMenuRoot = null;
GameObject m_PersistentMenuRoot = null;
bool m_Enabled = false;
DebugMenuManager m_DebugMenuManager = null;
public DebugMenuUI(DebugMenuManager manager)
{
m_DebugMenuManager = manager;
}
public void Toggle()
{
m_Enabled = !m_Enabled;
m_MainMenuRoot.SetActive(m_Enabled);
}
public void EnablePersistentView(bool value)
{
m_PersistentMenuRoot.SetActive(value);
}
void CleanUpGUI()
{
Object.Destroy(m_Root);
}
public void BuildGUI()
{
if (m_Root != null)
return;
float kBorderSize = 5.0f;
m_Root = new GameObject("DebugMenu Root");
Canvas canvas = m_Root.AddComponent<Canvas>();
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
UI.CanvasScaler canvasScaler = m_Root.AddComponent<UI.CanvasScaler>();
canvasScaler.uiScaleMode = UI.CanvasScaler.ScaleMode.ScaleWithScreenSize;
canvasScaler.referenceResolution = new Vector2(800.0f, 600.0f);
// TODO: Move background an layout to the menu itself.
m_MainMenuRoot = new GameObject("Background");
m_MainMenuRoot.AddComponent<CanvasRenderer>();
var image = m_MainMenuRoot.AddComponent<UI.Image>();
m_MainMenuRoot.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.anchorMin = new Vector2(0.0f, 0.0f);
image.rectTransform.anchorMax = new Vector2(0.5f, 1.0f);
image.rectTransform.anchoredPosition = new Vector2(kBorderSize, kBorderSize);
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>();
menuVLRectTransform.pivot = new Vector2(0.0f, 0.0f);
menuVLRectTransform.localPosition = Vector3.zero;
menuVLRectTransform.localScale = Vector3.one;
menuVLRectTransform.anchorMin = new Vector2(0.0f, 0.0f);
menuVLRectTransform.anchorMax = new Vector2(1.0f, 1.0f);
menuVLRectTransform.anchoredPosition = new Vector2(kBorderSize, kBorderSize);
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);
image.rectTransform.pivot = new Vector2(0.0f, 0.0f);
image.rectTransform.localPosition = Vector3.zero;
image.rectTransform.localScale = Vector3.one;
image.rectTransform.anchorMin = new Vector2(0.7f, 0.8f);
image.rectTransform.anchorMax = new Vector2(1.0f, 1.0f);
image.rectTransform.anchoredPosition = new Vector2(kBorderSize, kBorderSize);
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>();
menuVLRectTransform.pivot = new Vector2(0.0f, 0.0f);
menuVLRectTransform.localPosition = Vector3.zero;
menuVLRectTransform.localScale = Vector3.one;
menuVLRectTransform.anchorMin = new Vector2(0.0f, 0.0f);
menuVLRectTransform.anchorMax = new Vector2(1.0f, 1.0f);
menuVLRectTransform.anchoredPosition = new Vector2(kBorderSize, kBorderSize);
menuVLRectTransform.sizeDelta = new Vector2(-(kBorderSize * 2.0f), -(kBorderSize * 2.0f));
m_PersistentMenuRoot.SetActive(false);
DebugMenuUI.CreateTextElement("DebugMenuTitle", "Debug Menu", 14, TextAnchor.MiddleCenter, goVL);
int menuCount = m_DebugMenuManager.menuCount;
m_MenuRoots = new GameObject[menuCount];
for (int i = 0; i < menuCount; ++i)
{
m_MenuRoots[i] = m_DebugMenuManager.GetDebugMenu(i).BuildGUI(goVL);
}
m_DebugMenuManager.GetPersistentDebugMenu().BuildGUI(goVL2);
}
public static GameObject CreateVerticalLayoutGroup(string name, bool controlWidth, bool controlHeight, bool forceExpandWidth, bool forceExpandHeight, GameObject parent = null )
{
return CreateVerticalLayoutGroup(name, controlWidth, controlHeight, forceExpandWidth, forceExpandHeight, 0.0f, parent);
}
public static GameObject CreateVerticalLayoutGroup(string name, bool controlWidth, bool controlHeight, bool forceExpandWidth, bool forceExpandHeight, float spacing, GameObject parent = null )
{
GameObject go = new GameObject(name);
go.transform.SetParent(parent.transform, false);
UI.VerticalLayoutGroup verticalLayout = go.AddComponent<UI.VerticalLayoutGroup>();
verticalLayout.childControlHeight = controlHeight;
verticalLayout.childControlWidth = controlWidth;
verticalLayout.childForceExpandHeight = forceExpandHeight;
verticalLayout.childForceExpandWidth = forceExpandWidth;
verticalLayout.spacing = spacing;
return go;
}
public static GameObject CreateHorizontalLayoutGroup(string name, bool controlWidth, bool controlHeight, bool forceExpandWidth, bool forceExpandHeight, GameObject parent = null)
{
return CreateHorizontalLayoutGroup(name, controlWidth, controlHeight, forceExpandWidth, forceExpandHeight, 0.0f, parent);
}
public static GameObject CreateHorizontalLayoutGroup(string name, bool controlWidth, bool controlHeight, bool forceExpandWidth, bool forceExpandHeight, float spacing = 1.0f, GameObject parent = null)
{
GameObject go = new GameObject(name);
go.transform.SetParent(parent.transform, false);
UI.HorizontalLayoutGroup horizontalLayout = go.AddComponent<UI.HorizontalLayoutGroup>();
horizontalLayout.childControlHeight = controlHeight;
horizontalLayout.childControlWidth = controlWidth;
horizontalLayout.childForceExpandHeight = forceExpandHeight;
horizontalLayout.childForceExpandWidth = forceExpandWidth;
horizontalLayout.spacing = spacing;
return go;
}
public static GameObject CreateTextElement(string elementName, string text, int size = 14, TextAnchor alignment = TextAnchor.MiddleLeft, GameObject parent = null)
{
GameObject goText = new GameObject(elementName);
goText.transform.SetParent(parent.transform, false);
goText.transform.transform.localPosition = Vector3.zero;
goText.transform.transform.localScale = Vector3.one;
UI.Text textComponent = goText.AddComponent<UI.Text>();
textComponent.font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;
textComponent.text = text;
textComponent.alignment = alignment;
textComponent.fontSize = size;
textComponent.verticalOverflow = VerticalWrapMode.Overflow;
textComponent.color = DebugMenuUI.kColorUnSelected;
RectTransform rectTransform = goText.GetComponent<RectTransform>();
rectTransform.pivot = new Vector2(0.0f, 0.0f);
rectTransform.localPosition = new Vector3(0.0f, 0.0f);
rectTransform.anchorMin = new Vector2(0.0f, 0.0f);
rectTransform.anchorMax = new Vector2(1.0f, 1.0f);
return goText;
}
}
}

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


fileFormatVersion: 2
guid: 4e88bb221a7ceb74283e4e5f93e75092
timeCreated: 1492603542
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

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


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UnityEngine.Experimental.Rendering
{
[ExecuteInEditMode]
public class DebugMenuUpdater : MonoBehaviour
{
void Update()
{
DebugMenuManager.instance.Update();
DebugActionManager.instance.Update();
if (DebugActionManager.instance.GetAction(DebugActionManager.DebugAction.EnableDebugMenu) != 0.0f)
{
DebugMenuManager.instance.ToggleMenu();
}
if (DebugMenuManager.instance.isEnabled)
{
if (DebugActionManager.instance.GetAction(DebugActionManager.DebugAction.PreviousDebugMenu) != 0.0f)
{
DebugMenuManager.instance.PreviousDebugMenu();
}
if (DebugActionManager.instance.GetAction(DebugActionManager.DebugAction.NextDebugMenu) != 0.0f)
{
DebugMenuManager.instance.NextDebugMenu();
}
if (DebugActionManager.instance.GetAction(DebugActionManager.DebugAction.Validate) != 0.0f)
{
DebugMenuManager.instance.OnValidate();
}
if (DebugActionManager.instance.GetAction(DebugActionManager.DebugAction.Persistent) != 0.0f)
{
DebugMenuManager.instance.OnMakePersistent();
}
float moveHorizontal = DebugActionManager.instance.GetAction(DebugActionManager.DebugAction.MoveHorizontal);
if (moveHorizontal != 0.0f)
{
DebugMenuManager.instance.OnMoveHorizontal(moveHorizontal);
}
float moveVertical = DebugActionManager.instance.GetAction(DebugActionManager.DebugAction.MoveVertical);
if (moveVertical != 0.0f)
{
DebugMenuManager.instance.OnMoveVertical(moveVertical);
}
}
}
}
}

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


fileFormatVersion: 2
guid: 2dfdab1050228974ba8fbbd56e87da3e
timeCreated: 1492697894
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

138
Assets/ScriptableRenderPipeline/common/Debugging/Debugging.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UnityEngine.Experimental.Rendering
{
public class Debugging : MonoBehaviour
{
private static bool m_DebugControlEnabled = false;
public static bool debugControlEnabled { get { return m_DebugControlEnabled; } }
private float m_DebugControlEnabledMsgTime = 3.0f;
private float m_DebugControlEnabledMsgTimer = 0.0f;
private bool m_DebugKeyUp1 = false;
private bool m_DebugKeyUp2 = false;
private bool m_CanReceiveInput = true;
private static List<string> m_DebugMessages = new List<string>();
private static string kEnableDebugBtn1 = "Enable Debug Button 1";
private static string kEnableDebugBtn2 = "Enable Debug Button 2";
private string[] m_RequiredInputButtons = { kEnableDebugBtn1, kEnableDebugBtn2 };
private bool m_Valid = true;
public static void PushDebugMessage(string message)
{
m_DebugMessages.Add(message);
}
static public bool CheckRequiredInputButtonMapping(string[] values)
{
bool inputsOk = true;
foreach (string value in values)
{
try
{
Input.GetButton(value);
}
catch
{
Debug.LogError(string.Format("Required input button mapping missing: {0}.", value));
inputsOk = false;
}
}
return inputsOk;
}
static public bool CheckRequiredInputAxisMapping(string[] values)
{
bool inputsOk = true;
foreach (string value in values)
{
try
{
Input.GetAxis(value);
}
catch
{
Debug.LogWarning(string.Format("Required input axis mapping missing: {0}.", value));
inputsOk = false;
}
}
return inputsOk;
}
void OnEnable()
{
m_Valid = CheckRequiredInputButtonMapping(m_RequiredInputButtons);
}
void Update()
{
//if (m_Valid)
//{
// m_DebugControlEnabledMsgTimer += Time.deltaTime;
// bool enableDebug = Input.GetButton(kEnableDebugBtn1) && Input.GetButton(kEnableDebugBtn2) || Input.GetKey(KeyCode.LeftControl) && Input.GetKey(KeyCode.Backspace);
// if (m_CanReceiveInput && enableDebug)
// {
// m_DebugControlEnabled = !m_DebugControlEnabled;
// m_DebugControlEnabledMsgTimer = 0.0f;
// m_CanReceiveInput = false;
// m_DebugKeyUp1 = false;
// m_DebugKeyUp2 = false;
// }
// if (Input.GetButtonUp(kEnableDebugBtn1))
// {
// m_DebugKeyUp1 = true;
// }
// if (Input.GetButtonUp(kEnableDebugBtn2))
// {
// m_DebugKeyUp2 = true;
// }
// // For keyboard you want to be able to keep ctrl pressed.
// if (Input.GetKeyUp(KeyCode.Backspace))
// {
// m_DebugKeyUp1 = m_DebugKeyUp2 = true;
// }
// m_CanReceiveInput = m_DebugKeyUp1 && m_DebugKeyUp2;
// if (m_DebugControlEnabledMsgTimer < m_DebugControlEnabledMsgTime)
// {
// if (m_DebugControlEnabled)
// PushDebugMessage("Debug Controls Enabled");
// else
// PushDebugMessage("Debug Controls Disabled");
// }
//}
}
void OnGUI()
{
using (new GUILayout.HorizontalScope())
{
GUILayout.Space(10.0f);
using (new GUILayout.VerticalScope())
{
GUILayout.Space(10.0f);
for (int i = 0; i < m_DebugMessages.Count; ++i)
{
GUILayout.Label(m_DebugMessages[i]);
}
}
}
// Make sure to clear only after all relevant events have occured.
if (Event.current.type == EventType.Repaint)
m_DebugMessages.Clear();
}
}
}

9
Assets/ScriptableRenderPipeline/common/Debugging/Editor.meta


fileFormatVersion: 2
guid: 81304ee5cfbb2ff4b90df73d308d903e
folderAsset: yes
timeCreated: 1492162286
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

12
Assets/ScriptableRenderPipeline/common/Debugging/Editor/DebugMenuEditor.cs.meta


fileFormatVersion: 2
guid: 7a41f968abff8f14a93e3d1ea44e774b
timeCreated: 1492162306
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

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


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace UnityEngine.Experimental.Rendering
{
// This is the class that handles rendering the debug menu in the editor (as opposed to the runtime version in the player)
public class DebugMenuEditor : EditorWindow
{
[MenuItem("HDRenderPipeline/Debug Menu")]
static void DisplayDebugMenu()
{
var window = EditorWindow.GetWindow<DebugMenuEditor>("Debug Menu");
window.Show();
}
DebugMenuManager m_DebugMenu = null;
DebugMenuEditor()
{
}
void OnEnable()
{
m_DebugMenu = DebugMenuManager.instance;
}
void OnGUI()
{
if (m_DebugMenu == null)
return;
// 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;
using (new EditorGUILayout.HorizontalScope())
{
for(int i = 0 ; i < debugMenuCount ; ++i)
{
GUIStyle style = EditorStyles.miniButtonMid;
if (i == 0)
style = EditorStyles.miniButtonLeft;
if (i == debugMenuCount - 1)
style = EditorStyles.miniButtonRight;
if (GUILayout.Toggle(i == activeMenuIndex, new GUIContent(m_DebugMenu.GetDebugMenu(i).name), style))
activeMenuIndex = i;
}
}
if(EditorGUI.EndChangeCheck())
{
m_DebugMenu.activeMenuIndex = activeMenuIndex;
}
using(new EditorGUILayout.VerticalScope())
{
DebugMenu activeMenu = m_DebugMenu.GetDebugMenu(m_DebugMenu.activeMenuIndex);
for (int i = 0; i < activeMenu.itemCount; ++i)
{
activeMenu.GetDebugMenuItem(i).drawer.OnEditorGUI();
}
}
}
}
}

138
Assets/ScriptableRenderPipeline/common/Debugging.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UnityEngine.Experimental.Rendering
{
public class Debugging : MonoBehaviour
{
private static bool m_DebugControlEnabled = false;
public static bool debugControlEnabled { get { return m_DebugControlEnabled; } }
private float m_DebugControlEnabledMsgTime = 3.0f;
private float m_DebugControlEnabledMsgTimer = 0.0f;
private bool m_DebugKeyUp1 = false;
private bool m_DebugKeyUp2 = false;
private bool m_CanReceiveInput = true;
private static List<string> m_DebugMessages = new List<string>();
private static string kEnableDebugBtn1 = "Enable Debug Button 1";
private static string kEnableDebugBtn2 = "Enable Debug Button 2";
private string[] m_RequiredInputButtons = { kEnableDebugBtn1, kEnableDebugBtn2 };
private bool m_Valid = true;
public static void PushDebugMessage(string message)
{
m_DebugMessages.Add(message);
}
static public bool CheckRequiredInputButtonMapping(string[] values)
{
bool inputsOk = true;
foreach (string value in values)
{
try
{
Input.GetButton(value);
}
catch
{
Debug.LogWarning(string.Format("Required input button mapping missing: {0}.", value));
inputsOk = false;
}
}
return inputsOk;
}
static public bool CheckRequiredInputAxisMapping(string[] values)
{
bool inputsOk = true;
foreach (string value in values)
{
try
{
Input.GetAxis(value);
}
catch
{
Debug.LogWarning(string.Format("Required input axis mapping missing: {0}.", value));
inputsOk = false;
}
}
return inputsOk;
}
void OnEnable()
{
m_Valid = CheckRequiredInputButtonMapping(m_RequiredInputButtons);
}
void Update()
{
if (m_Valid)
{
m_DebugControlEnabledMsgTimer += Time.deltaTime;
bool enableDebug = Input.GetButton(kEnableDebugBtn1) && Input.GetButton(kEnableDebugBtn2) || Input.GetKey(KeyCode.LeftControl) && Input.GetKey(KeyCode.Backspace);
if (m_CanReceiveInput && enableDebug)
{
m_DebugControlEnabled = !m_DebugControlEnabled;
m_DebugControlEnabledMsgTimer = 0.0f;
m_CanReceiveInput = false;
m_DebugKeyUp1 = false;
m_DebugKeyUp2 = false;
}
if (Input.GetButtonUp(kEnableDebugBtn1))
{
m_DebugKeyUp1 = true;
}
if (Input.GetButtonUp(kEnableDebugBtn2))
{
m_DebugKeyUp2 = true;
}
// For keyboard you want to be able to keep ctrl pressed.
if (Input.GetKeyUp(KeyCode.Backspace))
{
m_DebugKeyUp1 = m_DebugKeyUp2 = true;
}
m_CanReceiveInput = m_DebugKeyUp1 && m_DebugKeyUp2;
if (m_DebugControlEnabledMsgTimer < m_DebugControlEnabledMsgTime)
{
if (m_DebugControlEnabled)
PushDebugMessage("Debug Controls Enabled");
else
PushDebugMessage("Debug Controls Disabled");
}
}
}
void OnGUI()
{
using (new GUILayout.HorizontalScope())
{
GUILayout.Space(10.0f);
using (new GUILayout.VerticalScope())
{
GUILayout.Space(10.0f);
for (int i = 0; i < m_DebugMessages.Count; ++i)
{
GUILayout.Label(m_DebugMessages[i]);
}
}
}
// Make sure to clear only after all relevant events have occured.
if (Event.current.type == EventType.Repaint)
m_DebugMessages.Clear();
}
}
}

/Assets/ScriptableRenderPipeline/common/Debugging.cs.meta → /Assets/ScriptableRenderPipeline/common/Debugging/Debugging.cs.meta

正在加载...
取消
保存