using System;
using UnityEngine.Assertions;
namespace UnityEngine.Rendering
{
///
/// Debug UI Class
///
public partial class DebugUI
{
///
/// Flags for Debug UI widgets.
///
[Flags]
public enum Flags
{
///
/// None.
///
None = 0,
///
/// This widget is Editor only.
///
EditorOnly = 1 << 1,
///
/// This widget is Runtime only.
///
RuntimeOnly = 1 << 2,
///
/// This widget will force the Debug Editor Window refresh.
///
EditorForceUpdate = 1 << 3
}
///
/// Base class for all debug UI widgets.
///
public abstract class Widget
{
// Set to null until it's added to a panel, be careful
///
/// Panels containing the widget.
///
protected Panel m_Panel;
///
/// Panels containing the widget.
///
public virtual Panel panel
{
get { return m_Panel; }
internal set { m_Panel = value; }
}
///
/// Parent container.
///
protected IContainer m_Parent;
///
/// Parent container.
///
public virtual IContainer parent
{
get { return m_Parent; }
internal set { m_Parent = value; }
}
///
/// Flags for the widget.
///
public Flags flags { get; set; }
///
/// Display name.
///
public string displayName { get; set; }
///
/// Tooltip.
///
public string tooltip { get; set; }
///
/// Path of the widget.
///
public string queryPath { get; private set; }
///
/// True if the widget is Editor only.
///
public bool isEditorOnly => flags.HasFlag(Flags.EditorOnly);
///
/// True if the widget is Runtime only.
///
public bool isRuntimeOnly => flags.HasFlag(Flags.RuntimeOnly);
///
/// True if the widget is inactive in the editor (i.e. widget is runtime only and the application is not 'Playing').
///
public bool isInactiveInEditor => (isRuntimeOnly && !Application.isPlaying);
///
/// Optional delegate that can be used to conditionally hide widgets at runtime (e.g. due to state of other widgets).
///
public Func isHiddenCallback;
///
/// If shouldHideDelegate has been set and returns true, the widget is hidden from the UI.
///
public bool isHidden => isHiddenCallback?.Invoke() ?? false;
internal virtual void GenerateQueryPath()
{
queryPath = displayName.Trim();
if (m_Parent != null)
queryPath = m_Parent.queryPath + " -> " + queryPath;
}
///
/// Returns the hash code of the widget.
///
/// The hash code of the widget.
public override int GetHashCode()
{
return queryPath.GetHashCode();
}
///
/// Helper struct to allow more compact initialization of widgets.
///
public struct NameAndTooltip
{
///
/// The name
///
public string name;
///
/// The tooltip
///
public string tooltip;
}
///
/// Helper setter to allow more compact initialization of widgets.
///
public NameAndTooltip nameAndTooltip
{
set
{
displayName = value.name;
tooltip = value.tooltip;
}
}
}
///
/// Interface for widgets that can contain other widgets.
///
public interface IContainer
{
///
/// List of children of the container.
///
ObservableList children { get; }
///
/// Display name of the container.
///
string displayName { get; set; }
///
/// Path of the container.
///
string queryPath { get; }
}
///
/// Any widget that implements this will be considered for serialization (only if the setter is set and thus is not read-only)
///
public interface IValueField
{
///
/// Return the value of the field.
///
/// Value of the field.
object GetValue();
///
/// Set the value of the field.
///
/// Input value.
void SetValue(object value);
///
/// Function used to validate the value when setting it.
///
///
///
object ValidateValue(object value);
}
// Miscellaneous
///
/// Button widget.
///
public class Button : Widget
{
///
/// Action performed by the button.
///
public Action action { get; set; }
}
///
/// Read only Value widget.
///
public class Value : Widget
{
///
/// Getter for the Value.
///
public Func