docs.unity3d.com
    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>
    BindableVariable<T>
    BindableVariableAlloc<T>
    Inherited Members
    Object.ToString()
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    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 Equals check.

    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
    IReadOnlyBindableVariable<T>.BindingCount

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

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

    Implements
    IReadOnlyBindableVariable<T>.Subscribe(Action<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.

    Implements
    IReadOnlyBindableVariable<T>.SubscribeAndUpdate(Action<T>)

    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
    IReadOnlyBindableVariable<T>.Task(T, CancellationToken)

    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
    IReadOnlyBindableVariable<T>.Task(Func<T, Boolean>, CancellationToken)

    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
    IReadOnlyBindableVariable<T>.Unsubscribe(Action<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
    Boolean

    True if both values are equal.

    Implements
    IReadOnlyBindableVariable<T>.ValueEquals(T)

    See Also

    BindableVariable<T>
    BindableVariableAlloc<T>
    BindableEnum<T>
    Back to top
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023