using System;
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
{
///
/// 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.
///
public bool editorForceUpdate { get { return (flags & Flags.EditorForceUpdate) != 0; } }
///
/// List of children.
///
public ObservableList children { get; private set; }
///
/// Callback used when the panel is set dirty.
///
public event Action onSetDirty = delegate { };
///
/// Constructor.
///
public Panel()
{
children = new ObservableList();
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);
}
///
/// Returns the hash code of the panel.
///
/// Hash code of the panel.
public override int GetHashCode()
{
int hash = 17;
hash = hash * 23 + displayName.GetHashCode();
int numChildren = children.Count;
for (int i = 0; i < numChildren; i++)
hash = hash * 23 + children[i].GetHashCode();
return hash;
}
///
/// 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);
}
}
}