Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the MVVM pattern with Unity Engine as front end [closed]

I plan to make some applications that will let me organize tasks from home or from somewhere else. For this I need a database server (a virtual one running at home), a backend part (the business logic) and the front end (the view). At school we learned the MVVM via WPF, but to be frank I use it only when it is explicitely required.

There are a lot of benefits in favour of Unity like

  • Artist friendly
  • Can compile to mobile, web and desktop
  • Fast development (in my case at least)
  • Has a lot of built in features I can harness.

Now, even as simple as I will make an app like this, sometimes I might want to extend it, improve it or change some components entirely. I know how to use MVVM in WPF but I only have some vague ideas for the Unity implementation which I would like someone skilled to overview.

The front end (Unity) would take care of sound management, fancy animations and the UI itself. But UI button events cannot access directly the database, so I thought of building some bridge classes. Say I want to delete a reminder, as an easy example. In an OnButtonClicked() method I would just call a BridgeClass's PleaseDeleteThis(MyReminder) and inside that method there's the backend solution that actually finds that reminder by id and removes from the database, then sends an everything all right flag back to the front end app so I know it was successful.

What I thought of is that using these bridge classes I wouldn't have to worry about what happens if I change the database server or the front end, as all they have to know is communicating with the bridge. I know the example was over simplified, but how doable would this one be regarding the component integrity and the MVVM pattern?

like image 245
agiro Avatar asked Jan 04 '23 11:01

agiro


1 Answers

MVVM has been successfully used by AAA software houses to build games. The makers of Shipbreakers (aka Homeworld: Deserts of Kharak) wrote their code such that the View was a MonoBehavor I believe, VM and M were POCO classes written external to and independent to Unity so as to speed development. They can have their own Views for prototyping external to Unity.

They also wrote their own debugging visualisers and property editors for Unity.

https://www.youtube.com/watch?v=q9aeNtKKXeo

MVVM is about at the 19:18 mark though I do recommend to watch the whole thing as there are some other great things in there.

like image 156
MickyD Avatar answered Jan 10 '23 20:01

MickyD