Skip to content

Fixed volume debug menu in playmode #149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,40 @@ public void SetColumnVisibility(int index, bool visible)
newVisibleColumns.Sort();
}
header.state.visibleColumns = newVisibleColumns.ToArray();

var cols = header.state.columns;
for (int i = 0; i < cols.Length; i++)
cols[i].width = 50f;
header.ResizeToFit();
}
#else
var columns = VisibleColumns;
if (index < 0 || index > columns.Length)
return;

columns[index] = visible;
#endif
}

/// <summary>
/// Get column visibility.
/// </summary>
/// <param name="index">Index of the column.</param>
/// <returns>True if the column is visible.</returns>
public bool GetColumnVisibility(int index)
{
#if UNITY_EDITOR
var header = Header;
if (index < 0 || index >= m_ColumnCount)
return false;

return header.IsColumnVisible(index + 1);
#else
var columns = VisibleColumns;
if (index < 0 || index > columns.Length)
return false;

return columns[index];
#endif
}

Expand Down Expand Up @@ -315,6 +348,41 @@ UnityEditor.IMGUI.Controls.MultiColumnHeaderState.Column CreateColumn(string nam
return m_Header;
}
}
#else
bool[] m_Header = null;

/// <summary>
/// The visible columns
/// </summary>
public bool[] VisibleColumns
{
get
{
if (m_Header != null)
return m_Header;

int columnCount = 0;
if (children.Count != 0)
{
columnCount = ((Container)children[0]).children.Count;
for (int i = 1; i < children.Count; i++)
{
if (((Container)children[i]).children.Count != columnCount)
{
Debug.LogError("All rows must have the same number of children.");
return null;
}
}
}

m_Header = new bool[columnCount];
for (int i = 0; i < columnCount; i++)
m_Header[i] = true;

return m_Header;
}
}
#endif

/// <summary>
/// Method called when a children is added.
Expand All @@ -337,7 +405,6 @@ protected override void OnItemRemoved(ObservableList<Widget> sender, ListChanged
base.OnItemRemoved(sender, e);
m_Header = null;
}
#endif
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,4 @@ MonoBehaviour:
prefab: {fileID: 224284813447651300, guid: 38a07789c9e87004dad98c2909f58369, type: 3}
- type: UnityEngine.Rendering.DebugUI+Table+Row, Unity.RenderPipelines.Core.Runtime,
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
prefab: {fileID: 224053494956566916, guid: 1c87ab2ce8b8b304d98fbe9a734b1f74, type: 3}
prefab: {fileID: 224053494956566916, guid: 2d019437ff89b8d44949727731cd9357, type: 3}
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public override void OnAction()
valueToggle.isOn = !valueToggle.isOn;
}

void UpdateColor()
internal void UpdateColor()
{
if (colorImage != null)
colorImage.color = m_Field.GetValue();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
using UnityEngine.UI;

namespace UnityEngine.Rendering.UI
{
/// <summary>
/// DebugUIHandler for row widget.
/// </summary>
public class DebugUIHandlerRow : DebugUIHandlerFoldout
{
float m_Timer;

/// <summary>
/// OnEnable implementation.
/// </summary>
protected override void OnEnable()
{
m_Timer = 0f;
}

/// <summary>
/// Update implementation.
/// </summary>
protected void Update()
{
var row = CastWidget<DebugUI.Table.Row>();
var table = row.parent as DebugUI.Table;

float refreshRate = 0.1f;
bool refreshRow = m_Timer >= refreshRate;
if (refreshRow)
m_Timer -= refreshRate;
m_Timer += Time.deltaTime;

for (int i = 0; i < row.children.Count; i++)
{
var child = gameObject.transform.GetChild(1).GetChild(i).gameObject;
var active = table.GetColumnVisibility(i);
child.SetActive(active);
if (active && refreshRow)
{
if (child.TryGetComponent<DebugUIHandlerColor>(out var color))
color.UpdateColor();
if (child.TryGetComponent<DebugUIHandlerToggle>(out var toggle))
toggle.UpdateValueLabel();
}
}

// Update previous and next ui handlers to pass over hidden volumes
var item = gameObject.transform.GetChild(1).GetChild(0).gameObject;
var itemWidget = item.GetComponent<DebugUIHandlerWidget>();
DebugUIHandlerWidget previous = null;
for (int i = 0; i < row.children.Count; i++)
{
itemWidget.previousUIHandler = previous;
if (table.GetColumnVisibility(i))
previous = itemWidget;

bool found = false;
for (int j = i + 1; j < row.children.Count; j++)
{
if (table.GetColumnVisibility(j))
{
var child = gameObject.transform.GetChild(1).GetChild(j).gameObject;
var childWidget = child.GetComponent<DebugUIHandlerWidget>();
itemWidget.nextUIHandler = childWidget;
item = child;
itemWidget = childWidget;
i = j - 1;
found = true;
break;
}
}
if (!found)
{
itemWidget.nextUIHandler = null;
break;
}
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public override void OnAction()
/// <summary>
/// Update the label.
/// </summary>
protected virtual void UpdateValueLabel()
internal protected virtual void UpdateValueLabel()
{
if (valueToggle != null)
valueToggle.isOn = m_Field.GetValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal override void SetWidget(DebugUI.Widget widget)
/// <summary>
/// Update the label.
/// </summary>
protected override void UpdateValueLabel()
internal protected override void UpdateValueLabel()
{
base.UpdateValueLabel();
DebugUI.HistoryBoolField field = m_Field as DebugUI.HistoryBoolField;
Expand Down
Loading