docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class BindableVariableBase<T>

    Abstract class which contains a member variable of type T and provides a binding API to data changes.

    Inheritance
    object
    BindableVariableBase<T>
    BindableEnum<T>
    BindableVariableAlloc<T>
    BindableVariable<T>
    Implements
    IReadOnlyBindableVariable<T>
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Unity.XR.CoreUtils.Bindings.Variables
    Assembly: Unity.XR.CoreUtils.dll
    Syntax
    [Serializable]
    public abstract class BindableVariableBase<T> : IReadOnlyBindableVariable<T>
    Type Parameters
    Name Description
    T

    The type of the variable value.

    Constructors

    BindableVariableBase(T, bool, Func<T, T, bool>, bool)

    Constructor for bindable variable, which is a variable that notifies listeners when the internal value changes.

    Declaration
    protected BindableVariableBase(T initialValue = default, 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.

    bool checkEquality

    Setting true checks whether to compare new value to old before triggering callback. Defaults to true.

    Func<T, T, bool> equalityMethod

    Func used to provide custom equality checking behavior. Defaults to Equals check.

    bool 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.

    See Also
    BindableVariable<T>
    BindableVariableAlloc<T>
    BindableEnum<T>

    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
    int
    See Also
    BindableVariable<T>
    BindableVariableAlloc<T>
    BindableEnum<T>

    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
    See Also
    SetValueWithoutNotify(T)

    Methods

    BroadcastValue()

    Triggers a callback for all subscribed listeners with the current internal variable value.

    Declaration
    public void BroadcastValue()
    See Also
    BindableVariable<T>
    BindableVariableAlloc<T>
    BindableEnum<T>

    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
    bool

    Returns true if a broadcast would have normally occurred if the property setter was used instead. Always returns false if no listeners are subscribed.

    See Also
    Value

    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.

    See Also
    BindableVariable<T>
    BindableVariableAlloc<T>
    BindableEnum<T>

    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.

    See Also
    BindableVariable<T>
    BindableVariableAlloc<T>
    BindableEnum<T>

    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
    public 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.

    CancellationToken token

    Token used to trigger a cancellation of the task.

    Returns
    Type Description
    Task<T>

    Task to schedule.

    See Also
    BindableVariable<T>
    BindableVariableAlloc<T>
    BindableEnum<T>

    Task(T, CancellationToken)

    Wait until BindableVariable is set to awaitState.

    Declaration
    public Task<T> Task(T awaitState, CancellationToken token = default)
    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.

    See Also
    BindableVariable<T>
    BindableVariableAlloc<T>
    BindableEnum<T>

    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

    Callback to unregister.

    See Also
    BindableVariable<T>
    BindableVariableAlloc<T>
    BindableEnum<T>

    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
    bool

    True if both values are equal.

    See Also
    BindableVariable<T>
    BindableVariableAlloc<T>
    BindableEnum<T>

    Implements

    IReadOnlyBindableVariable<T>

    See Also

    BindableVariable<T>
    BindableVariableAlloc<T>
    BindableEnum<T>
    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)