Skip to content

Utility components for quickly binding data values to views.

License

Notifications You must be signed in to change notification settings

coryleach/UnityBindings

Repository files navigation

Gameframe.Bindings 👋

Codacy Badge GitHub release (latest by date including pre-releases) openupm license

twitter

This is a library of binding components that allow you to quickly wire data sources to target properties via the inspector.

Binding changes propagate via the System.ComponentModel.INotifyPropertyChanged interface but the included binding components will also refresh their target properties in OnEnable.
A general purpose ComponentBinding monobehaviour is included to wire any two UnityEngine.Objects together as well as a TextBinding for quick and simple binding to text fields.

Quick Package Install

Using UnityPackageManager (for Unity 2019.3 or later)

Open the package manager window (menu: Window > Package Manager)
Select "Add package from git URL...", fill in the pop-up with the following link:
https://github.com/coryleach/UnityBindings.git#1.0.5

Using UnityPackageManager (for Unity 2019.1 or later)

Find the manifest.json file in the Packages folder of your project and edit it to look like this:

{
  "dependencies": {
    "com.gameframe.bindings": "https://github.com/coryleach/UnityBindings.git#1.0.5",
    ...
  },
}

Usage

This library contains a small set of components that can be used to bind source property values to target property values in the Unity inspector.
For an example of how the components are used import the package included in the Demo folder after installing this package.

Demo1 Demo2

//Bindings can also be created in code as follows
//Currently all bindings are one way from source to target
var binding = new Binding();

//If your source implements INotifyPropertyChanged correctly changes will automatically propagate
binding.SetSource(myData,"SourcePropertyName");
binding.SetTarget(myView,"TargetPropertyName");

//You can also force a refresh (unnecessary if source implements INotifyPropertyChange)
binding.Refresh();

//Temporarily disable bindings
binding.Enabled = false;

//Set a custom converter to transform source values before they are passed to the target
binding.Converter = (x) => x.ToString();

//Destroy the Binding
binding.Dispose(); 

Author

👤 Cory Leach

Show your support

Give a ⭐️ if this project helped you!


This README was generated with ❤️ by Gameframe.Packages