Game.UI.Widgets.SettableBindings
Assembly:
Assembly-CSharp
Namespace:
Game.UI.Widgets
Type:
class
Base:
IWidgetBindingFactory
Summary:
SettableBindings is a small binding-factory used by the UI binding system to produce a trigger-style binding named "setValue". When invoked, the binding resolves a widget path via the provided IReader
Fields
- None
This class does not declare any instance or static fields.
Properties
- None
There are no public properties on this type.
Constructors
public SettableBindings()
The default constructor. The class does not perform any initialization; it is essentially a stateless factory object.
Methods
public IEnumerable<IBinding> CreateBindings(string group, IReader<IWidget> pathResolver, ValueChangedCallback onValueChanged)
CreateBindings returns one or more bindings for the specified binding group. Implementation details:- Produces a single RawTriggerBinding for the trigger name "setValue".
- When the trigger fires, the binding callback receives an IJsonReader instance (reader).
- The callback uses pathResolver.Read(reader, out var value) to resolve a widget reference from the JSON payload.
- If the resolved value is an ISettable:
- Calls settable.SetValue(reader) to let the widget consume the reader and update its state.
- If settable.shouldTriggerValueChangedEvent is true, invokes onValueChanged(value) to notify the binding system that the widget's value changed.
- If the resolved value is null or does not implement ISettable:
- Calls reader.SkipValue() to advance the reader past the value.
- Logs an error via UnityEngine.Debug.LogError with either "Widget does not implement ISettable" (when value != null) or "Invalid widget path" (when value == null).
- The factory is stateless and safe to reuse across multiple bindings/groups.
Notes and expectations:
- The method returns an IEnumerable
Usage Example
// Example: enumerate bindings created by the factory and register them with a hypothetical binding system.
var factory = new SettableBindings();
// pathResolver and onValueChanged must be provided by the UI binding system.
// Here are placeholders to show how CreateBindings is called:
IReader<IWidget> pathResolver = /* obtain from UI framework */;
ValueChangedCallback onValueChanged = (obj) => {
// react to value changes (obj is the widget instance that changed)
};
// Create and register bindings for group "myGroup"
foreach (var binding in factory.CreateBindings("myGroup", pathResolver, onValueChanged))
{
// Register binding with the UI binding manager (pseudo-code).
// UiBindingManager.Register(binding);
}
Additional example explanation: - When the UI sends a trigger named "setValue" with a payload that resolves to a widget implementing ISettable, that widget's SetValue(IJsonReader) will be executed with the JSON payload reader. - If the widget's shouldTriggerValueChangedEvent property is true after SetValue returns, the provided onValueChanged callback will be invoked with the widget instance so the rest of the binding system can react (update bindings, propagate changes, etc.).