Topic Author
Posts: 44
Joined: 12 Apr 2019, 00:30

Unity: Trying to figure out how to organize my data for ViewModels

21 Jul 2019, 17:57

I have done WPF programming for a long time, but I'm new to Unity. I'm really excited about trying out Noesis, but I'm having a conceptual problem that I'm sure has a simple answer.

My application is going to be receiving a lot of data over WebSockets. I've got a WebSocket class defined as a MonoBehavior and it is working. However once data comes in, I need to push updates to my ViewModels, both data and other things (like starting animations).

What is the best way to organize things in my project to do this? Is there a way for my WebSocket class to get access to the ViewModels? Do I need some sort of DataManager that can see all of the ViewModels and update them when a DataUpdated() event fires?

Any/all suggestions welcome. Thanks!

User avatar
Site Admin
Posts: 1911
Joined: 22 Dec 2011, 19:20

Re: Unity: Trying to figure out how to organize my data for ViewModels

25 Jul 2019, 20:33

Hi and welcome,

If you take a look at our examples you will see a basic configuration for developing MVVM applications, for example:
https://github.com/Noesis/Tutorials/blo ... ow.xaml.cs

Basically you will have a root control (MainWindow) and a ViewModel set as its DataContext. Inner controls would bind to properties of the ViewModel to access different data, or other controls can create its own view models.

There is no predefined way in Noesis to access ViewModels other than get the DataContext of a control.
Perhaps you can define some sort of WebRequest system where ViewModels can register web queries, and then get a response on a delegate to update its properties and notify the UI of changes (this should be done in Unity's main thread, because UI elements cannot be modified in other threads).

In the xaml you can use DataTriggers to fire animations, load controls or update the look of the UI.

Who is online

Users browsing this forum: asusralis and 1 guest