Game.UI.Editor.ProgressIndicator
Assembly:
Game
Namespace:
Game.UI.Editor
Type:
class
Base:
NamedWidgetWithTooltip
Summary:
ProgressIndicator is a UI widget used in the editor to display a progress indicator with three visual states: Loading, Success, and Failure. It supports data-binding through delegate properties so external code can supply the current progress (float) and state (enum). The widget tracks internal cached values (m_Progress and m_State) and signals property changes when the provided delegates return new values. When no progress delegate is provided the widget is treated as indeterminate. The class serializes its visible state via WriteProperties for UI layout/serialization.
Fields
-
private float m_Progress = 1f
This caches the last-known progress value. Default is 1.0f. The Update method compares incoming progress via Mathf.Approximately and sets widget change flags when it changes. -
private State m_State
This caches the last-known State (Loading, Success, Failure). The field is updated when the bound state delegate returns a different value, causing property changes to be signaled.
Properties
-
public Func<float> progress { get; set; }
Delegate used to provide the current progress value from external code. If null, the indicator is considered indeterminate. Values are compared to m_Progress with Mathf.Approximately before signalling a property update. -
public Func<State> state { get; set; }
Delegate used to provide the current indicator state (Loading, Success, Failure). When the returned value differs from m_State, m_State is updated and property change notifications are produced.
Constructors
public ProgressIndicator()
Implicit default constructor. The class uses field initializers for defaults (m_Progress = 1f). No additional runtime initialization is required by the constructor.
Methods
-
protected override WidgetChanges Update()
Checks the bound delegates (state and progress) and updates internal cached fields. Calls base.Update() and accumulates WidgetChanges. For the state delegate: if a new value differs from m_State the method updates m_State and marks WidgetChanges.Properties. For the progress delegate: it reads a float and uses Mathf.Approximately to determine if the value has changed; if so it updates m_Progress and marks WidgetChanges.Properties. Returns the aggregated WidgetChanges indicating which parts of the widget have changed. -
protected override void WriteProperties(IJsonWriter writer)
Serializes the widget properties to the provided writer. Calls base.WriteProperties(writer) then writes: - "state" as an int (the enum value of m_State),
- "progress" as a float (m_Progress),
- "indeterminate" as a bool (true if progress delegate is null). This is used for UI serialization/communication of the widget state.
Usage Example
// Example: bind an external progress source and state provider to the widget.
ProgressIndicator indicator = new ProgressIndicator();
// Provide a dynamic progress value (0..1).
float currentProgress = 0f;
indicator.progress = () => currentProgress;
// Provide a dynamic state value.
indicator.state = () =>
{
if (currentProgress < 1f) return ProgressIndicator.State.Loading;
return ProgressIndicator.State.Success;
};
// Somewhere in update logic, update currentProgress and let the widget pick it up.
currentProgress = 0.5f; // ProgressIndicator.Update() will detect the change and mark Properties.