1
\$\begingroup\$

I've been working with MVVM in WPF for a long time and I'm now trying out Unity3D for a GUI-driven application.

Can I work with view models and bind them to properties in GUI-components? I guess the attached script-instance would be the "data context"? But how do I for instance bind (two-way) a text-property in my script to the text-property of a GUIText?

If Unity3D doesnt support this out of the box, could I implement a "bindable GUIText" myself somehow?

I know there are a few GUI frameworks for Unity3D out there allready and some of them seem to "support" MVVM as well. But I havent been able to find out many details about this. For instance the "data binding" support in NGUI/NData seem to be only between view-components and not between view and viewmodel, which is what MVVM is all about.

UPDATE

Apparently, the guy behind Durandal and Caliburn.Micro is working on a binding-framework for Unity3D which looks very promising. I guess this answers my question basically.

\$\endgroup\$
2
\$\begingroup\$

Unity - not unlike some other game engines - provides as the backbone of its architecture a scene-graph that unifies all aspects of the MVC / MVVM triad. Trying to work around such fundaments of the platform will only cost you more in time than you think you might gain by adapting it to the architectural paradigm you mention... rest assured.

Re your question on GUI: This depends very much on which Unity GUI system you are using:

  • IMGUI requires you to make GUI calls on every update -- thus there is no "retained mode" data binding.

  • Retained mode GUI for v4 should retain the values you put into them, but that isn't the same as data-binding. You'd need to explicitly update the values.

  • Unity 5 (due around July 2014) will provide access to the new GUI system. Being NGUI based, you'll have access to data-binding, as you can see that NGUI has for some time supported data binding.

| improve this answer | |
\$\endgroup\$
  • 2
    \$\begingroup\$ Sadly, Unity 5 UI system (which is available in Unity 4.6 too) does not support data binding. \$\endgroup\$ – mr.pd Dec 9 '14 at 8:45
0
\$\begingroup\$

I recently just released, finally, an old project of mine that does just this. It's only for the legacy GUI, I'm not up to speed on the best options for the new UI.

Basically it creates a "retained mode" by building an object hierarchy of controls just once, then making the appropriate GUILayout calls each time OnGUI is called. It does data binding and a bunch of other stuff. Overhead is minimal, only function calls. No reflection.

Kind of late in the game but it's an option if anyone needs it.

https://github.com/mattolenik/AffinityUI

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

I wanted proper MVVM support in Unity so I created a new framework. It's built upon the unity 4.6 UI system so no extra UI framework needed. It allows you to create views using XML, it supports theming, data binding, animations, dynamic/responsive content etc. It's similar to WPF/Silverlight (XAML) and other MVVM/MVC/MVP frameworks such as Caliburn, AngularJS etc. It's available here: www.markux.com.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.