LayerProcGen v0.1.0
Layer-based infinite procedural generation
|
The central class in a system for quickly specifying debug options. More...
Inherited by DebugButton, and DebugFoldout.
Public Member Functions | |
void | HandleClick () |
virtual void | UpdateAnimValue (float delta) |
Static Public Member Functions | |
static void | UpdateAnimValues (float timeDelta) |
Public Attributes | |
DebugFoldout | parent |
Static Public Attributes | |
static DebugFoldout | root = DebugFoldout.CreateRoot() |
Static Protected Member Functions | |
static void | NotifyUIChanged () |
Properties | |
bool | hidden [get, set] |
string | name [get, protected set] |
Events | |
static Action | UIChanged |
The central class in a system for quickly specifying debug options.
The functionality primarily resides in this class and the derived classes, DebugToggle, DebugRadioButton, DebugFoldout, DebugButton.
Disabling a DebugToggle temporarily disables all child toggles under it, and also hides them (as well as other control types under it).
Collaping a DebugFoldout (a disclosure widget) also hides all child controls under it, but does not affect their enabled state.
A DebugRadioButton looks and behaves the same as a toggle, except that when it's enabled, it disables all sibling radio buttons, and clicking an already enabled radio button has no effect.
A DebugButton is a simple button which you can register a callback to.
Debug options are specified with a path parameter, and the UI for the debug options automatically displays the options in a hierarchy based on those paths.
Example specification:
The above code would implicitly create a foldout called "Layers", with an implicitly created child Toggle called "ExampleLayer", with a child toggle called "Radiuses", which is the one returned by the function.
The paths are divided by forward slashes /
. Each parent control is either a toggle or a foldout. Foldouts are created by prepending the name with a greater-than sign >
(mimicking the look of a foldout/disclosure triangle).
If the same control is created from multiple places, either explicitly or implicitly, they will reference the same control, so that no duplicates are created.
The value of a DebugToggle or DebugRadioButton is checked via its enabled property.
It's also possible to register callbacks instead of checking the enabled property on the fly.
While the core DebugOption functionality is not Unity-dependent, the front-end for interacting with the controls is.
Debug Options component
Add the DebugOptions component to a RectTransform somewhere under a Canvas, and the debug options will be displayed within the RectTransform rect during Play Mode and in builds. The component uses IMGUI, the RectTransform is just for layout. Alternatively, you can call the static method DebugOptions.DrawDebugOptions(Rect rect)
from an OnGUI
method of your own Unity component code.
Debug Options window
The DebugOptionsWindow is a Unity editor window that displays the debug options. When running the game in Play Mode in the Unity editor, this makes it possible to use the debug options without displaying them in the game itself. This is particularly useful for recording polished videos. The window is opened with the menu Window > Debug Options
.
Similar classes could be made for drawing the debug options under different frameworks than Unity, especially if they support immediate-mode UI.