浏览代码
Debug Menu Framework: Base classes and GUI skeleton for both Editor and PlayMode
/Branch_Batching2
Debug Menu Framework: Base classes and GUI skeleton for both Editor and PlayMode
/Branch_Batching2
Julien Ignace
8 年前
当前提交
93921066
共有 17 个文件被更改,包括 803 次插入 和 138 次删除
-
9Assets/ScriptableRenderPipeline/common/Debugging.meta
-
243Assets/ScriptableRenderPipeline/common/Debugging/DebugActionManager.cs
-
12Assets/ScriptableRenderPipeline/common/Debugging/DebugActionManager.cs.meta
-
84Assets/ScriptableRenderPipeline/common/Debugging/DebugMenu.cs
-
12Assets/ScriptableRenderPipeline/common/Debugging/DebugMenu.cs.meta
-
173Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuManager.cs
-
12Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuManager.cs.meta
-
31Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuUI.cs
-
12Assets/ScriptableRenderPipeline/common/Debugging/DebugMenuUI.cs.meta
-
138Assets/ScriptableRenderPipeline/common/Debugging/Debugging.cs
-
9Assets/ScriptableRenderPipeline/common/Debugging/Editor.meta
-
56Assets/ScriptableRenderPipeline/common/Debugging/Editor/DebugMenuEditor.cs
-
12Assets/ScriptableRenderPipeline/common/Debugging/Editor/DebugMenuEditor.cs.meta
-
138Assets/ScriptableRenderPipeline/common/Debugging.cs
-
0/Assets/ScriptableRenderPipeline/common/Debugging/Debugging.cs.meta
|
|||
fileFormatVersion: 2 |
|||
guid: 58a02e8711d94134393b2a8ac22b96ca |
|||
folderAsset: yes |
|||
timeCreated: 1491989728 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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 string[] m_RequiredInputButtons = { kEnableDebugBtn1, kEnableDebugBtn2, kDebugPreviousBtn, kDebugNextBtn }; |
|||
|
|||
|
|||
public enum DebugAction |
|||
{ |
|||
EnableDebugMenu, |
|||
PreviousDebugMenu, |
|||
NextDebugMenu, |
|||
DebugActionCount |
|||
} |
|||
|
|||
enum DebugActionRepeatMode |
|||
{ |
|||
Never, |
|||
Delay |
|||
} |
|||
|
|||
class DebugActionDesc |
|||
{ |
|||
public List<string[]> buttonTriggerList = new List<string[]>(); |
|||
public List<KeyCode[]> keyTriggerList = new List<KeyCode[]>(); |
|||
public DebugActionRepeatMode repeatMode = DebugActionRepeatMode.Never; |
|||
public float repeatDelay = 0.0f; |
|||
} |
|||
|
|||
class DebugActionState |
|||
{ |
|||
enum DebugActionKeyType |
|||
{ |
|||
Button, |
|||
Key |
|||
} |
|||
|
|||
DebugActionKeyType m_Type; |
|||
string[] m_PressedButtons; |
|||
KeyCode[] m_PressedKeys; |
|||
bool[] m_TriggerPressedUp = null; |
|||
float m_Timer; |
|||
bool m_RunningAction = false; |
|||
bool m_Actiontriggered = false; |
|||
|
|||
public bool runningAction { get { return m_RunningAction; } } |
|||
public bool actionTriggered { get { return m_Actiontriggered; } } |
|||
public float timer{ get { return m_Timer; } } |
|||
|
|||
private void Trigger(int triggerCount) |
|||
{ |
|||
m_Actiontriggered = true; |
|||
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 Trigger(string[] buttons) |
|||
{ |
|||
m_Type = DebugActionKeyType.Button; |
|||
m_PressedButtons = buttons; |
|||
Trigger(buttons.Length); |
|||
} |
|||
|
|||
public void Trigger(KeyCode[] keys) |
|||
{ |
|||
m_Type = DebugActionKeyType.Key; |
|||
m_PressedKeys = keys; |
|||
Trigger(keys.Length); |
|||
} |
|||
|
|||
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_Actiontriggered = false; |
|||
|
|||
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 |
|||
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); |
|||
} |
|||
|
|||
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.Trigger(buttons); |
|||
break; |
|||
} |
|||
} |
|||
|
|||
// 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.Trigger(keys); |
|||
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 bool GetAction(DebugAction action) |
|||
{ |
|||
return m_DebugActionStates[(int)action].actionTriggered; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 7e580489e9758c4429e4048beba3792e |
|||
timeCreated: 1492088391 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering |
|||
{ |
|||
public class DebugMenu |
|||
{ |
|||
public string name { get { return m_Name; } } |
|||
|
|||
protected string m_Name = "Unknown Debug Menu"; |
|||
|
|||
private GameObject m_Root = null; |
|||
|
|||
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.LayoutElement layoutElement = m_Root.AddComponent<UI.LayoutElement>();
|
|||
//layoutElement.ignoreLayout = true;
|
|||
|
|||
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); |
|||
//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); |
|||
for (int i = 0; i < 12; ++i ) |
|||
{ |
|||
DebugMenuUI.CreateTextDebugElement(string.Format("{0} Blabla", i), string.Format("{0} Blabla", i), 10, TextAnchor.MiddleLeft, m_Root); |
|||
} |
|||
|
|||
m_Root.SetActive(false); |
|||
return m_Root; |
|||
} |
|||
} |
|||
|
|||
public class LightingDebugMenu |
|||
: DebugMenu |
|||
{ |
|||
public LightingDebugMenu() |
|||
{ |
|||
m_Name = "Lighting"; |
|||
} |
|||
} |
|||
|
|||
public class RenderingDebugMenu |
|||
: DebugMenu |
|||
{ |
|||
public RenderingDebugMenu() |
|||
{ |
|||
m_Name = "Rendering"; |
|||
} |
|||
} |
|||
|
|||
public class PwetteDebugMenu |
|||
: DebugMenu |
|||
{ |
|||
public PwetteDebugMenu() |
|||
{ |
|||
m_Name = "Pwette"; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 8275ad749cb4c4344ba07749bfc7d9d1 |
|||
timeCreated: 1492075547 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Linq; |
|||
using System.Reflection; |
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering |
|||
{ |
|||
[ExecuteInEditMode] |
|||
public class DebugMenuManager : MonoBehaviour |
|||
{ |
|||
bool m_Enabled = false; |
|||
int m_ActiveMenuIndex = 0; |
|||
List<DebugMenu> m_DebugMenus = new List<DebugMenu>(); |
|||
|
|||
// UI
|
|||
GameObject m_Root = null; |
|||
GameObject[] m_MenuRoots = 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; |
|||
} |
|||
|
|||
void LookUpDebugMenuClasses() |
|||
{ |
|||
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)); |
|||
} |
|||
} |
|||
|
|||
void OnEnable() |
|||
{ |
|||
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_ActiveMenuIndex = m_ActiveMenuIndex - 1; |
|||
if (m_ActiveMenuIndex == -1) |
|||
m_ActiveMenuIndex = m_DebugMenus.Count - 1; |
|||
m_MenuRoots[m_ActiveMenuIndex].SetActive(true); |
|||
} |
|||
|
|||
void NextDebugMenu() |
|||
{ |
|||
m_MenuRoots[m_ActiveMenuIndex].SetActive(false); |
|||
m_ActiveMenuIndex = (m_ActiveMenuIndex + 1) % m_DebugMenus.Count; |
|||
m_MenuRoots[m_ActiveMenuIndex].SetActive(true); |
|||
} |
|||
|
|||
void ToggleMenu() |
|||
{ |
|||
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_DebugMenus.Count; |
|||
m_MenuRoots = new GameObject[menuCount]; |
|||
for (int i = 0; i < menuCount; ++i) |
|||
{ |
|||
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;
|
|||
} |
|||
|
|||
m_MenuRoots[activeMenuIndex].SetActive(true); |
|||
} |
|||
} |
|||
|
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 0d82eeff53030774abf4d8d510717fad |
|||
timeCreated: 1491995655 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering |
|||
{ |
|||
public class DebugMenuUI |
|||
{ |
|||
|
|||
public static GameObject CreateTextDebugElement(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 titleText = goText.AddComponent<UI.Text>(); |
|||
titleText.font = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font; |
|||
titleText.text = text; |
|||
titleText.alignment = alignment; |
|||
titleText.fontSize = size; |
|||
|
|||
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; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 4e88bb221a7ceb74283e4e5f93e75092 |
|||
timeCreated: 1492603542 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 81304ee5cfbb2ff4b90df73d308d903e |
|||
folderAsset: yes |
|||
timeCreated: 1492162286 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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 = FindObjectOfType<DebugMenuManager>(); |
|||
} |
|||
|
|||
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.
|
|||
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; |
|||
} |
|||
} |
|||
|
|||
m_DebugMenu.activeMenuIndex = activeMenuIndex; |
|||
} |
|||
} |
|||
|
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 7a41f968abff8f14a93e3d1ea44e774b |
|||
timeCreated: 1492162306 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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(); |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue