#if ENABLE_UIELEMENTS_MODULE && UNITY_ENABLE_CHECKS
#define ENABLE_RENDERING_DEBUGGER_UI
#endif
using System;
#if UNITY_EDITOR
using UnityEditor;
#endif
#if ENABLE_RENDERING_DEBUGGER_UI
using UnityEngine.UIElements;
#endif
namespace UnityEngine.Rendering
{
public partial class DebugUI
{
// Root panel class - we don't want to extend Container here because we need a clear
// separation between debug panels and actual widgets
///
/// Root panel class.
///
public class Panel : IContainer, IComparable
{
#if ENABLE_RENDERING_DEBUGGER_UI
private VisualElement m_HelpButton;
///
public VisualElement Create(DebugUI.Context context)
{
VisualElement container = new GroupBox()
{
text = displayName,
name = displayName + "_Content"
};
var label = container.Q(className: "unity-group-box__label");
label.AddToClassList("debug-window-header-title");
label.AddToClassList("debug-window-search-filter-target");
label.AddToClassList("debug-window-header-row");
#if UNITY_EDITOR
if (EditorGUIUtility.isProSkin)
{
container.AddToClassList("dark");
}
m_HelpButton = new UIElements.Button(() => Help.BrowseURL(documentationUrl));
m_HelpButton.tooltip = $"Open Reference for {displayName} debugger panel.";
m_HelpButton.SetEnabled(!string.IsNullOrEmpty(documentationUrl));
m_HelpButton.AddToClassList("debug-window-help-button");
label.Add(m_HelpButton);
#endif
container.AddToClassList("debug-window-tab-content");
container.AddToClassList("unity-inspector-element");
var content = new VisualElement();
foreach (var child in children)
{
if (context == Context.Editor && child.isRuntimeOnly)
continue;
if (context.IsAnyRuntimeContext() && child.isEditorOnly)
continue;
var childUIElement = child.ToVisualElement(context);
if (childUIElement != null)
content.Add(childUIElement);
}
container.Add(content);
return container;
}
#endif
///
/// Widget flags for this panel.
///
public Flags flags { get; set; }
///
/// Display name of the panel.
///
public string displayName { get; set; }
///
/// Group index of the panel.
///
public int groupIndex { get; set; }
///
/// Path of the panel.
///
public string queryPath { get { return displayName; } }
///
/// Specify if the panel is editor only.
///
public bool isEditorOnly { get { return (flags & Flags.EditorOnly) != 0; } }
///
/// Specify if the panel is runtime only.
///
public bool isRuntimeOnly { get { return (flags & Flags.RuntimeOnly) != 0; } }
///
/// Returns true if the panel is inactive in the editor.
///
public bool isInactiveInEditor { get { return (isRuntimeOnly && !Application.isPlaying); } }
///
/// Returns true if the panel should always be updated.
///
[Obsolete("This is no longer used. #from(6000.5)")]
public bool editorForceUpdate => false;
///
/// List of children.
///
public ObservableList children { get; private set; }
///
/// Callback used when the panel is set dirty.
///
public event Action onSetDirty = delegate { };
#if UNITY_EDITOR
private string m_DocumentationURL;
public string documentationUrl {
get => m_DocumentationURL;
set
{
if (m_DocumentationURL == value)
return;
m_DocumentationURL = value;
#if ENABLE_RENDERING_DEBUGGER_UI
m_HelpButton?.SetEnabled(!string.IsNullOrEmpty(m_DocumentationURL));
#endif
}
}
#endif
///
/// Constructor.
///
public Panel()
{
children = new ObservableList(0, (widget, widget1) => widget.order.CompareTo(widget1.order));
children.ItemAdded += OnItemAdded;
children.ItemRemoved += OnItemRemoved;
}
///
/// Callback used when a child is added.
///
/// Sender widget.
/// List of added children.
protected virtual void OnItemAdded(ObservableList sender, ListChangedEventArgs e)
{
if (e.item != null)
{
e.item.panel = this;
e.item.parent = this;
}
SetDirty();
}
///
/// Callback used when a child is removed.
///
/// Sender widget.
/// List of removed children.
protected virtual void OnItemRemoved(ObservableList sender, ListChangedEventArgs e)
{
if (e.item != null)
{
e.item.panel = null;
e.item.parent = null;
}
SetDirty();
}
///
/// Set the panel dirty.
///
public void SetDirty()
{
int numChildren = children.Count;
for (int i = 0; i < numChildren; i++)
children[i].GenerateQueryPath();
onSetDirty(this);
}
///
/// Comparison function.
///
/// Panel to compare to.
/// True if the panels share the same group index.
int IComparable.CompareTo(Panel other) => other == null ? 1 : groupIndex.CompareTo(other.groupIndex);
internal bool TryFindChild(string childDisplayName, out T foundChild)
where T : DebugUI.Widget
{
foundChild = null;
if (!string.IsNullOrEmpty(childDisplayName))
{
foreach (var child in children)
{
if (child.displayName.Equals(childDisplayName) && child is T castedChild)
{
foundChild = castedChild;
break;
}
}
}
return foundChild != null;
}
}
}
}