What is a Bindable?
A Bindable is an object that can be bound to a Bind object to synchronize its value with other Bindables. It can be used to connect UI elements with game logic scripts, or to synchronize data between different parts of a system.
How it works
A Bindable has a unique identifier called a guid, which is used to identify it within a Bind object. It can be connected to a single Bind object at any point in time.
A Bindable has three connection types:
- Sender – the Bindable only sends value updates to the Bind, when its value changes. It does not receive value updates from the Bind.
- Bidirectional – the Bindable sends value updates to the Bind, when its value changes. It also receives value updates from the Bind.
- Receiver – the Bindable only receives value updates from the Bind. It does not send value updates to the Bind, when its value changes.
A Bindable has a value of type object, called BindyValue that is used to bind a value to a target object and a variable name. This is the value that is synchronized between Bindables that are connected to the same Bind object. BindyValue can be of any type, including custom types. BindyValue has an onValueChanged event that is invoked when its value changes.
On Bind Behavior
When a Bindable is added to a Bind, it can have one of three OnBindBehavior values:
- DoNothing – the Bindable does not send or receive any value.
- SetValue – the Bindable sends its value to the Bind.
- GetValue – the Bindable receives the value from the Bind, by checking the last value sent by the Bind.
A Bindable has three update modes that determine how it updates its value:
- Realtime – the Bindable updates its value every frame, regardless of the frame rate.
- FrameBased – the Bindable updates its value based on the FrameInterval (every X frames).
- TimeBased – the Bindable updates its value based on the TimeInterval (every X seconds).
In summary, a Bindable is a key component of the Bindy system, allowing for easy and flexible synchronization of values between objects.