浏览代码

- Implemented first debug menu items (bool and float) in the player

- Implemented inputs for changing active menu item and modifying them.
/Branch_Batching2
Julien Ignace 7 年前
当前提交
0682d57b
共有 14 个文件被更改,包括 658 次插入148 次删除
  1. 7
      Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/HDRenderPipelineDebug.cs
  2. 8
      Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.asset
  3. 5
      Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs
  4. 68
      Assets/ScriptableRenderPipeline/common/Debugging/DebugActionManager.cs
  5. 146
      Assets/ScriptableRenderPipeline/common/Debugging/DebugMenu.cs
  6. 166
      Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuManager.cs
  7. 99
      Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuUI.cs
  8. 2
      Assets/ScriptableRenderPipeline/common/Debugging/Debugging.cs
  9. 2
      Assets/ScriptableRenderPipeline/common/Debugging/Editor/DebugMenuEditor.cs
  10. 32
      ProjectSettings/InputManager.asset
  11. 196
      Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuItemUI.cs
  12. 12
      Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuItemUI.cs.meta
  13. 51
      Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuUpdater.cs
  14. 12
      Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuUpdater.cs.meta

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


public LightingDebugSettings lightingDebugSettings = new LightingDebugSettings();
public RenderingDebugSettings renderingDebugSettings = new RenderingDebugSettings();
public void RegisterDebug()
{
DebugMenuManager.instance.AddDebugItem<LightingDebugMenu, bool>("Enable Shadows", () => lightingDebugSettings.enableShadows, (value) => lightingDebugSettings.enableShadows = (bool)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugMenu, bool>("Display Sky Reflection", () => lightingDebugSettings.displaySkyReflection, (value) => lightingDebugSettings.displaySkyReflection = (bool)value);
DebugMenuManager.instance.AddDebugItem<LightingDebugMenu, float>("Sky Reflection Mipmap", () => lightingDebugSettings.skyReflectionMipmap, (value) => lightingDebugSettings.skyReflectionMipmap = (float)value);
}
public void OnValidate()
{
lightingDebugSettings.OnValidate();

8
Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.asset


debugOverlayRatio: 0.33
displayMaterialDebug: 1
displayRenderingDebug: 1
displayLightingDebug: 0
displayLightingDebug: 1
materialDebugSettings:
debugViewMaterial: 0
lightingDebugSettings:

useDepthPrepass: 0
sssSettings:
numProfiles: 0
texturingMode: 0
transmissionFlags: 0
maxShadowDistance: 1000
maxShadowDistance: 800
directionalLightNearPlaneOffset: 5
directionalLightNearPlaneOffset: 10
m_TextureSettings:
spotCookieSize: 128
pointCookieSize: 512

5
Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.cs


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

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


private static string kEnableDebugBtn2 = "Enable Debug Button 2";
private static string kDebugPreviousBtn = "Debug Previous";
private static string kDebugNextBtn = "Debug Next";
private string[] m_RequiredInputButtons = { kEnableDebugBtn1, kEnableDebugBtn2, kDebugPreviousBtn, kDebugNextBtn };
private static string kValidateBtn = "Fire1";
private static string kDPadVertical = "D-Pad Vertical";
private static string kDPadHorizontal = "D-Pad Horizontal";
private string[] m_RequiredInputButtons = { kEnableDebugBtn1, kEnableDebugBtn2, kDebugPreviousBtn, kDebugNextBtn, kValidateBtn, kDPadVertical, kDPadHorizontal };
public enum DebugAction

NextDebugMenu,
Validate,
MoveVertical,
MoveHorizontal,
DebugActionCount
}

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;

enum DebugActionKeyType
{
Button,
Axis,
string m_PressedAxis = "";
bool m_Actiontriggered = false;
float m_ActionState = 0.0f;
public bool actionTriggered { get { return m_Actiontriggered; } }
public float actionState { get { return m_ActionState; } }
private void Trigger(int triggerCount)
private void Trigger(int triggerCount, float state)
m_Actiontriggered = true;
m_ActionState = state;
m_RunningAction = true;
m_Timer = 0.0f;

}
public void Trigger(string[] buttons)
public void TriggerWithButton(string[] buttons, float state)
Trigger(buttons.Length);
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 Trigger(KeyCode[] keys)
public void TriggerWithKey(KeyCode[] keys, float state)
Trigger(keys.Length);
m_PressedAxis = "";
Trigger(keys.Length, state);
}
private void Reset()

public void Update(DebugActionDesc desc)
{
// Always reset this so that the action can only be caught once until repeat/reset
m_Actiontriggered = false;
m_ActionState = 0.0f;
if (m_TriggerPressedUp != null)
{

{
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]);
}

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();

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);
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)

if (allButtonPressed)
{
state.Trigger(buttons);
state.TriggerWithButton(buttons, 1.0f);
// 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)
{

if (allKeyPressed)
{
state.Trigger(keys);
state.TriggerWithKey(keys, 1.0f);
break;
}
}

}
}
public bool GetAction(DebugAction action)
public float GetAction(DebugAction action)
return m_DebugActionStates[(int)action].actionTriggered;
return m_DebugActionStates[(int)action].actionState;
}
}
}

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


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
public class DebugMenuItem
{
public Type type { get { return m_Type; } }
public string name { get { return m_Name; } }
public DebugMenuItem(string name, Type type, Func<object> getter, Action<object> setter)
{
m_Type = type;
m_Setter = setter;
m_Getter = getter;
m_Name = name;
}
public Type GetItemType()
{
return m_Type;
}
public void SetValue(object value)
{
m_Setter(value);
}
public object GetValue()
{
return m_Getter();
}
Func<object> m_Getter;
Action<object> m_Setter;
Type m_Type;
string m_Name;
}
public class DebugMenu
{
public string name { get { return m_Name; } }

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;
// TODO: Move this to UI classes
public GameObject BuildGUI(GameObject parent)
{
m_Root = new GameObject(string.Format("{0}", m_Name));

//UI.LayoutElement layoutElement = m_Root.AddComponent<UI.LayoutElement>();
//layoutElement.ignoreLayout = true;
UI.VerticalLayoutGroup menuVL = m_Root.AddComponent<UI.VerticalLayoutGroup>();
menuVL.spacing = 5.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);
//menuVLRectTransform.anchoredPosition = new Vector2(kBorderSize, kBorderSize);
//menuVLRectTransform.sizeDelta = new Vector2(-(kBorderSize * 2.0f), -(kBorderSize * 2.0f));
//RectTransform rectTransform = m_Root.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);
DebugMenuUI.CreateTextDebugElement(string.Format("{0} Title", m_Name), m_Name, 14, TextAnchor.MiddleLeft, m_Root);
DebugMenuUI.CreateTextDebugElement(string.Format("{0} Title", m_Name), m_Name, 14, TextAnchor.MiddleLeft, m_Root);
for (int i = 0; i < 12; ++i )
m_ItemsUI.Clear();
foreach(DebugMenuItem menuItem in m_Items)
DebugMenuUI.CreateTextDebugElement(string.Format("{0} Blabla", i), string.Format("{0} Blabla", i), 10, TextAnchor.MiddleLeft, m_Root);
DebugMenuItemUI newItemUI = null;
if(menuItem.GetItemType() == typeof(bool))
{
newItemUI = new DebugMenuBoolItemUI(m_Root, menuItem);
}
else if(menuItem.GetItemType() == typeof(float))
{
newItemUI = new DebugMenuFloatItemUI(m_Root, menuItem);
}
m_ItemsUI.Add(newItemUI);
}
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)
{
if(m_Items.Count != 0)
SetSelectedItem(0);
}
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)
{
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_ItemsUI[m_SelectedItem].OnValidate();
}
public void AddDebugMenuItem<ItemType>(string name, Func<object> getter, Action<object> setter)
{
DebugMenuItem newItem = new DebugMenuItem(name, typeof(ItemType), getter, setter);
m_Items.Add(newItem);
}
}

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


namespace UnityEngine.Experimental.Rendering
{
[ExecuteInEditMode]
public class DebugMenuManager : MonoBehaviour
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_DebugMenuUI = new DebugMenuUI(this);
}
// UI
GameObject m_Root = null;
GameObject[] m_MenuRoots = null;
DebugMenuUI m_DebugMenuUI = null;
public bool isEnabled { get { return m_Enabled; } }
public int activeMenuIndex { get { return m_ActiveMenuIndex; } set { m_ActiveMenuIndex = value; } }

void LookUpDebugMenuClasses()
{
// Prepare all debug menus
var types = Assembly.GetAssembly(typeof(DebugMenu)).GetTypes()
.Where(t => t.IsSubclassOf(typeof(DebugMenu)));

}
}
void OnEnable()
public void PreviousDebugMenu()
LookUpDebugMenuClasses();
}
void Update()
{
DebugActionManager.instance.Update();
if(DebugActionManager.instance.GetAction(DebugActionManager.DebugAction.EnableDebugMenu))
{
ToggleMenu();
}
if(DebugActionManager.instance.GetAction(DebugActionManager.DebugAction.PreviousDebugMenu))
{
PreviousDebugMenu();
}
if (DebugActionManager.instance.GetAction(DebugActionManager.DebugAction.NextDebugMenu))
{
NextDebugMenu();
}
}
void PreviousDebugMenu()
{
m_MenuRoots[m_ActiveMenuIndex].SetActive(false);
m_DebugMenus[m_ActiveMenuIndex].SetSelected(false);
m_MenuRoots[m_ActiveMenuIndex].SetActive(true);
m_DebugMenus[m_ActiveMenuIndex].SetSelected(true);
void NextDebugMenu()
public void NextDebugMenu()
m_MenuRoots[m_ActiveMenuIndex].SetActive(false);
m_DebugMenus[m_ActiveMenuIndex].SetSelected(false);
m_MenuRoots[m_ActiveMenuIndex].SetActive(true);
m_DebugMenus[m_ActiveMenuIndex].SetSelected(true);
void ToggleMenu()
public void ToggleMenu()
if(!m_Enabled)
{
CleanUpGUI();
}
else
{
BuildGUI();
}
m_DebugMenuUI.Toggle();
if(m_Enabled)
m_DebugMenus[m_ActiveMenuIndex].SetSelected(true);
void CleanUpGUI()
public void OnValidate()
Object.Destroy(m_Root);
m_DebugMenus[m_ActiveMenuIndex].OnValidate();
void BuildGUI()
public void OnMoveHorizontal(float value)
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);
m_DebugMenus[m_ActiveMenuIndex].OnMoveHorizontal(value);
}
RectTransform canvasRT = canvas.GetComponent<RectTransform>();
//canvasRT.localScale = Vector3.one;
float width = canvasRT.rect.width;
float height = canvasRT.rect.height;
public void OnMoveVertical(float value)
{
m_DebugMenus[m_ActiveMenuIndex].OnMoveVertical(value);
}
GameObject go = new GameObject("Background");
go.AddComponent<CanvasRenderer>();
var image = go.AddComponent<UI.Image>();
go.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(1.0f, 1.0f);
image.rectTransform.anchoredPosition = new Vector2(kBorderSize, kBorderSize);
image.rectTransform.sizeDelta = new Vector2(-(kBorderSize * 2.0f), -(kBorderSize * 2.0f));
image.color = new Color(0.5f, 0.5f, 0.5f, 0.4f);
T GetDebugMenu<T>() where T:DebugMenu
{
Type debugMenuType = typeof(T);
foreach(DebugMenu menu in m_DebugMenus)
{
if (menu is T)
return menu as T;
}
GameObject goVL = new GameObject("DebugMenu VLayout");
goVL.transform.SetParent(go.transform, false);
UI.VerticalLayoutGroup menuVL = goVL.AddComponent<UI.VerticalLayoutGroup>();
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));
menuVL.spacing = 5.0f;
menuVL.childControlWidth = true;
menuVL.childControlHeight = true;
menuVL.childForceExpandWidth = true;
menuVL.childForceExpandHeight = false;
return null;
}
DebugMenuUI.CreateTextDebugElement("DebugMenuTitle", "Debug Menu", 14, TextAnchor.MiddleCenter, goVL);
int menuCount = m_DebugMenus.Count;
m_MenuRoots = new GameObject[menuCount];
for (int i = 0; i < menuCount; ++i)
public void AddDebugItem<DebugMenuType, ItemType>(string name, Func<object> getter, Action<object> setter) where DebugMenuType : DebugMenu
{
DebugMenuType debugMenu = GetDebugMenu<DebugMenuType>();
if (debugMenu != null)
m_MenuRoots[i] = m_DebugMenus[i].BuildGUI(goVL);
//m_MenuRoots[i] = new GameObject(string.Format("{0}", m_DebugMenus[i].name));
//m_MenuRoots[i].transform.parent = m_Root.transform;
//m_MenuRoots[i].transform.localPosition = Vector3.zero;
//GameObject title = new GameObject(string.Format("{0} Title", m_DebugMenus[i].name));
//title.transform.parent = m_MenuRoots[i].transform;
//title.transform.transform.localPosition = Vector3.zero;
//UI.Text titleText = title.AddComponent<UI.Text>();
//titleText.font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;
//titleText.text = m_DebugMenus[i].name;
debugMenu.AddDebugMenuItem<ItemType>(name, getter, setter);
m_MenuRoots[activeMenuIndex].SetActive(true);
}

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


{
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 float kDebugItemNameWidth = 150.0f;
GameObject m_Root = null;
GameObject[] m_MenuRoots = null;
bool m_Enabled = false;
int m_ActiveMenuIndex = 0;
DebugMenuManager m_DebugMenuManager = null;
public DebugMenuUI(DebugMenuManager manager)
{
m_DebugMenuManager = manager;
}
public void Toggle()
{
m_Enabled = !m_Enabled;
if(!m_Enabled)
{
CleanUpGUI();
}
else
{
BuildGUI();
}
}
void CleanUpGUI()
{
Object.Destroy(m_Root);
}
void BuildGUI()
{
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);
RectTransform canvasRT = canvas.GetComponent<RectTransform>();
//canvasRT.localScale = Vector3.one;
float width = canvasRT.rect.width;
float height = canvasRT.rect.height;
GameObject go = new GameObject("Background");
go.AddComponent<CanvasRenderer>();
var image = go.AddComponent<UI.Image>();
go.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(1.0f, 1.0f);
image.rectTransform.anchoredPosition = new Vector2(kBorderSize, kBorderSize);
image.rectTransform.sizeDelta = new Vector2(-(kBorderSize * 2.0f), -(kBorderSize * 2.0f));
image.color = new Color(0.5f, 0.5f, 0.5f, 0.4f);
GameObject goVL = new GameObject("DebugMenu VLayout");
goVL.transform.SetParent(go.transform, false);
UI.VerticalLayoutGroup menuVL = goVL.AddComponent<UI.VerticalLayoutGroup>();
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));
menuVL.spacing = 5.0f;
menuVL.childControlWidth = true;
menuVL.childControlHeight = true;
menuVL.childForceExpandWidth = true;
menuVL.childForceExpandHeight = false;
DebugMenuUI.CreateTextDebugElement("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);
}
}
public static GameObject CreateTextDebugElement(string elementName, string text, int size = 14, TextAnchor alignment = TextAnchor.MiddleLeft, GameObject parent = null)
{

goText.transform.transform.localScale = Vector3.one;
UI.Text titleText = goText.AddComponent<UI.Text>();
titleText.font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;
titleText.text = text;
titleText.alignment = alignment;
titleText.fontSize = size;
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);

2
Assets/ScriptableRenderPipeline/common/Debugging/Debugging.cs


}
catch
{
Debug.LogWarning(string.Format("Required input button mapping missing: {0}.", value));
Debug.LogError(string.Format("Required input button mapping missing: {0}.", value));
inputsOk = false;
}
}

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


void OnEnable()
{
m_DebugMenu = FindObjectOfType<DebugMenuManager>();
m_DebugMenu = DebugMenuManager.instance;
}
void OnGUI()

32
ProjectSettings/InputManager.asset


type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: D-Pad 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: D-Pad 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

196
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 abstract void SetSelected(bool value);
public abstract void OnValidate();
public abstract void OnIncrement();
public abstract void OnDecrement();
}
public class DebugMenuSimpleItemUI : DebugMenuItemUI
{
protected GameObject m_Name = null;
protected GameObject m_Value = null;
protected DebugMenuSimpleItemUI(GameObject parent, DebugMenuItem menuItem)
{
m_MenuItem = menuItem;
m_Root = new GameObject();
m_Root.transform.SetParent(parent.transform, false);
UI.HorizontalLayoutGroup horizontalLayout = m_Root.AddComponent<UI.HorizontalLayoutGroup>();
horizontalLayout.childControlHeight = true;
horizontalLayout.childControlWidth = true;
horizontalLayout.childForceExpandHeight = false;
horizontalLayout.childForceExpandWidth = false;
m_Name = DebugMenuUI.CreateTextDebugElement(m_MenuItem.name, m_MenuItem.name, 10, TextAnchor.MiddleLeft, m_Root);
var layoutElem = m_Name.AddComponent<UI.LayoutElement>();
layoutElem.minWidth = DebugMenuUI.kDebugItemNameWidth;
m_Value = DebugMenuUI.CreateTextDebugElement(string.Format("{0} value", m_MenuItem.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 class DebugMenuBoolItemUI : DebugMenuSimpleItemUI
{
public DebugMenuBoolItemUI(GameObject parent, DebugMenuItem menuItem)
: base(parent, menuItem)
{
UpdateText();
}
private void UpdateText()
{
m_Value.GetComponent<UI.Text>().text = (bool)m_MenuItem.GetValue() ? "True" : "False";
}
public override void OnValidate()
{
m_MenuItem.SetValue(!(bool)m_MenuItem.GetValue());
UpdateText();
}
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)
: base(parent, menuItem)
{
UpdateText();
}
private void UpdateText()
{
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;
UpdateText();
}
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);
}
UpdateText();
}
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)
}
UpdateText();
}
}
}

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:

51
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()
{
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();
}
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:
正在加载...
取消
保存