using System;
namespace UnityEngine.Rendering.UI
{
///
/// Base class for handling UI actions for widgets.
///
public class DebugUIHandlerWidget : MonoBehaviour
{
///
/// Default widget color.
///
[HideInInspector]
public Color colorDefault = new Color(0.8f, 0.8f, 0.8f, 1f);
///
/// Selected widget color.
///
[HideInInspector]
public Color colorSelected = new Color(0.25f, 0.65f, 0.8f, 1f);
///
/// Parent widget UI Handler.
///
public DebugUIHandlerWidget parentUIHandler { get; set; }
///
/// Previous widget UI Handler.
///
public DebugUIHandlerWidget previousUIHandler { get; set; }
///
/// Next widget UI Handler.
///
public DebugUIHandlerWidget nextUIHandler { get; set; }
///
/// Associated widget.
///
protected DebugUI.Widget m_Widget;
///
/// OnEnable implementation.
///
protected virtual void OnEnable() { }
internal virtual void SetWidget(DebugUI.Widget widget)
{
m_Widget = widget;
}
internal DebugUI.Widget GetWidget()
{
return m_Widget;
}
///
/// Casts the widget to the correct type.
///
/// Type of the widget.
/// Properly cast reference to the widget.
protected T CastWidget()
where T : DebugUI.Widget
{
var casted = m_Widget as T;
string typeName = m_Widget == null ? "null" : m_Widget.GetType().ToString();
if (casted == null)
throw new InvalidOperationException("Can't cast " + typeName + " to " + typeof(T));
return casted;
}
///
/// OnSelection implementation.
///
/// True if the selection wrapped around.
/// Previous widget.
/// True if the selection is allowed.
public virtual bool OnSelection(bool fromNext, DebugUIHandlerWidget previous)
{
return true;
}
///
/// OnDeselection implementation.
///
public virtual void OnDeselection() { }
///
/// OnAction implementation.
///
public virtual void OnAction() { }
///
/// OnIncrement implementation.
///
/// True if incrementing fast.
public virtual void OnIncrement(bool fast) { }
///
/// OnDecrement implementation.
///
/// Trye if decrementing fast.
public virtual void OnDecrement(bool fast) { }
///
/// Previous implementation.
///
/// Previous widget UI handler, parent if there is none.
public virtual DebugUIHandlerWidget Previous()
{
if (previousUIHandler != null)
return previousUIHandler;
if (parentUIHandler != null)
return parentUIHandler;
return null;
}
///
/// Next implementation.
///
/// Next widget UI handler, parent if there is none.
public virtual DebugUIHandlerWidget Next()
{
if (nextUIHandler != null)
return nextUIHandler;
if (parentUIHandler != null)
{
var p = parentUIHandler;
while (p != null)
{
var n = p.nextUIHandler;
if (n != null)
return n;
p = p.parentUIHandler;
}
}
return null;
}
}
}