Skip to content
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 @@ -654,6 +654,81 @@ public override bool OnGUI(DebugUI.Widget widget, DebugState state)
}
}

/// <summary>
/// Builtin Drawer for <see cref="DebugUI.ObjectField"> Items.
/// </summary>
[DebugUIDrawer(typeof(DebugUI.ObjectField))]
public sealed class DebugUIDrawerObjectField : DebugUIDrawer
{
/// <summary>
/// OnGUI implementation for Object DebugUIDrawer.
/// </summary>
/// <param name="widget">DebugUI <see cref="DebugUI.Widget">.</param>
/// <param name="state">Debug State associated with the Debug Item.</param>
/// <returns>The state of the widget.</returns>
public override bool OnGUI(DebugUI.Widget widget, DebugState state)
{
var w = Cast<DebugUI.ObjectField>(widget);

EditorGUI.BeginChangeCheck();

var rect = PrepareControlRect();
var value = EditorGUI.ObjectField(rect, EditorGUIUtility.TrTextContent(w.displayName, w.tooltip), w.GetValue(), w.type, true);

if (EditorGUI.EndChangeCheck())
Apply(w, state, value);

return true;
}
}

/// <summary>
/// Builtin Drawer for <see cref="DebugUI.ObjectListField"> Items.
/// </summary>
[DebugUIDrawer(typeof(DebugUI.ObjectListField))]
public sealed class DebugUIDrawerObjectListField : DebugUIDrawer
{
/// <summary>
/// OnGUI implementation for ObjectList DebugUIDrawer.
/// </summary>
/// <param name="widget">DebugUI <see cref="DebugUI.Widget">.</param>
/// <param name="state">Debug State associated with the Debug Item.</param>
/// <returns>The state of the widget.</returns>
public override bool OnGUI(DebugUI.Widget widget, DebugState state)
{
var w = Cast<DebugUI.ObjectListField>(widget);
var objects = w.GetValue();

float height = Math.Max(objects != null ? objects.Length : 0, 1) * DebugWindow.Styles.singleRowHeight;
var rect = PrepareControlRect(height);

rect = EditorGUI.PrefixLabel(rect, EditorGUIUtility.TrTextContent(widget.displayName));

EditorGUI.BeginChangeCheck();
DoObjectList(rect, w, objects);
if (EditorGUI.EndChangeCheck())
Apply(w, state, objects);

return true;
}

internal static void DoObjectList(Rect rect, DebugUI.ObjectListField widget, UnityEngine.Object[] objects)
{
if (objects == null || objects.Length == 0)
{
EditorGUI.LabelField(rect, GUIContent.none, EditorGUIUtility.TrTextContent("Empty"));
return;
}

rect.height = EditorGUIUtility.singleLineHeight;
for (int i = 0; i < objects.Length; i++)
{
objects[i] = EditorGUI.ObjectField(rect, GUIContent.none, objects[i], widget.type, true);
rect.y += DebugWindow.Styles.singleRowHeight;
}
}
}

/// <summary>
/// Builtin Drawer for MessageBox Items.
/// </summary>
Expand Down Expand Up @@ -782,23 +857,29 @@ public sealed class DebugUIDrawerTable : DebugUIDrawer
/// <returns>The state of the widget.</returns>
public override bool OnGUI(DebugUI.Widget widget, DebugState state)
{
const float k_ScrollBarHeight = 15;

var w = Cast<DebugUI.Table>(widget);
var header = w.Header;
var visible = header.state.visibleColumns;

float contentHeight = 0.0f;
foreach (DebugUI.Table.Row row in w.children)
contentHeight += row != null ? GetRowHeight(row, visible) : EditorGUIUtility.singleLineHeight;

// Put some space before the array
PrepareControlRect(EditorGUIUtility.singleLineHeight * 0.5f);

// Draw an outline around the table
var rect = EditorGUI.IndentedRect(PrepareControlRect(header.height + (w.children.Count + 1) * EditorGUIUtility.singleLineHeight));
var rect = EditorGUI.IndentedRect(PrepareControlRect(header.height + contentHeight + k_ScrollBarHeight));
rect = DrawOutline(rect);

// Compute rects
var headerRect = new Rect(rect.x, rect.y, rect.width, header.height);
var contentRect = new Rect(rect.x, headerRect.yMax, rect.width, rect.height - headerRect.height);
var viewRect = new Rect(contentRect.x, contentRect.y, header.state.widthOfAllVisibleColumns, contentRect.height);
var rowRect = contentRect;
rowRect.height = EditorGUIUtility.singleLineHeight;
viewRect.height -= EditorGUIUtility.singleLineHeight;
viewRect.height -= k_ScrollBarHeight;

// Show header
header.OnGUI(headerRect, Mathf.Max(w.scroll.x, 0f));
Expand All @@ -807,24 +888,27 @@ public override bool OnGUI(DebugUI.Widget widget, DebugState state)
w.scroll = GUI.BeginScrollView(contentRect, w.scroll, viewRect);
{
var columns = header.state.columns;
var visible = header.state.visibleColumns;
for (int r = 0; r < w.children.Count; r++)
{
var row = Cast<DebugUI.Container>(w.children[r]);
rowRect.x = contentRect.x;
rowRect.width = columns[0].width;
rowRect.height = (row is DebugUI.Table.Row tableRow) ? GetRowHeight(tableRow, visible) : EditorGUIUtility.singleLineHeight;

rowRect.xMin += 2;
rowRect.xMax -= 2;
EditorGUI.LabelField(rowRect, GUIContent.none, EditorGUIUtility.TrTextContent(row.displayName));
EditorGUI.LabelField(rowRect, GUIContent.none, EditorGUIUtility.TrTextContent(row.displayName), DebugWindow.Styles.centeredLeft);
rowRect.xMin -= 2;
rowRect.xMax += 2;

for (int c = 1; c < visible.Length; c++)
using (new EditorGUI.DisabledScope(w.isReadOnly))
{
rowRect.x += rowRect.width;
rowRect.width = columns[visible[c]].width;
DisplayChild(rowRect, row.children[visible[c] - 1], w.isReadOnly);
for (int c = 1; c < visible.Length; c++)
{
rowRect.x += rowRect.width;
rowRect.width = columns[visible[c]].width;
DisplayChild(rowRect, row.children[visible[c] - 1]);
}
}
rowRect.y += rowRect.height;
}
Expand All @@ -834,6 +918,19 @@ public override bool OnGUI(DebugUI.Widget widget, DebugState state)
return false;
}

internal float GetRowHeight(DebugUI.Table.Row row, int[] visibleColumns)
{
float height = EditorGUIUtility.singleLineHeight;
for (int c = 1; c < visibleColumns.Length; c++)
{
var child = row.children[visibleColumns[c] - 1] as DebugUI.ObjectListField;
if (child == null || child.GetValue() == null)
continue;
height = Mathf.Max(height, child.GetValue().Length * DebugWindow.Styles.singleRowHeight);
}
return height;
}

internal Rect DrawOutline(Rect rect)
{
if (Event.current.type != EventType.Repaint)
Expand All @@ -853,7 +950,7 @@ internal Rect DrawOutline(Rect rect)
return new Rect(rect.x + size, rect.y + size, rect.width - 2 * size, rect.height - 2 * size);
}

internal void DisplayChild(Rect rect, DebugUI.Widget child, bool disable)
internal void DisplayChild(Rect rect, DebugUI.Widget child)
{
rect.xMin += 2;
rect.xMax -= 2;
Expand All @@ -865,14 +962,22 @@ internal void DisplayChild(Rect rect, DebugUI.Widget child, bool disable)
else if (child.GetType() == typeof(DebugUI.ColorField))
{
var widget = Cast<DebugUI.ColorField>(child);
using (new EditorGUI.DisabledScope(disable))
EditorGUI.ColorField(rect, GUIContent.none, widget.GetValue(), false, widget.showAlpha, widget.hdr);
EditorGUI.ColorField(rect, GUIContent.none, widget.GetValue(), false, widget.showAlpha, widget.hdr);
}
else if (child.GetType() == typeof(DebugUI.BoolField))
{
var widget = Cast<DebugUI.BoolField>(child);
using (new EditorGUI.DisabledScope(disable))
EditorGUI.Toggle(rect, GUIContent.none, widget.GetValue());
EditorGUI.Toggle(rect, GUIContent.none, widget.GetValue());
}
else if (child.GetType() == typeof(DebugUI.ObjectField))
{
var widget = Cast<DebugUI.ObjectField>(child);
EditorGUI.ObjectField(rect, GUIContent.none, widget.GetValue(), widget.type, true);
}
else if (child.GetType() == typeof(DebugUI.ObjectListField))
{
var widget = Cast<DebugUI.ObjectListField>(child);
DebugUIDrawerObjectListField.DoObjectList(rect, widget, widget.GetValue());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,9 @@ public class Styles
public readonly GUIStyle sectionHeader = new GUIStyle(EditorStyles.largeLabel);
public readonly Color skinBackgroundColor;

public static GUIStyle centeredLeft = new GUIStyle(EditorStyles.label) { alignment = TextAnchor.MiddleLeft };
public static float singleRowHeight = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;

public static int foldoutColumnWidth = 70;

public Styles()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,28 @@ public class Vector4Field : Field<Vector4>
public int decimals = 3;
}

/// <summary>
/// Object field.
/// </summary>
public class ObjectField : Field<Object>
{
/// <summary>
/// Object type.
/// </summary>
public Type type = typeof(Object);
}

/// <summary>
/// Object list field.
/// </summary>
public class ObjectListField : Field<Object[]>
{
/// <summary>
/// Objects type.
/// </summary>
public Type type = typeof(Object);
}

/// <summary>
/// Simple message box widget, providing a couple of different styles.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,9 @@ MonoBehaviour:
- type: UnityEngine.Rendering.DebugUI+ValueTuple, Unity.RenderPipelines.Core.Runtime,
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
prefab: {fileID: 224720214277421396, guid: a2148203dd960814ca5db0c293ceda35, type: 3}
- type: UnityEngine.Rendering.DebugUI+ObjectField, Unity.RenderPipelines.Core.Runtime,
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
prefab: {fileID: 224720214277421396, guid: a87cfaef648f17c41b568e842e068c51, type: 3}
- type: UnityEngine.Rendering.DebugUI+ObjectListField, Unity.RenderPipelines.Core.Runtime,
Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
prefab: {fileID: 224224135738715566, guid: ad83bc56407925d44a77a5bd01cd6783, type: 3}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using UnityEngine.UI;

namespace UnityEngine.Rendering.UI
{
/// <summary>
/// DebugUIHandler for object widget.
/// </summary>
public class DebugUIHandlerObject : DebugUIHandlerWidget
{
/// <summary>Name of the value field.</summary>
public Text nameLabel;
/// <summary>Value of the value field.</summary>
public Text valueLabel;

internal override void SetWidget(DebugUI.Widget widget)
{
base.SetWidget(widget);
var field = CastWidget<DebugUI.ObjectField>();
nameLabel.text = field.displayName;
valueLabel.text = field.GetValue().name;
}

/// <summary>
/// OnSelection implementation.
/// </summary>
/// <param name="fromNext">True if the selection wrapped around.</param>
/// <param name="previous">Previous widget.</param>
/// <returns>True if the selection is allowed.</returns>
public override bool OnSelection(bool fromNext, DebugUIHandlerWidget previous)
{
nameLabel.color = colorSelected;
valueLabel.color = colorSelected;
return true;
}

/// <summary>
/// OnDeselection implementation.
/// </summary>
public override void OnDeselection()
{
nameLabel.color = colorDefault;
valueLabel.color = colorDefault;
}
}
}

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

Loading