Class BindableVariableBase<T>
Abstract class which contains a member variable of type T
and provides a binding API to data changes.
Inherited Members
Namespace: Unity.XR.CoreUtils.Bindings.Variables
Syntax
[Serializable]
public abstract class BindableVariableBase<T> : IReadOnlyBindableVariable<T>
Type Parameters
Name | Description |
---|---|
T | The type of the variable value. |
Constructors
BindableVariableBase(T, Boolean, Func<T, T, Boolean>, Boolean)
Constructor for bindable variable, which is a variable that notifies listeners when the internal value changes.
Declaration
protected BindableVariableBase(T initialValue = null, bool checkEquality = true, Func<T, T, bool> equalityMethod = null, bool startInitialized = false)
Parameters
Type | Name | Description |
---|---|---|
T | initialValue | Value to initialize variable with. Defaults to type default. |
Boolean | checkEquality | Setting true checks whether to compare new value to old before triggering callback. Defaults to true. |
Func<T, T, Boolean> | equalityMethod | Func used to provide custom equality checking behavior. Defaults to |
Boolean | startInitialized | Setting false results in initial value setting will trigger registered callbacks, regardless of whether the value is the same as the initial one. Defaults to false. |
Properties
BindingCount
Get number of subscribed binding callbacks. Note that if you manually call Unsubscribe(Action<T>) with the same callback several times this value may be inaccurate. For best results leverage the IEventBinding returned by the subscribe call and use that to unsubscribe as needed.
Declaration
public int BindingCount { get; }
Property Value
Type | Description |
---|---|
Int32 |
Implements
Value
The internal variable value. When setting the value, subscribers may be notified. The subscribers will not be notified if this variable is initialized, is configured to check for equality, and the new value is equivalent.
Declaration
public T Value { get; set; }
Property Value
Type | Description |
---|---|
T |
Implements
See Also
Methods
BroadcastValue()
Triggers a callback for all subscribed listeners with the current internal variable value.
Declaration
public void BroadcastValue()
SetValueWithoutNotify(T)
Sets the internal variable value and, even if different, doesn't notify of the change to subscribed listeners. This is intended to be used by developers to allow for setting multiple bindable variables before broadcasting any of them individually.
Declaration
public bool SetValueWithoutNotify(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | The new value. |
Returns
Type | Description |
---|---|
Boolean | Returns true if a broadcast would have normally occurred if the property setter was used instead. |
See Also
Subscribe(Action<T>)
Register callback to the event that is invoked when the value is updated.
Declaration
public IEventBinding Subscribe(Action<T> callback)
Parameters
Type | Name | Description |
---|---|---|
Action<T> | callback | Callback to register. |
Returns
Type | Description |
---|---|
IEventBinding | IEventBinding which allows for safe and easy bind, unbind, and clear functions. |
Implements
SubscribeAndUpdate(Action<T>)
Triggers the callback inline, followed by the Subscribe(Action<T>) function.
Declaration
public IEventBinding SubscribeAndUpdate(Action<T> callback)
Parameters
Type | Name | Description |
---|---|---|
Action<T> | callback | Callback to register. |
Returns
Type | Description |
---|---|
IEventBinding | IEventBinding which allows for safe and easy bind, unbind, and clear functions. |
Implements
Task(T, CancellationToken)
Wait until BindableVariable is set to awaitState
.
Declaration
public Task<T> Task(T awaitState, CancellationToken token = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
T | awaitState | Variable state to wait for. |
CancellationToken | token | Token used to trigger a cancellation of the task. |
Returns
Type | Description |
---|---|
Task<T> | Task to schedule. |
Implements
Task(Func<T, Boolean>, CancellationToken)
Wait until predicate is met, or until token is called. A null predicate can be passed to have it await any change.
Declaration
public Task<T> Task(Func<T, bool> awaitPredicate, CancellationToken token = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
Func<T, Boolean> | awaitPredicate | Callback to be executed on completion of task. |
CancellationToken | token | Token used to trigger a cancellation of the task. |
Returns
Type | Description |
---|---|
Task<T> | Task to schedule. |
Implements
Unsubscribe(Action<T>)
Manually unsubscribe callback from Value update event, but no protections from multiple unsubscribe calls. If unsubscribing multiple times, reference count may not be accurate.
Declaration
public void Unsubscribe(Action<T> callback)
Parameters
Type | Name | Description |
---|---|---|
Action<T> | callback |
Implements
ValueEquals(T)
Evaluates equality with the internal value held by the bindable variable.
Declaration
public virtual bool ValueEquals(T other)
Parameters
Type | Name | Description |
---|---|---|
T | other | Other value to compare equality against. |
Returns
Type | Description |
---|---|
Boolean | True if both values are equal. |