Interface IReadOnlyBindableVariable<T>
Bindable variable interface useful for removing write capability from external access, while preserving the ability to subscribe to changes.
Namespace: Unity.XR.CoreUtils .Bindings.Variables
Assembly: Unity.XR.CoreUtils.dll
Syntax
public interface IReadOnlyBindableVariable<T>
Type Parameters
Name | Description |
---|---|
T | The type of the variable value. |
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 IEvent
Declaration
int BindingCount { get; }
Property Value
Type | Description |
---|---|
int |
Value
Get internal variable value.
Declaration
T Value { get; }
Property Value
Type | Description |
---|---|
T |
Methods
Subscribe(Action<T>)
Register callback to the event that is invoked when the value is updated.
Declaration
IEventBinding Subscribe(Action<T> callback)
Parameters
Type | Name | Description |
---|---|---|
Action<T> | callback | Callback to register. |
Returns
Type | Description |
---|---|
IEvent |
IEvent |
SubscribeAndUpdate(Action<T>)
Triggers the callback inline, followed by the Subscribe(Action<T>) function.
Declaration
IEventBinding SubscribeAndUpdate(Action<T> callback)
Parameters
Type | Name | Description |
---|---|---|
Action<T> | callback | Callback to register. |
Returns
Type | Description |
---|---|
IEvent |
IEvent |
Task(Func<T, bool>, CancellationToken)
Wait until predicate is met, or until token is called. A null predicate can be passed to have it await any change.
Declaration
Task<T> Task(Func<T, bool> awaitPredicate, CancellationToken token = default)
Parameters
Type | Name | Description |
---|---|---|
Func<T, bool> | awaitPredicate | Callback to be executed on completion of task. |
Cancellation |
token | Token used to trigger a cancellation of the task. |
Returns
Type | Description |
---|---|
Task<T> | Task to schedule. |
Task(T, CancellationToken)
Wait until BindableVariable is set to awaitState
.
Declaration
Task<T> Task(T awaitState, CancellationToken token = default)
Parameters
Type | Name | Description |
---|---|---|
T | awaitState | Variable state to wait for. |
Cancellation |
token | Token used to trigger a cancellation of the task. |
Returns
Type | Description |
---|---|
Task<T> | Task to schedule. |
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
void Unsubscribe(Action<T> callback)
Parameters
Type | Name | Description |
---|---|---|
Action<T> | callback | Callback to unregister. |
ValueEquals(T)
Evaluates equality with the internal value held by the bindable variable.
Declaration
bool ValueEquals(T other)
Parameters
Type | Name | Description |
---|---|---|
T | other | Other value to compare equality against. |
Returns
Type | Description |
---|---|
bool | True if both values are equal. |