浏览代码
Merge pull request #272 from Unity-Technologies/Branch_DebugMenu2
Merge pull request #272 from Unity-Technologies/Branch_DebugMenu2
Debug Menu Update/RenderPassXR_Sandbox
GitHub
8 年前
当前提交
d3bd8f2f
共有 36 个文件被更改,包括 1745 次插入 和 1448 次删除
-
2Assets/ScriptableRenderPipeline/Core/Camera/CameraSwitcher.cs
-
24Assets/ScriptableRenderPipeline/Core/Debugging/DebugActionManager.cs
-
177Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuManager.cs
-
163Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuUI.cs
-
22Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuUpdater.cs
-
26Assets/ScriptableRenderPipeline/Core/Debugging/Editor/DebugMenuEditor.cs
-
26Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/DebugDisplay.cs
-
238Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs
-
20Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.asset
-
333Assets/ScriptableRenderPipeline/Core/Debugging/DebugItemHandler.cs
-
460Assets/ScriptableRenderPipeline/Core/Debugging/DebugItemUI.cs
-
143Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuState.cs
-
12Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuState.cs.meta
-
146Assets/ScriptableRenderPipeline/Core/Debugging/DebugPanel.cs
-
176Assets/ScriptableRenderPipeline/Core/Debugging/DebugPanelUI.cs
-
12Assets/ScriptableRenderPipeline/Core/Debugging/DebugPanelUI.cs.meta
-
9Assets/ScriptableRenderPipeline/Core/Debugging/Serialization.meta
-
70Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/LightingDebugPanel.cs
-
12Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/LightingDebugPanel.cs.meta
-
12Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateBool.cs.meta
-
12Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateColor.cs.meta
-
12Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateFloat.cs.meta
-
12Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateInt.cs.meta
-
12Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateUInt.cs.meta
-
10Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateBool.cs
-
10Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateColor.cs
-
10Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateFloat.cs
-
10Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateInt.cs
-
10Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateUInt.cs
-
267Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenu.cs
-
453Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuItemUI.cs
-
292Assets/ScriptableRenderPipeline/Core/Debugging/DebugItemDrawer.cs
-
0/Assets/ScriptableRenderPipeline/Core/Debugging/DebugPanel.cs.meta
-
0/Assets/ScriptableRenderPipeline/Core/Debugging/DebugItemUI.cs.meta
-
0/Assets/ScriptableRenderPipeline/Core/Debugging/DebugItemHandler.cs.meta
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using System; |
|||
|
|||
#if UNITY_EDITOR
|
|||
using UnityEditor; |
|||
#endif
|
|||
|
|||
namespace UnityEngine.Experimental.Rendering |
|||
{ |
|||
public abstract class DebugItemHandler |
|||
{ |
|||
protected DebugItem m_DebugItem = null; |
|||
|
|||
public void SetDebugItem(DebugItem item) |
|||
{ |
|||
m_DebugItem = item; |
|||
} |
|||
|
|||
// Method user needs to override for specific value clamping.
|
|||
public virtual void ClampValues(Func<object> getter, Action<object> setter) {} |
|||
// Method that will create UI items for runtime debug menu.
|
|||
public abstract DebugItemUI BuildGUI(GameObject parent); |
|||
// Method users need to override for editor specific UI
|
|||
public abstract bool OnEditorGUIImpl(); |
|||
public void OnEditorGUI() |
|||
{ |
|||
if(OnEditorGUIImpl()) |
|||
{ |
|||
DebugMenuUI.changed = true; |
|||
} |
|||
} |
|||
|
|||
// Method users need to override for specific serialization of custom types.
|
|||
public abstract DebugItemState CreateDebugItemState(); |
|||
} |
|||
|
|||
// This is the default debug item handler that handles all basic types.
|
|||
public class DefaultDebugItemHandler |
|||
: DebugItemHandler |
|||
{ |
|||
bool m_IsInitialized = false; |
|||
|
|||
// Label for simple GUI items
|
|||
protected GUIContent m_Label; |
|||
|
|||
// Values and strings for Enum items
|
|||
protected List<GUIContent> m_EnumStrings = null; |
|||
protected List<int> m_EnumValues = null; |
|||
|
|||
public void Initialize() |
|||
{ |
|||
if (m_IsInitialized) |
|||
return; |
|||
|
|||
m_Label = new GUIContent(m_DebugItem.name); |
|||
Type itemType = m_DebugItem.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 override DebugItemState CreateDebugItemState() |
|||
{ |
|||
DebugItemState newItemState = null; |
|||
if (m_DebugItem.GetItemType() == typeof(bool)) |
|||
{ |
|||
newItemState = ScriptableObject.CreateInstance<DebugItemStateBool>(); |
|||
} |
|||
else if (m_DebugItem.GetItemType() == typeof(int)) |
|||
{ |
|||
newItemState = ScriptableObject.CreateInstance<DebugItemStateInt>(); |
|||
} |
|||
else if (m_DebugItem.GetItemType() == typeof(uint)) |
|||
{ |
|||
newItemState = ScriptableObject.CreateInstance<DebugItemStateUInt>(); |
|||
} |
|||
else if (m_DebugItem.GetItemType() == typeof(float)) |
|||
{ |
|||
newItemState = ScriptableObject.CreateInstance<DebugItemStateFloat>(); |
|||
} |
|||
else if (m_DebugItem.GetItemType() == typeof(Color)) |
|||
{ |
|||
newItemState = ScriptableObject.CreateInstance<DebugItemStateColor>(); |
|||
} |
|||
else if (m_DebugItem.GetItemType().BaseType == typeof(System.Enum)) |
|||
{ |
|||
newItemState = ScriptableObject.CreateInstance<DebugItemStateInt>(); // Need to be serialized as int. For some reason serialization of the Enum directly just fails...
|
|||
} |
|||
|
|||
return newItemState; |
|||
} |
|||
|
|||
public override DebugItemUI BuildGUI(GameObject parent) |
|||
{ |
|||
Initialize(); |
|||
|
|||
DebugItemUI newItemUI = null; |
|||
if (m_DebugItem.GetItemType() == typeof(bool)) |
|||
{ |
|||
newItemUI = new DebugBoolItemUI(parent, m_DebugItem, m_Label.text); |
|||
} |
|||
else if (m_DebugItem.GetItemType() == typeof(int)) |
|||
{ |
|||
newItemUI = new DebugIntItemUI(parent, m_DebugItem, m_Label.text); |
|||
} |
|||
else if (m_DebugItem.GetItemType() == typeof(uint)) |
|||
{ |
|||
newItemUI = new DebugUIntItemUI(parent, m_DebugItem, m_Label.text); |
|||
} |
|||
else if (m_DebugItem.GetItemType() == typeof(float)) |
|||
{ |
|||
newItemUI = new DebugFloatItemUI(parent, m_DebugItem, m_Label.text); |
|||
} |
|||
else if (m_DebugItem.GetItemType() == typeof(Color)) |
|||
{ |
|||
newItemUI = new DebugColorItemUI(parent, m_DebugItem, m_Label.text); |
|||
} |
|||
else if (m_DebugItem.GetItemType().BaseType == typeof(System.Enum)) |
|||
{ |
|||
newItemUI = new DebugEnumItemUI(parent, m_DebugItem, m_Label.text, m_EnumStrings.ToArray(), m_EnumValues.ToArray()); |
|||
} |
|||
|
|||
return newItemUI; |
|||
} |
|||
|
|||
#if UNITY_EDITOR
|
|||
bool DrawBoolItem() |
|||
{ |
|||
bool value = (bool)m_DebugItem.GetValue(); |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
value = EditorGUILayout.Toggle(m_Label, value); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
m_DebugItem.SetValue(value); |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
bool DrawIntItem() |
|||
{ |
|||
int value = (int)m_DebugItem.GetValue(); |
|||
EditorGUI.BeginChangeCheck(); |
|||
value = EditorGUILayout.IntField(m_Label, value); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
m_DebugItem.SetValue(value); |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
bool DrawUIntItem() |
|||
{ |
|||
int value = (int)(uint)m_DebugItem.GetValue(); |
|||
EditorGUI.BeginChangeCheck(); |
|||
value = EditorGUILayout.IntField(m_Label, value); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
value = System.Math.Max(0, value); |
|||
m_DebugItem.SetValue((uint)value); |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
bool DrawFloatItem() |
|||
{ |
|||
float value = (float)m_DebugItem.GetValue(); |
|||
EditorGUI.BeginChangeCheck(); |
|||
value = EditorGUILayout.FloatField(m_Label, value); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
m_DebugItem.SetValue(value); |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
bool DrawColorItem() |
|||
{ |
|||
EditorGUI.BeginChangeCheck(); |
|||
Color value = EditorGUILayout.ColorField(m_Label, (Color)m_DebugItem.GetValue()); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
m_DebugItem.SetValue(value); |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
bool DrawEnumItem() |
|||
{ |
|||
EditorGUI.BeginChangeCheck(); |
|||
int value = EditorGUILayout.IntPopup(m_Label, (int)m_DebugItem.GetValue(), m_EnumStrings.ToArray(), m_EnumValues.ToArray()); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
m_DebugItem.SetValue(value); |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
public override bool OnEditorGUIImpl() |
|||
{ |
|||
Initialize(); |
|||
|
|||
if (m_DebugItem.readOnly) |
|||
{ |
|||
EditorGUILayout.LabelField(m_Label, new GUIContent(m_DebugItem.GetValue().ToString())); |
|||
return false; |
|||
} |
|||
|
|||
if (m_DebugItem.GetItemType() == typeof(bool)) |
|||
{ |
|||
return DrawBoolItem(); |
|||
} |
|||
else if (m_DebugItem.GetItemType() == typeof(int)) |
|||
{ |
|||
return DrawIntItem(); |
|||
} |
|||
else if(m_DebugItem.GetItemType() == typeof(uint)) |
|||
{ |
|||
return DrawUIntItem(); |
|||
} |
|||
else if (m_DebugItem.GetItemType() == typeof(float)) |
|||
{ |
|||
return DrawFloatItem(); |
|||
} |
|||
else if (m_DebugItem.GetItemType() == typeof(Color)) |
|||
{ |
|||
return DrawColorItem(); |
|||
} |
|||
else if (m_DebugItem.GetItemType().BaseType == typeof(System.Enum)) |
|||
{ |
|||
return DrawEnumItem(); |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
#endif
|
|||
} |
|||
|
|||
public class DebugItemHandlerFloatMinMax |
|||
: DefaultDebugItemHandler |
|||
{ |
|||
float m_Min = 0.0f; |
|||
float m_Max = 1.0f; |
|||
public DebugItemHandlerFloatMinMax(float min, float max) |
|||
{ |
|||
m_Min = min; |
|||
m_Max = max; |
|||
} |
|||
|
|||
public override void ClampValues(Func<object> getter, Action<object> setter) |
|||
{ |
|||
setter(Mathf.Clamp((float)getter(), m_Min, m_Max)); |
|||
} |
|||
|
|||
#if UNITY_EDITOR
|
|||
public override bool OnEditorGUIImpl() |
|||
{ |
|||
Initialize(); |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
float value = EditorGUILayout.Slider(m_DebugItem.name, (float)m_DebugItem.GetValue(), m_Min, m_Max); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
m_DebugItem.SetValue(value); |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
#endif
|
|||
} |
|||
|
|||
public class DebugItemHandlerIntEnum |
|||
: DefaultDebugItemHandler |
|||
{ |
|||
GUIContent[] m_IntEnumStrings = null; |
|||
int[] m_IntEnumValues = null; |
|||
|
|||
public DebugItemHandlerIntEnum(GUIContent[] enumStrings, int[] enumValues) |
|||
{ |
|||
m_IntEnumStrings = enumStrings; |
|||
m_IntEnumValues = enumValues; |
|||
} |
|||
|
|||
public override DebugItemUI BuildGUI(GameObject parent) |
|||
{ |
|||
Initialize(); |
|||
|
|||
return new DebugEnumItemUI(parent, m_DebugItem, m_Label.text, m_IntEnumStrings, m_IntEnumValues); |
|||
} |
|||
|
|||
#if UNITY_EDITOR
|
|||
public override bool OnEditorGUIImpl() |
|||
{ |
|||
Initialize(); |
|||
|
|||
UnityEditor.EditorGUI.BeginChangeCheck(); |
|||
int value = UnityEditor.EditorGUILayout.IntPopup(m_Label, (int)m_DebugItem.GetValue(), m_IntEnumStrings, m_IntEnumValues); |
|||
if (UnityEditor.EditorGUI.EndChangeCheck()) |
|||
{ |
|||
m_DebugItem.SetValue(value); |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
#endif
|
|||
} |
|||
|
|||
} |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering |
|||
{ |
|||
// Class that users need to extend for runtime debug menu item UI
|
|||
public abstract class DebugItemUI |
|||
{ |
|||
protected GameObject m_Root = null; |
|||
protected DebugItem m_DebugItem = null; |
|||
|
|||
public bool dynamicDisplay { get { return m_DebugItem.dynamicDisplay; } } |
|||
|
|||
protected DebugItemUI(DebugItem debugItem) |
|||
{ |
|||
m_DebugItem = debugItem; |
|||
} |
|||
|
|||
// Implement for selection specific beahavior (like changing color for example)
|
|||
public abstract void SetSelected(bool value); |
|||
// Implement behavior when user execute the "Validate" action
|
|||
public abstract void OnValidate(); |
|||
// Implement behavior when user execute the "Increment" action
|
|||
public abstract void OnIncrement(); |
|||
// Implement behavior when user execute the "Decrement" action
|
|||
public abstract void OnDecrement(); |
|||
// Implement this method to update the UI with current item value.
|
|||
// User must call it whenever Validate/Increment/Decrement is called. It will also be automatically called for dynamically displayed items.
|
|||
public abstract void Update(); |
|||
} |
|||
|
|||
public class DebugSimpleItemUI : DebugItemUI |
|||
{ |
|||
protected GameObject m_Name = null; |
|||
protected GameObject m_Value = null; |
|||
|
|||
protected DebugSimpleItemUI(GameObject parent, DebugItem debugItem, string name) |
|||
: base(debugItem) |
|||
{ |
|||
|
|||
m_Root = DebugMenuUI.CreateHorizontalLayoutGroup("", true, true, false, false, parent); |
|||
m_Name = DebugMenuUI.CreateTextElement(m_DebugItem.name, name, 10, TextAnchor.MiddleLeft, m_Root); |
|||
var layoutElem = m_Name.AddComponent<UI.LayoutElement>(); |
|||
layoutElem.minWidth = DebugMenuUI.kDebugItemNameWidth; |
|||
m_Value = DebugMenuUI.CreateTextElement(string.Format("{0} value", name), "", 10, TextAnchor.MiddleLeft, m_Root); |
|||
} |
|||
|
|||
public override void SetSelected(bool value) |
|||
{ |
|||
m_Name.GetComponent<UI.Text>().color = value ? DebugMenuUI.kColorSelected : DebugMenuUI.kColorUnSelected; |
|||
m_Value.GetComponent<UI.Text>().color = value ? DebugMenuUI.kColorSelected : DebugMenuUI.kColorUnSelected; |
|||
} |
|||
|
|||
public override void OnValidate() |
|||
{ |
|||
throw new System.NotImplementedException(); |
|||
} |
|||
|
|||
public override void OnIncrement() |
|||
{ |
|||
throw new System.NotImplementedException(); |
|||
} |
|||
|
|||
public override void OnDecrement() |
|||
{ |
|||
throw new System.NotImplementedException(); |
|||
} |
|||
|
|||
public override void Update() |
|||
{ |
|||
throw new System.NotImplementedException(); |
|||
} |
|||
} |
|||
|
|||
public class DebugBoolItemUI : DebugSimpleItemUI |
|||
{ |
|||
public DebugBoolItemUI(GameObject parent, DebugItem debugItem, string name) |
|||
: base(parent, debugItem, name) |
|||
{ |
|||
Update(); |
|||
} |
|||
|
|||
public override void Update() |
|||
{ |
|||
m_Value.GetComponent<UI.Text>().text = (bool)m_DebugItem.GetValue() ? "True" : "False"; |
|||
} |
|||
|
|||
|
|||
public override void OnValidate() |
|||
{ |
|||
m_DebugItem.SetValue(!(bool)m_DebugItem.GetValue()); |
|||
Update(); |
|||
} |
|||
|
|||
public override void OnIncrement() |
|||
{ |
|||
OnValidate(); |
|||
} |
|||
|
|||
public override void OnDecrement() |
|||
{ |
|||
OnValidate(); |
|||
} |
|||
} |
|||
|
|||
public class DebugFloatItemUI : DebugSimpleItemUI |
|||
{ |
|||
bool m_SelectIncrementMode = false; |
|||
int m_CurrentIncrementIndex = -1; |
|||
|
|||
public DebugFloatItemUI(GameObject parent, DebugItem debugItem, string name) |
|||
: base(parent, debugItem, name) |
|||
{ |
|||
Update(); |
|||
} |
|||
|
|||
public override void Update() |
|||
{ |
|||
float currentValue = (float)m_DebugItem.GetValue(); |
|||
bool isNegative = currentValue < 0.0f; |
|||
// Easier to format the string without caring about the '-' sign. We add it back at the end
|
|||
currentValue = Mathf.Abs(currentValue); |
|||
|
|||
char separator = System.Convert.ToChar(System.Globalization.CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator); |
|||
|
|||
// Start with the maximum amount of trailing zeros
|
|||
string valueWithMaxDecimals = string.Format("{0:0.00000}", currentValue); |
|||
|
|||
// Remove trailing zeros until we reach the separator or we reach the decimal we are currently editing.
|
|||
int separatorIndex = valueWithMaxDecimals.LastIndexOf(separator); |
|||
int index = valueWithMaxDecimals.Length - 1; |
|||
while ( |
|||
valueWithMaxDecimals[index] == '0' // Remove trailing zeros
|
|||
&& index > (separatorIndex + 1) // until we reach the separator
|
|||
&& index > (System.Math.Abs(m_CurrentIncrementIndex) + separatorIndex)) // Or it's the index of the current decimal being edited (so as to display the last trailing zero in this case)
|
|||
{ |
|||
index--; |
|||
} |
|||
|
|||
string finalValue = new string(valueWithMaxDecimals.ToCharArray(), 0, index + 1); |
|||
|
|||
// Add leading zeros until we reach where the current order is being edited.
|
|||
if(m_CurrentIncrementIndex > 0) |
|||
{ |
|||
float incrementValue = Mathf.Pow(10.0f, (float)m_CurrentIncrementIndex); |
|||
if(incrementValue > currentValue) |
|||
{ |
|||
float compareValue = currentValue + 1.0f; // Start at 1.0f because we know that we are going to increment by 10 or more
|
|||
while (incrementValue > compareValue) |
|||
{ |
|||
finalValue = finalValue.Insert(0, "0"); |
|||
compareValue *= 10.0f; |
|||
} |
|||
} |
|||
} |
|||
|
|||
// When selecting which decimal/order you want to edit, we show brackets around the figure to show the user.
|
|||
if(m_SelectIncrementMode) |
|||
{ |
|||
separatorIndex = finalValue.LastIndexOf(separator); // separator may have changed place if we added leading zeros
|
|||
int bracketIndex = separatorIndex - m_CurrentIncrementIndex; |
|||
if(m_CurrentIncrementIndex >= 0) // Skip separator
|
|||
bracketIndex -= 1; |
|||
|
|||
finalValue = finalValue.Insert(bracketIndex, "["); |
|||
finalValue = finalValue.Insert(bracketIndex + 2, "]"); |
|||
} |
|||
|
|||
if(isNegative) |
|||
finalValue = finalValue.Insert(0, "-"); |
|||
|
|||
m_Value.GetComponent<UI.Text>().text = finalValue; |
|||
} |
|||
|
|||
public override void OnValidate() |
|||
{ |
|||
m_SelectIncrementMode = !m_SelectIncrementMode; |
|||
Update(); |
|||
} |
|||
|
|||
public override void OnIncrement() |
|||
{ |
|||
if(!m_SelectIncrementMode) |
|||
{ |
|||
m_DebugItem.SetValue((float)m_DebugItem.GetValue() + Mathf.Pow(10.0f, (float)m_CurrentIncrementIndex)); |
|||
} |
|||
else |
|||
{ |
|||
m_CurrentIncrementIndex -= 1; // * 0.1 (10^m_CurrentIncrementIndex)
|
|||
m_CurrentIncrementIndex = System.Math.Max(-5, m_CurrentIncrementIndex); |
|||
} |
|||
Update(); |
|||
} |
|||
|
|||
public override void OnDecrement() |
|||
{ |
|||
if (!m_SelectIncrementMode) |
|||
{ |
|||
m_DebugItem.SetValue((float)m_DebugItem.GetValue() - Mathf.Pow(10.0f, (float)m_CurrentIncrementIndex)); |
|||
} |
|||
else |
|||
{ |
|||
m_CurrentIncrementIndex += 1; // * 10 (10^m_CurrentIncrementIndex)
|
|||
} |
|||
Update(); |
|||
} |
|||
} |
|||
|
|||
// Everything is done with int. We don't really care about values > 2b for debugging.
|
|||
public class DebugIntegerItemUI : DebugSimpleItemUI |
|||
{ |
|||
bool m_SelectIncrementMode = false; |
|||
int m_CurrentIncrementIndex = 0; |
|||
|
|||
public DebugIntegerItemUI(GameObject parent, DebugItem debugItem, string name) |
|||
: base(parent, debugItem, name) |
|||
{ |
|||
} |
|||
|
|||
protected void UpdateText(int value) |
|||
{ |
|||
bool isNegative = value < 0f; |
|||
// Easier to format the string without caring about the '-' sign. We add it back at the end
|
|||
value = System.Math.Abs(value); |
|||
|
|||
string finalValue = string.Format("{0}", value); |
|||
|
|||
// Add leading zeros until we reach where the current order is being edited.
|
|||
if(m_CurrentIncrementIndex > 0) |
|||
{ |
|||
int incrementValue = (int)System.Math.Pow(10, m_CurrentIncrementIndex); |
|||
if(incrementValue > value) |
|||
{ |
|||
int compareValue = System.Math.Max(value, 1); |
|||
while (incrementValue > compareValue) |
|||
{ |
|||
finalValue = finalValue.Insert(0, "0"); |
|||
compareValue *= 10; |
|||
} |
|||
} |
|||
} |
|||
|
|||
// When selecting which decimal/order you want to edit, we show brackets around the figure to show the user.
|
|||
if(m_SelectIncrementMode) |
|||
{ |
|||
int bracketIndex = finalValue.Length - 1 - m_CurrentIncrementIndex; |
|||
|
|||
finalValue = finalValue.Insert(bracketIndex, "["); |
|||
finalValue = finalValue.Insert(bracketIndex + 2, "]"); |
|||
} |
|||
|
|||
if(isNegative) |
|||
finalValue = finalValue.Insert(0, "-"); |
|||
|
|||
m_Value.GetComponent<UI.Text>().text = finalValue; |
|||
} |
|||
|
|||
protected virtual int GetIntegerValue() |
|||
{ |
|||
throw new System.NotImplementedException(); |
|||
} |
|||
|
|||
protected virtual void SetIntegerValue(int value) |
|||
{ |
|||
throw new System.NotImplementedException(); |
|||
} |
|||
|
|||
public override void Update() |
|||
{ |
|||
UpdateText(GetIntegerValue()); |
|||
} |
|||
|
|||
public override void OnValidate() |
|||
{ |
|||
m_SelectIncrementMode = !m_SelectIncrementMode; |
|||
Update(); |
|||
} |
|||
|
|||
public override void OnIncrement() |
|||
{ |
|||
if (!m_SelectIncrementMode) |
|||
{ |
|||
SetIntegerValue(GetIntegerValue() + (int)Mathf.Pow(10.0f, (float)m_CurrentIncrementIndex)); |
|||
} |
|||
else |
|||
{ |
|||
m_CurrentIncrementIndex -= 1; // *= 0.1 (10^m_CurrentIncrementIndex)
|
|||
m_CurrentIncrementIndex = System.Math.Max(0, m_CurrentIncrementIndex); |
|||
} |
|||
Update(); |
|||
} |
|||
|
|||
public override void OnDecrement() |
|||
{ |
|||
if (!m_SelectIncrementMode) |
|||
{ |
|||
SetIntegerValue(GetIntegerValue() - (int)Mathf.Pow(10.0f, (float)m_CurrentIncrementIndex)); |
|||
} |
|||
else |
|||
{ |
|||
m_CurrentIncrementIndex += 1; // *= 10 (10^m_CurrentIncrementIndex)
|
|||
m_CurrentIncrementIndex = System.Math.Max(0, m_CurrentIncrementIndex); |
|||
} |
|||
Update(); |
|||
} |
|||
} |
|||
public class DebugIntItemUI : DebugIntegerItemUI |
|||
{ |
|||
public DebugIntItemUI(GameObject parent, DebugItem debugItem, string name) |
|||
: base(parent, debugItem, name) |
|||
{ |
|||
UpdateText((int)m_DebugItem.GetValue()); |
|||
} |
|||
|
|||
protected override int GetIntegerValue() |
|||
{ |
|||
return (int)m_DebugItem.GetValue(); |
|||
} |
|||
|
|||
protected override void SetIntegerValue(int value) |
|||
{ |
|||
m_DebugItem.SetValue(value); |
|||
} |
|||
} |
|||
|
|||
public class DebugUIntItemUI : DebugIntegerItemUI |
|||
{ |
|||
public DebugUIntItemUI(GameObject parent, DebugItem debugItem, string name) |
|||
: base(parent, debugItem, name) |
|||
{ |
|||
UpdateText((int)(uint)m_DebugItem.GetValue()); |
|||
} |
|||
|
|||
protected override int GetIntegerValue() |
|||
{ |
|||
return (int)(uint)m_DebugItem.GetValue(); |
|||
} |
|||
|
|||
protected override void SetIntegerValue(int value) |
|||
{ |
|||
m_DebugItem.SetValue((uint)System.Math.Max(0, value)); |
|||
} |
|||
} |
|||
|
|||
public class DebugEnumItemUI : DebugSimpleItemUI |
|||
{ |
|||
int m_CurrentValueIndex = 0; |
|||
GUIContent[] m_ValueNames; |
|||
int[] m_Values; |
|||
|
|||
public DebugEnumItemUI(GameObject parent, DebugItem debugItem, string name, GUIContent[] valueNames, int[] values) |
|||
: base(parent, debugItem, name) |
|||
{ |
|||
m_Values = values; |
|||
m_ValueNames = valueNames; |
|||
m_CurrentValueIndex = FindIndexForValue((int)m_DebugItem.GetValue()); |
|||
|
|||
Update(); |
|||
} |
|||
|
|||
private int FindIndexForValue(int value) |
|||
{ |
|||
for(int i = 0 ; i < m_Values.Length ; ++i) |
|||
{ |
|||
if (m_Values[i] == value) |
|||
return i; |
|||
} |
|||
|
|||
return -1; |
|||
} |
|||
|
|||
public override void Update() |
|||
{ |
|||
if(m_CurrentValueIndex != -1) |
|||
{ |
|||
m_Value.GetComponent<UI.Text>().text = m_ValueNames[m_CurrentValueIndex].text; |
|||
} |
|||
} |
|||
|
|||
public override void OnValidate() |
|||
{ |
|||
OnIncrement(); |
|||
} |
|||
|
|||
public override void OnIncrement() |
|||
{ |
|||
m_CurrentValueIndex = (m_CurrentValueIndex + 1) % m_Values.Length; |
|||
m_DebugItem.SetValue(m_Values[m_CurrentValueIndex]); |
|||
Update(); |
|||
} |
|||
|
|||
public override void OnDecrement() |
|||
{ |
|||
m_CurrentValueIndex -= 1; |
|||
if (m_CurrentValueIndex < 0) |
|||
m_CurrentValueIndex = m_Values.Length - 1; |
|||
|
|||
m_DebugItem.SetValue(m_Values[m_CurrentValueIndex]); |
|||
Update(); |
|||
} |
|||
} |
|||
|
|||
public class DebugColorItemUI : DebugItemUI |
|||
{ |
|||
protected GameObject m_Name = null; |
|||
protected GameObject m_ColorRect = null; |
|||
|
|||
public DebugColorItemUI(GameObject parent, DebugItem debugItem, string name) |
|||
: base(debugItem) |
|||
{ |
|||
m_DebugItem = debugItem; |
|||
|
|||
m_Root = DebugMenuUI.CreateHorizontalLayoutGroup(name, true, true, false, false, parent); |
|||
|
|||
m_Name = DebugMenuUI.CreateTextElement(m_DebugItem.name, name, 10, TextAnchor.MiddleLeft, m_Root); |
|||
var layoutElemName = m_Name.AddComponent<UI.LayoutElement>(); |
|||
layoutElemName.minWidth = DebugMenuUI.kDebugItemNameWidth; |
|||
|
|||
// Force layout because we need the right height for the color rect element afterward.
|
|||
UI.LayoutRebuilder.ForceRebuildLayoutImmediate(m_Root.GetComponent<RectTransform>()); |
|||
RectTransform nameRect = m_Name.GetComponent<RectTransform>(); |
|||
|
|||
m_ColorRect = new GameObject(); |
|||
m_ColorRect.transform.SetParent(m_Root.transform, false); |
|||
m_ColorRect.AddComponent<UI.Image>(); |
|||
UI.LayoutElement layoutElem = m_ColorRect.AddComponent<UI.LayoutElement>(); |
|||
// We need to set min width/height because without an image, the size would be zero.
|
|||
layoutElem.minHeight = nameRect.rect.height; |
|||
layoutElem.minWidth = 40.0f; |
|||
|
|||
Update(); |
|||
} |
|||
|
|||
public override void Update() |
|||
{ |
|||
Color currentValue = (Color)m_DebugItem.GetValue(); |
|||
UI.Image image = m_ColorRect.GetComponent<UI.Image>(); |
|||
image.color = currentValue; |
|||
} |
|||
|
|||
public override void SetSelected(bool value) |
|||
{ |
|||
m_Name.GetComponent<UI.Text>().color = value ? DebugMenuUI.kColorSelected : DebugMenuUI.kColorUnSelected; |
|||
} |
|||
|
|||
// TODO: Edit mode!
|
|||
public override void OnValidate() |
|||
{ |
|||
} |
|||
|
|||
public override void OnIncrement() |
|||
{ |
|||
} |
|||
|
|||
public override void OnDecrement() |
|||
{ |
|||
} |
|||
} |
|||
} |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using System; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering |
|||
{ |
|||
[Serializable] |
|||
public abstract class DebugItemState |
|||
: ScriptableObject |
|||
{ |
|||
public DebugItemState() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public string panelName = ""; |
|||
public string itemName = ""; |
|||
|
|||
public abstract void UpdateDebugItemValue(); |
|||
public abstract void SetValue(object value); |
|||
|
|||
public void Initialize(string itemName, string panelName) |
|||
{ |
|||
this.panelName = panelName; |
|||
this.itemName = itemName; |
|||
} |
|||
} |
|||
|
|||
public class DebugItemState<T> : DebugItemState |
|||
{ |
|||
public T value; |
|||
|
|||
public override void SetValue(object value) |
|||
{ |
|||
#if UNITY_EDITOR
|
|||
UnityEditor.Undo.RecordObject(this, "DebugMenu State Update"); |
|||
UnityEditor.EditorUtility.SetDirty(this); |
|||
#endif
|
|||
this.value = (T)value; |
|||
} |
|||
|
|||
public override void UpdateDebugItemValue() |
|||
{ |
|||
DebugMenuManager dmm = DebugMenuManager.instance; |
|||
DebugPanel menu = dmm.GetDebugPanel(panelName); |
|||
if (menu != null) |
|||
{ |
|||
DebugItem item = menu.GetDebugItem(itemName); |
|||
if (item != null) |
|||
{ |
|||
item.SetValue(value, false); |
|||
} |
|||
} |
|||
|
|||
} |
|||
} |
|||
|
|||
public class DebugMenuState |
|||
: ScriptableObject |
|||
{ |
|||
[SerializeField] |
|||
List<DebugItemState> m_ItemStateList = new List<DebugItemState>(); |
|||
|
|||
public void OnEnable() |
|||
{ |
|||
#if UNITY_EDITOR
|
|||
UnityEditor.Undo.undoRedoPerformed += OnUndoRedoPerformed; |
|||
#endif
|
|||
|
|||
// We need to delay the actual update because at this point, some menus might not be created yet (depending on call order) so we can't update their values.
|
|||
DebugMenuManager.instance.RequireUpdateFromDebugItemState(); |
|||
} |
|||
|
|||
public void OnDisable() |
|||
{ |
|||
#if UNITY_EDITOR
|
|||
UnityEditor.Undo.undoRedoPerformed -= OnUndoRedoPerformed; |
|||
#endif
|
|||
// We check consistency in OnDisable instead of OnEnable because we compare the serialized state to the currently running debug menu so we need to make sure that all debug menu are properly created (which is not the case in OnEnable depending on call order)
|
|||
CheckConsistency(); |
|||
} |
|||
|
|||
|
|||
#if UNITY_EDITOR
|
|||
void OnUndoRedoPerformed() |
|||
{ |
|||
// Maybe check a hash or something? So that we don't do that at each redo...
|
|||
UpdateAllDebugItems(); |
|||
UnityEditorInternal.InternalEditorUtility.RepaintAllViews(); |
|||
} |
|||
#endif
|
|||
|
|||
void CheckConsistency() |
|||
{ |
|||
// Remove all objects that may have been removed from the debug menu since last serialization
|
|||
DebugMenuManager dmm = DebugMenuManager.instance; |
|||
List<DebugItemState> tempList = new List<DebugItemState>(); |
|||
foreach(var itemState in m_ItemStateList) |
|||
{ |
|||
DebugItem item = null; |
|||
DebugPanel menu = dmm.GetDebugPanel(itemState.panelName); |
|||
if(menu != null) |
|||
{ |
|||
item = menu.GetDebugItem(itemState.itemName); |
|||
} |
|||
|
|||
// Item no longer exist, clean up its state from the asset.
|
|||
if (item == null) |
|||
{ |
|||
tempList.Add(itemState); |
|||
} |
|||
} |
|||
|
|||
foreach(var itemState in tempList) |
|||
{ |
|||
m_ItemStateList.Remove(itemState); |
|||
Object.DestroyImmediate(itemState, true); |
|||
} |
|||
} |
|||
|
|||
public void AddDebugItemState(DebugItemState state) |
|||
{ |
|||
#if UNITY_EDITOR
|
|||
UnityEditor.AssetDatabase.AddObjectToAsset(state, this); |
|||
#endif
|
|||
m_ItemStateList.Add(state); |
|||
} |
|||
|
|||
public DebugItemState FindDebugItemState(string itemName, string menuName) |
|||
{ |
|||
return m_ItemStateList.Find(x => x.itemName == itemName && x.panelName == menuName); |
|||
} |
|||
|
|||
public void UpdateAllDebugItems() |
|||
{ |
|||
foreach (var itemState in m_ItemStateList) |
|||
{ |
|||
itemState.UpdateDebugItemValue(); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: d17031e345b144b4a887f66665be6a2b |
|||
timeCreated: 1495180913 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using System; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering |
|||
{ |
|||
public class DebugItem |
|||
{ |
|||
public Type type { get { return m_Type; } } |
|||
public string name { get { return m_Name; } } |
|||
public DebugItemHandler handler { get { return m_Handler; } } |
|||
public bool dynamicDisplay { get { return m_DynamicDisplay; } } |
|||
public bool readOnly { get { return m_Setter == null; } } |
|||
|
|||
public DebugItem(string name, Type type, Func<object> getter, Action<object> setter, bool dynamicDisplay = false, DebugItemHandler handler = null) |
|||
{ |
|||
m_Type = type; |
|||
m_Setter = setter; |
|||
m_Getter = getter; |
|||
m_Name = name; |
|||
m_Handler = handler; |
|||
m_DynamicDisplay = dynamicDisplay; |
|||
} |
|||
|
|||
public Type GetItemType() |
|||
{ |
|||
return m_Type; |
|||
} |
|||
|
|||
public void SetValue(object value, bool record = true) |
|||
{ |
|||
// Setter can be null for readonly items
|
|||
if(m_Setter != null) |
|||
{ |
|||
m_Setter(value); |
|||
m_Handler.ClampValues(m_Getter, m_Setter); |
|||
|
|||
// Update state for serialization/undo
|
|||
if(record) |
|||
m_State.SetValue(m_Getter()); |
|||
} |
|||
} |
|||
|
|||
public object GetValue() |
|||
{ |
|||
return m_Getter(); |
|||
} |
|||
|
|||
public void SetDebugItemState(DebugItemState state) |
|||
{ |
|||
m_State = state; |
|||
} |
|||
|
|||
Func<object> m_Getter; |
|||
Action<object> m_Setter; |
|||
Type m_Type; |
|||
string m_Name; |
|||
DebugItemHandler m_Handler = null; |
|||
bool m_DynamicDisplay = false; |
|||
DebugItemState m_State = null; |
|||
} |
|||
|
|||
public class DebugPanel |
|||
{ |
|||
public string name { get { return m_Name; } } |
|||
public DebugPanelUI panelUI { get { return m_DebugPanelUI; } } |
|||
public int itemCount { get { return m_Items.Count; } } |
|||
|
|||
protected string m_Name = "Unknown Debug Menu"; |
|||
protected List<DebugItem> m_Items = new List<DebugItem>(); |
|||
protected DebugPanelUI m_DebugPanelUI = null; |
|||
|
|||
protected DebugPanel(string name) |
|||
{ |
|||
m_Name = name; |
|||
} |
|||
|
|||
public DebugItem GetDebugItem(int index) |
|||
{ |
|||
if (index >= m_Items.Count || index < 0) |
|||
return null; |
|||
return m_Items[index]; |
|||
} |
|||
|
|||
public DebugItem GetDebugItem(string name) |
|||
{ |
|||
return m_Items.Find(x => x.name == name); |
|||
} |
|||
|
|||
public bool HasDebugItem(DebugItem debugItem) |
|||
{ |
|||
foreach(var item in m_Items) |
|||
{ |
|||
if (debugItem == item) |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
public void RemoveDebugItem(DebugItem debugItem) |
|||
{ |
|||
m_Items.Remove(debugItem); |
|||
m_DebugPanelUI.RebuildGUI(); |
|||
} |
|||
|
|||
public void AddDebugItem(DebugItem debugItem) |
|||
{ |
|||
m_Items.Add(debugItem); |
|||
m_DebugPanelUI.RebuildGUI(); |
|||
} |
|||
|
|||
public void AddDebugItem<ItemType>(string name, Func<object> getter, Action<object> setter, bool dynamicDisplay = false, DebugItemHandler handler = null) |
|||
{ |
|||
if (handler == null) |
|||
handler = new DefaultDebugItemHandler(); |
|||
DebugItem newItem = new DebugItem(name, typeof(ItemType), getter, setter, dynamicDisplay, handler); |
|||
handler.SetDebugItem(newItem); |
|||
m_Items.Add(newItem); |
|||
|
|||
DebugMenuManager dmm = DebugMenuManager.instance; |
|||
DebugItemState itemState = dmm.FindDebugItemState(name, m_Name); |
|||
if(itemState == null) |
|||
{ |
|||
itemState = handler.CreateDebugItemState(); |
|||
itemState.Initialize(name, m_Name); |
|||
itemState.SetValue(getter()); |
|||
dmm.AddDebugItemState(itemState); |
|||
} |
|||
|
|||
newItem.SetDebugItemState(itemState); |
|||
} |
|||
} |
|||
|
|||
public class DebugPanel<DebugPanelUIClass> |
|||
: DebugPanel where DebugPanelUIClass:DebugPanelUI, new() |
|||
{ |
|||
public DebugPanel(string name) |
|||
: base(name) |
|||
{ |
|||
m_DebugPanelUI = new DebugPanelUIClass(); |
|||
m_DebugPanelUI.SetDebugPanel(this); |
|||
} |
|||
} |
|||
} |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using System; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering |
|||
{ |
|||
public class DebugPanelUI |
|||
{ |
|||
protected GameObject m_Root = null; |
|||
protected DebugPanel m_DebugPanel = null; |
|||
protected List<DebugItemUI> m_ItemsUI = new List<DebugItemUI>(); |
|||
protected int m_SelectedItem = -1; |
|||
|
|||
public int itemCount { get { return m_ItemsUI.Count; } } |
|||
|
|||
public DebugPanelUI() |
|||
{ |
|||
} |
|||
|
|||
public void SetDebugPanel(DebugPanel panel) |
|||
{ |
|||
m_DebugPanel = panel; |
|||
} |
|||
|
|||
public void BuildGUI(GameObject parent) |
|||
{ |
|||
m_Root = new GameObject(string.Format("{0}", m_DebugPanel.name)); |
|||
m_Root.transform.SetParent(parent.transform); |
|||
m_Root.transform.localPosition = Vector3.zero; |
|||
m_Root.transform.localScale = Vector3.one; |
|||
|
|||
UI.VerticalLayoutGroup menuVL = m_Root.AddComponent<UI.VerticalLayoutGroup>(); |
|||
menuVL.spacing = 5.0f; |
|||
menuVL.childControlWidth = true; |
|||
menuVL.childControlHeight = true; |
|||
menuVL.childForceExpandWidth = true; |
|||
menuVL.childForceExpandHeight = false; |
|||
|
|||
RectTransform menuVLRectTransform = m_Root.GetComponent<RectTransform>(); |
|||
menuVLRectTransform.pivot = new Vector2(0.0f, 0.0f); |
|||
menuVLRectTransform.localPosition = new Vector3(0.0f, 0.0f); |
|||
menuVLRectTransform.anchorMin = new Vector2(0.0f, 0.0f); |
|||
menuVLRectTransform.anchorMax = new Vector2(1.0f, 1.0f); |
|||
|
|||
BuildGUIImpl(m_Root); |
|||
} |
|||
|
|||
public void RebuildGUI() |
|||
{ |
|||
for (int i = 0; i < m_Root.transform.childCount; ++i) |
|||
{ |
|||
Object.DestroyImmediate(m_Root.transform.GetChild(i).gameObject); |
|||
} |
|||
BuildGUIImpl(m_Root); |
|||
} |
|||
|
|||
// Default Implementation: just build all items with provided handler.
|
|||
public virtual void BuildGUIImpl(GameObject parent) |
|||
{ |
|||
DebugMenuUI.CreateTextElement(string.Format("{0} Title", m_DebugPanel.name), m_DebugPanel.name, 14, TextAnchor.MiddleLeft, m_Root); |
|||
|
|||
m_ItemsUI.Clear(); |
|||
for (int i = 0; i < m_DebugPanel.itemCount; i++) |
|||
{ |
|||
DebugItemHandler handler = m_DebugPanel.GetDebugItem(i).handler; // Should never be null, we have at least the default handler
|
|||
m_ItemsUI.Add(handler.BuildGUI(parent)); |
|||
} |
|||
} |
|||
|
|||
#if UNITY_EDITOR
|
|||
// Default implementation for editor UI of a debug panel. Users may override this behavior.
|
|||
// This will just display all items via their specific handlers in a vertical layout.
|
|||
public virtual void OnEditorGUI() |
|||
{ |
|||
using (new UnityEditor.EditorGUILayout.VerticalScope()) |
|||
{ |
|||
for (int i = 0; i < m_DebugPanel.itemCount; ++i) |
|||
{ |
|||
m_DebugPanel.GetDebugItem(i).handler.OnEditorGUI(); |
|||
} |
|||
} |
|||
} |
|||
#endif
|
|||
|
|||
public DebugItem GetSelectedDebugItem() |
|||
{ |
|||
if (m_SelectedItem != -1) |
|||
{ |
|||
return m_DebugPanel.GetDebugItem(m_SelectedItem); |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
void SetSelectedItem(int index) |
|||
{ |
|||
if (m_SelectedItem != -1) |
|||
{ |
|||
m_ItemsUI[m_SelectedItem].SetSelected(false); |
|||
} |
|||
|
|||
m_SelectedItem = index; |
|||
m_ItemsUI[m_SelectedItem].SetSelected(true); |
|||
} |
|||
|
|||
public void SetSelected(bool value) |
|||
{ |
|||
m_Root.SetActive(value); |
|||
|
|||
if (value) |
|||
{ |
|||
if (m_SelectedItem == -1) |
|||
{ |
|||
NextItem(); |
|||
} |
|||
else |
|||
SetSelectedItem(m_SelectedItem); |
|||
} |
|||
} |
|||
|
|||
void NextItem() |
|||
{ |
|||
if (m_ItemsUI.Count != 0) |
|||
{ |
|||
int newSelected = (m_SelectedItem + 1) % m_ItemsUI.Count; |
|||
SetSelectedItem(newSelected); |
|||
} |
|||
} |
|||
|
|||
void PreviousItem() |
|||
{ |
|||
if (m_ItemsUI.Count != 0) |
|||
{ |
|||
int newSelected = m_SelectedItem - 1; |
|||
if (newSelected == -1) |
|||
newSelected = m_ItemsUI.Count - 1; |
|||
SetSelectedItem(newSelected); |
|||
} |
|||
} |
|||
|
|||
public void OnMoveHorizontal(float value) |
|||
{ |
|||
if (m_SelectedItem != -1 && !m_DebugPanel.GetDebugItem(m_SelectedItem).readOnly) |
|||
{ |
|||
if (value > 0.0f) |
|||
m_ItemsUI[m_SelectedItem].OnIncrement(); |
|||
else |
|||
m_ItemsUI[m_SelectedItem].OnDecrement(); |
|||
} |
|||
} |
|||
|
|||
public void OnMoveVertical(float value) |
|||
{ |
|||
if (value > 0.0f) |
|||
PreviousItem(); |
|||
else |
|||
NextItem(); |
|||
} |
|||
|
|||
public void OnValidate() |
|||
{ |
|||
if (m_SelectedItem != -1 && !m_DebugPanel.GetDebugItem(m_SelectedItem).readOnly) |
|||
m_ItemsUI[m_SelectedItem].OnValidate(); |
|||
} |
|||
|
|||
public void Update() |
|||
{ |
|||
foreach (var itemUI in m_ItemsUI) |
|||
{ |
|||
if (itemUI.dynamicDisplay) |
|||
itemUI.Update(); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 7407c6acaa932c34f86414a4a8935f24 |
|||
timeCreated: 1492075547 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: a07168baba11f084daec1edd4032f153 |
|||
folderAsset: yes |
|||
timeCreated: 1495456975 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
#if UNITY_EDITOR
|
|||
using UnityEditor; |
|||
#endif
|
|||
|
|||
namespace UnityEngine.Experimental.Rendering.HDPipeline |
|||
{ |
|||
public class LightingDebugPanelUI |
|||
: DebugPanelUI |
|||
{ |
|||
#if UNITY_EDITOR
|
|||
public override void OnEditorGUI() |
|||
{ |
|||
using (new UnityEditor.EditorGUILayout.VerticalScope()) |
|||
{ |
|||
m_DebugPanel.GetDebugItem("Enable Shadows").handler.OnEditorGUI(); |
|||
|
|||
DebugItem shadowDebug = m_DebugPanel.GetDebugItem("Shadow Debug Mode"); |
|||
shadowDebug.handler.OnEditorGUI(); |
|||
if ((ShadowMapDebugMode)shadowDebug.GetValue() == ShadowMapDebugMode.VisualizeShadowMap) |
|||
{ |
|||
EditorGUI.indentLevel++; |
|||
m_DebugPanel.GetDebugItem("Shadow Map Index").handler.OnEditorGUI(); |
|||
EditorGUI.indentLevel--; |
|||
} |
|||
DebugItem lightingDebugModeItem = m_DebugPanel.GetDebugItem("Lighting Debug Mode"); |
|||
lightingDebugModeItem.handler.OnEditorGUI(); |
|||
if ((DebugLightingMode)lightingDebugModeItem.GetValue() == DebugLightingMode.SpecularLighting) |
|||
{ |
|||
EditorGUI.indentLevel++; |
|||
DebugItem overrideSmoothnessItem = m_DebugPanel.GetDebugItem("Override Smoothness"); |
|||
overrideSmoothnessItem.handler.OnEditorGUI(); |
|||
if ((bool)overrideSmoothnessItem.GetValue()) |
|||
{ |
|||
m_DebugPanel.GetDebugItem("Override Smoothness Value").handler.OnEditorGUI(); |
|||
} |
|||
EditorGUI.indentLevel--; |
|||
} |
|||
else if ((DebugLightingMode)lightingDebugModeItem.GetValue() == DebugLightingMode.DiffuseLighting) |
|||
{ |
|||
EditorGUI.indentLevel++; |
|||
m_DebugPanel.GetDebugItem("Debug Lighting Albedo").handler.OnEditorGUI(); |
|||
EditorGUI.indentLevel--; |
|||
} |
|||
|
|||
DebugItem displaySkyReflecItem = m_DebugPanel.GetDebugItem("Display Sky Reflection"); |
|||
displaySkyReflecItem.handler.OnEditorGUI(); |
|||
if ((bool)displaySkyReflecItem.GetValue()) |
|||
{ |
|||
EditorGUI.indentLevel++; |
|||
m_DebugPanel.GetDebugItem("Sky Reflection Mipmap").handler.OnEditorGUI(); |
|||
EditorGUI.indentLevel--; |
|||
} |
|||
} |
|||
} |
|||
#endif
|
|||
} |
|||
|
|||
public class LightingDebugPanel |
|||
: DebugPanel<LightingDebugPanelUI> |
|||
{ |
|||
public LightingDebugPanel() |
|||
: base("Lighting") |
|||
{ |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 19cc6398a661be547848eb23d58699cf |
|||
timeCreated: 1495638676 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: b7b2843778281fb4bbd2a62a3e165c15 |
|||
timeCreated: 1495456996 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 6e7cea1e2f04a344db1d12f0f1c98f3e |
|||
timeCreated: 1495456996 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: dd5284e29e625f044be91737547ae28d |
|||
timeCreated: 1495456996 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 7b805c6a0dad19144b48c3fe01b2775d |
|||
timeCreated: 1495456996 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: cdfed9a25a787094cbad07cb325b88e0 |
|||
timeCreated: 1495456996 |
|||
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 DebugItemStateBool : DebugItemState<bool> |
|||
{ |
|||
} |
|||
} |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering |
|||
{ |
|||
public class DebugItemStateColor : DebugItemState<Color> |
|||
{ |
|||
} |
|||
} |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering |
|||
{ |
|||
public class DebugItemStateFloat : DebugItemState<float> |
|||
{ |
|||
} |
|||
} |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering |
|||
{ |
|||
public class DebugItemStateInt : DebugItemState<int> |
|||
{ |
|||
} |
|||
} |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering |
|||
{ |
|||
public class DebugItemStateUInt : DebugItemState<uint> |
|||
{ |
|||
} |
|||
} |
|
|||
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") |
|||
{ |
|||
} |
|||
} |
|||
} |
|
|||
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; |
|||
GUIContent[] m_ValueNames; |
|||
int[] m_Values; |
|||
|
|||
public DebugMenuEnumItemUI(GameObject parent, DebugMenuItem menuItem, string name, GUIContent[] valueNames, int[] values) |
|||
: base(parent, menuItem, name) |
|||
{ |
|||
m_Values = values; |
|||
m_ValueNames = valueNames; |
|||
m_CurrentValueIndex = FindIndexForValue((int)m_MenuItem.GetValue()); |
|||
|
|||
Update(); |
|||
} |
|||
|
|||
private int FindIndexForValue(int value) |
|||
{ |
|||
for(int i = 0 ; i < m_Values.Length ; ++i) |
|||
{ |
|||
if (m_Values[i] == value) |
|||
return i; |
|||
} |
|||
|
|||
return -1; |
|||
} |
|||
|
|||
public override void Update() |
|||
{ |
|||
if(m_CurrentValueIndex != -1) |
|||
{ |
|||
m_Value.GetComponent<UI.Text>().text = m_ValueNames[m_CurrentValueIndex].text; |
|||
} |
|||
} |
|||
|
|||
public override void OnValidate() |
|||
{ |
|||
OnIncrement(); |
|||
} |
|||
|
|||
public override void OnIncrement() |
|||
{ |
|||
m_CurrentValueIndex = (m_CurrentValueIndex + 1) % m_Values.Length; |
|||
m_MenuItem.SetValue(m_Values[m_CurrentValueIndex]); |
|||
Update(); |
|||
} |
|||
|
|||
public override void OnDecrement() |
|||
{ |
|||
m_CurrentValueIndex -= 1; |
|||
if (m_CurrentValueIndex < 0) |
|||
m_CurrentValueIndex = m_Values.Length - 1; |
|||
|
|||
m_MenuItem.SetValue(m_Values[m_CurrentValueIndex]); |
|||
Update(); |
|||
} |
|||
} |
|||
|
|||
public class DebugMenuColorItemUI : DebugMenuItemUI |
|||
{ |
|||
protected GameObject m_Name = null; |
|||
protected GameObject m_ColorRect = null; |
|||
|
|||
public DebugMenuColorItemUI(GameObject parent, DebugMenuItem menuItem, string name) |
|||
: base(menuItem) |
|||
{ |
|||
m_MenuItem = menuItem; |
|||
|
|||
m_Root = DebugMenuUI.CreateHorizontalLayoutGroup(name, true, true, false, false, parent); |
|||
|
|||
m_Name = DebugMenuUI.CreateTextElement(m_MenuItem.name, name, 10, TextAnchor.MiddleLeft, m_Root); |
|||
var layoutElemName = m_Name.AddComponent<UI.LayoutElement>(); |
|||
layoutElemName.minWidth = DebugMenuUI.kDebugItemNameWidth; |
|||
|
|||
// Force layout because we need the right height for the color rect element afterward.
|
|||
UI.LayoutRebuilder.ForceRebuildLayoutImmediate(m_Root.GetComponent<RectTransform>()); |
|||
RectTransform nameRect = m_Name.GetComponent<RectTransform>(); |
|||
|
|||
m_ColorRect = new GameObject(); |
|||
m_ColorRect.transform.SetParent(m_Root.transform, false); |
|||
m_ColorRect.AddComponent<UI.Image>(); |
|||
UI.LayoutElement layoutElem = m_ColorRect.AddComponent<UI.LayoutElement>(); |
|||
// We need to set min width/height because without an image, the size would be zero.
|
|||
layoutElem.minHeight = nameRect.rect.height; |
|||
layoutElem.minWidth = 40.0f; |
|||
|
|||
Update(); |
|||
} |
|||
|
|||
public override void Update() |
|||
{ |
|||
Color currentValue = (Color)m_MenuItem.GetValue(); |
|||
UI.Image image = m_ColorRect.GetComponent<UI.Image>(); |
|||
image.color = currentValue; |
|||
} |
|||
|
|||
public override void SetSelected(bool value) |
|||
{ |
|||
m_Name.GetComponent<UI.Text>().color = value ? DebugMenuUI.kColorSelected : DebugMenuUI.kColorUnSelected; |
|||
} |
|||
|
|||
// TODO: Edit mode!
|
|||
public override void OnValidate() |
|||
{ |
|||
} |
|||
|
|||
public override void OnIncrement() |
|||
{ |
|||
} |
|||
|
|||
public override void OnDecrement() |
|||
{ |
|||
} |
|||
} |
|||
} |
|
|||
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
|
|||
protected GUIContent m_Label; |
|||
protected List<GUIContent> m_EnumStrings = null; |
|||
protected 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.ToArray(), m_EnumValues.ToArray()); |
|||
} |
|||
|
|||
return newItemUI; |
|||
} |
|||
|
|||
#if UNITY_EDITOR
|
|||
bool 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); |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
bool 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); |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
bool 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); |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
bool 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); |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
bool DrawColorItem() |
|||
{ |
|||
EditorGUI.BeginChangeCheck(); |
|||
Color value = EditorGUILayout.ColorField(m_Label, (Color)m_MenuItem.GetValue()); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
m_MenuItem.SetValue(value); |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
bool 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); |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
public virtual bool OnEditorGUI() |
|||
{ |
|||
if (m_MenuItem.GetItemType() == typeof(bool)) |
|||
{ |
|||
return DrawBoolItem(); |
|||
} |
|||
else if (m_MenuItem.GetItemType() == typeof(int)) |
|||
{ |
|||
return DrawIntItem(); |
|||
} |
|||
else if(m_MenuItem.GetItemType() == typeof(uint)) |
|||
{ |
|||
return DrawUIntItem(); |
|||
} |
|||
else if (m_MenuItem.GetItemType() == typeof(float)) |
|||
{ |
|||
return DrawFloatItem(); |
|||
} |
|||
else if (m_MenuItem.GetItemType() == typeof(Color)) |
|||
{ |
|||
return DrawColorItem(); |
|||
} |
|||
else if (m_MenuItem.GetItemType().BaseType == typeof(System.Enum)) |
|||
{ |
|||
return DrawEnumItem(); |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
#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 bool 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); |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
#endif
|
|||
} |
|||
|
|||
public class DebugItemDrawerIntEnum |
|||
: DebugItemDrawer |
|||
{ |
|||
GUIContent[] m_EnumStrings = null; |
|||
int[] m_EnumValues = null; |
|||
|
|||
public DebugItemDrawerIntEnum(GUIContent[] enumStrings, int[] enumValues) |
|||
{ |
|||
m_EnumStrings = enumStrings; |
|||
m_EnumValues = enumValues; |
|||
} |
|||
|
|||
public override DebugMenuItemUI BuildGUI(GameObject parent, DebugMenuItem menuItem) |
|||
{ |
|||
return new DebugMenuEnumItemUI(parent, menuItem, m_Label.text, m_EnumStrings, m_EnumValues); |
|||
} |
|||
|
|||
#if UNITY_EDITOR
|
|||
public override bool OnEditorGUI() |
|||
{ |
|||
UnityEditor.EditorGUI.BeginChangeCheck(); |
|||
int value = UnityEditor.EditorGUILayout.IntPopup(m_Label, (int)m_MenuItem.GetValue(), m_EnumStrings, m_EnumValues); |
|||
if (UnityEditor.EditorGUI.EndChangeCheck()) |
|||
{ |
|||
m_MenuItem.SetValue(value); |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
#endif
|
|||
} |
|||
|
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue