Update 10.02.2015:
The first version of Data Bind for Unity is available in the Asset Store! Check it out now for a very low initial price and help me with your feedback to further develop it for your needs!
Introduction:
A clean separation between logic/data and visualization is a must-have, not only in software projects (Separation of content and presentation - Wikipedia). 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 (Model–view–viewmodel - Wikipedia) which is highly utilized in Windows Presentation Foundation (WPF, Windows Presentation Foundation - Wikipedia). 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
Example: 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.
More information
Check out the official documentation with tutorials, examples, API and explanations. If any questions are left, just send me a message or post in this thread!
Original Post:
Hi there,
We are using NData (NData - MVVM framework for NGUI - Community Showcases - Unity Discussions) for a long time now, but unfortunately there seems to be no further development. During the last projects we added many custom extensions to it, fixed some issues and changed some of the core classes a bit.
So the idea came up to build a new data binding/MVVM asset from the ground up which can be used with both NGUI, uGUI and other UI frameworks. The core is practically done. But before we start to write a lot of documentation, tools and tutorials, I’d like to hear your opinion about it and if you have the need for such an asset. Or maybe you even know about an already existing asset that has everything a developer needs to do some nice data binding
Here are the main features/advantages of the Data Bind asset we would build:
- Data binding asset for Unity
- More advanced and more general than NData
- Separates your view from the logic of your game
- Exchange your UI system without touching any logic
- Switch between NGUI and Unity UI
- Easily extendable for other UI systems (e.g. custom ones)
So, what do you think? Really curious about your opinions!