Skip to content

Commit 2d226eb

Browse files
Fixed volume debug menu in playmode (#149)
* Refresh widgets in play mode. Added doc. Reduced refresh rate * Changelog * Added some code doc * Fix refresh rate and scroll over hidden volumes in play mode Co-authored-by: sebastienlagarde <[email protected]>
1 parent 85bf9c3 commit 2d226eb

File tree

12 files changed

+741
-10
lines changed

12 files changed

+741
-10
lines changed

com.unity.render-pipelines.core/Runtime/Debugging/DebugUI.Containers.cs

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,40 @@ public void SetColumnVisibility(int index, bool visible)
252252
newVisibleColumns.Sort();
253253
}
254254
header.state.visibleColumns = newVisibleColumns.ToArray();
255+
256+
var cols = header.state.columns;
257+
for (int i = 0; i < cols.Length; i++)
258+
cols[i].width = 50f;
259+
header.ResizeToFit();
255260
}
261+
#else
262+
var columns = VisibleColumns;
263+
if (index < 0 || index > columns.Length)
264+
return;
265+
266+
columns[index] = visible;
267+
#endif
268+
}
269+
270+
/// <summary>
271+
/// Get column visibility.
272+
/// </summary>
273+
/// <param name="index">Index of the column.</param>
274+
/// <returns>True if the column is visible.</returns>
275+
public bool GetColumnVisibility(int index)
276+
{
277+
#if UNITY_EDITOR
278+
var header = Header;
279+
if (index < 0 || index >= m_ColumnCount)
280+
return false;
281+
282+
return header.IsColumnVisible(index + 1);
283+
#else
284+
var columns = VisibleColumns;
285+
if (index < 0 || index > columns.Length)
286+
return false;
287+
288+
return columns[index];
256289
#endif
257290
}
258291

@@ -315,6 +348,41 @@ UnityEditor.IMGUI.Controls.MultiColumnHeaderState.Column CreateColumn(string nam
315348
return m_Header;
316349
}
317350
}
351+
#else
352+
bool[] m_Header = null;
353+
354+
/// <summary>
355+
/// The visible columns
356+
/// </summary>
357+
public bool[] VisibleColumns
358+
{
359+
get
360+
{
361+
if (m_Header != null)
362+
return m_Header;
363+
364+
int columnCount = 0;
365+
if (children.Count != 0)
366+
{
367+
columnCount = ((Container)children[0]).children.Count;
368+
for (int i = 1; i < children.Count; i++)
369+
{
370+
if (((Container)children[i]).children.Count != columnCount)
371+
{
372+
Debug.LogError("All rows must have the same number of children.");
373+
return null;
374+
}
375+
}
376+
}
377+
378+
m_Header = new bool[columnCount];
379+
for (int i = 0; i < columnCount; i++)
380+
m_Header[i] = true;
381+
382+
return m_Header;
383+
}
384+
}
385+
#endif
318386

319387
/// <summary>
320388
/// Method called when a children is added.
@@ -337,7 +405,6 @@ protected override void OnItemRemoved(ObservableList<Widget> sender, ListChanged
337405
base.OnItemRemoved(sender, e);
338406
m_Header = null;
339407
}
340-
#endif
341408
}
342409
}
343410
}

com.unity.render-pipelines.core/Runtime/Debugging/Prefabs/Resources/DebugUI Canvas.prefab

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,4 @@ MonoBehaviour:
172172
prefab: {fileID: 224284813447651300, guid: 38a07789c9e87004dad98c2909f58369, type: 3}
173173
- type: UnityEngine.Rendering.DebugUI+Table+Row, Unity.RenderPipelines.Core.Runtime,
174174
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
175-
prefab: {fileID: 224053494956566916, guid: 1c87ab2ce8b8b304d98fbe9a734b1f74, type: 3}
175+
prefab: {fileID: 224053494956566916, guid: 2d019437ff89b8d44949727731cd9357, type: 3}

com.unity.render-pipelines.core/Runtime/Debugging/Prefabs/Scripts/DebugUIHandlerColor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public override void OnAction()
141141
valueToggle.isOn = !valueToggle.isOn;
142142
}
143143

144-
void UpdateColor()
144+
internal void UpdateColor()
145145
{
146146
if (colorImage != null)
147147
colorImage.color = m_Field.GetValue();
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using UnityEngine.UI;
2+
3+
namespace UnityEngine.Rendering.UI
4+
{
5+
/// <summary>
6+
/// DebugUIHandler for row widget.
7+
/// </summary>
8+
public class DebugUIHandlerRow : DebugUIHandlerFoldout
9+
{
10+
float m_Timer;
11+
12+
/// <summary>
13+
/// OnEnable implementation.
14+
/// </summary>
15+
protected override void OnEnable()
16+
{
17+
m_Timer = 0f;
18+
}
19+
20+
/// <summary>
21+
/// Update implementation.
22+
/// </summary>
23+
protected void Update()
24+
{
25+
var row = CastWidget<DebugUI.Table.Row>();
26+
var table = row.parent as DebugUI.Table;
27+
28+
float refreshRate = 0.1f;
29+
bool refreshRow = m_Timer >= refreshRate;
30+
if (refreshRow)
31+
m_Timer -= refreshRate;
32+
m_Timer += Time.deltaTime;
33+
34+
for (int i = 0; i < row.children.Count; i++)
35+
{
36+
var child = gameObject.transform.GetChild(1).GetChild(i).gameObject;
37+
var active = table.GetColumnVisibility(i);
38+
child.SetActive(active);
39+
if (active && refreshRow)
40+
{
41+
if (child.TryGetComponent<DebugUIHandlerColor>(out var color))
42+
color.UpdateColor();
43+
if (child.TryGetComponent<DebugUIHandlerToggle>(out var toggle))
44+
toggle.UpdateValueLabel();
45+
}
46+
}
47+
48+
// Update previous and next ui handlers to pass over hidden volumes
49+
var item = gameObject.transform.GetChild(1).GetChild(0).gameObject;
50+
var itemWidget = item.GetComponent<DebugUIHandlerWidget>();
51+
DebugUIHandlerWidget previous = null;
52+
for (int i = 0; i < row.children.Count; i++)
53+
{
54+
itemWidget.previousUIHandler = previous;
55+
if (table.GetColumnVisibility(i))
56+
previous = itemWidget;
57+
58+
bool found = false;
59+
for (int j = i + 1; j < row.children.Count; j++)
60+
{
61+
if (table.GetColumnVisibility(j))
62+
{
63+
var child = gameObject.transform.GetChild(1).GetChild(j).gameObject;
64+
var childWidget = child.GetComponent<DebugUIHandlerWidget>();
65+
itemWidget.nextUIHandler = childWidget;
66+
item = child;
67+
itemWidget = childWidget;
68+
i = j - 1;
69+
found = true;
70+
break;
71+
}
72+
}
73+
if (!found)
74+
{
75+
itemWidget.nextUIHandler = null;
76+
break;
77+
}
78+
}
79+
}
80+
}
81+
}

com.unity.render-pipelines.core/Runtime/Debugging/Prefabs/Scripts/DebugUIHandlerRow.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

com.unity.render-pipelines.core/Runtime/Debugging/Prefabs/Scripts/DebugUIHandlerToggle.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public override void OnAction()
5959
/// <summary>
6060
/// Update the label.
6161
/// </summary>
62-
protected virtual void UpdateValueLabel()
62+
internal protected virtual void UpdateValueLabel()
6363
{
6464
if (valueToggle != null)
6565
valueToggle.isOn = m_Field.GetValue();

com.unity.render-pipelines.core/Runtime/Debugging/Prefabs/Scripts/DebugUIHandlerToggleHistory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ internal override void SetWidget(DebugUI.Widget widget)
3636
/// <summary>
3737
/// Update the label.
3838
/// </summary>
39-
protected override void UpdateValueLabel()
39+
internal protected override void UpdateValueLabel()
4040
{
4141
base.UpdateValueLabel();
4242
DebugUI.HistoryBoolField field = m_Field as DebugUI.HistoryBoolField;

0 commit comments

Comments
 (0)