Table of Contents

Binding Properties

Binding Extensions

The Bindables package adds extension methods to make subscribing, updating, and unsubscribing from Bindables much more concise and convenient. For example all Unity components gain a Bind extension method to invoke a callback when a Bindable changes.

void Start()
{
    this.Bind(Health, v => Debug.Log($"New health: {v}"));
}

Bind will automatically unsubscribe the callback when this is destroyed.

Generating Binding Extensions

You can also configure Bindables to generate extensions for public properties on any Unity type. Go to Tools > Bindables > Settings, check Unity.TextMeshPro, and click Generate Extensions.

Bindable Settings

Now, you can use the BindText extension to assign the health to a TextMeshProUGUI component.

public TextMeshProUGUI MyText;

void Start()
{
    MyText.BindText(Health);
}

You'll find similar extensions every public property on TextMeshProUGUI, such as BindColor, BindFont, BindFontWeight.

Binding Transforms

Often, you don't want to assign the value of a Bindable directly, but transform it somehow before assigning it. All Binding Extensions provide an optional callback you can pass as a transform.

public TextMeshProUGUI HealthText;

void Start()
{
    HealthText.BindText(Health, health => $"Health: {health}");
}

Now the text will be set to "Health: 100" and update automatically with Health changes.

Next we'll learn about more advanced transforms using the Derived methods.