Wiki

Clone wiki

Data Bind / Introduction

A clean separation between logic/data and visualization is a must-have, not only in software projects (http://en.wikipedia.org/wiki/Separation_of_presentation_and_content). This guarantees that the business logic of the application isn't dependent on the presentation, so the visualization can be easily adapted.

One famous architecture, at least in the Microsoft universe, is the MVVM pattern (http://en.wikipedia.org/wiki/Model_View_ViewModel) which is highly utilized in Windows Presentation Foundation (WPF, http://en.wikipedia.org/wiki/Windows_Presentation_Foundation). I don't want to get too much into detail of this framework as it a fully developed business framework with a huge amount of complex stuff.

The part we are interested in is the data binding between the view and the view model. The view model is an additional structure which sits between the view and the logic. It gets its data from the logic of the application and provides an interface for the view to use. Via data bindings the view can use the data provided by the view model to show it to the user.

This is what we adapted with our plugin, so you'll have a common way how your UI is separated from you game logic to get many cool advantages:

  • Don't be afraid that UI changes break your game any more, the logic is completely separated
  • Exchange your UI system without touching any logic (e.g. from NGUI to Unity UI)
  • Easily extend the plugin to use it with a custom UI, world objects or custom input commands

Easy Health Bars

Tired of remembering to update two variables (actor.Health = 20.0f, healthLabel.Text = „20“) if the health of your character changed, so the UI is updated correctly?

No problem, Data Bind will take care of this from now on. You just update the data in your context and the UI will update magically!

Okay, not really magically, but without any work on your side. In principal it works like this:

  • The data variables in your context are wrapped in a so called "Data property"
  • The bindings on UI side register for value changes on this properties
  • When your code sets a new value for your data, the property informs its listeners, so they can update the UI properly.

The easiest way to get started quickly is to have a look at the examples provided with the plugin and to read through the step-by-step Tutorial.

Updated