I’m new to unity and i’m building a GUI with the new UI. This UI is a bit complex, i need to change some value with a slider or a toggle to change an element on the scene.
I’m a bit lost on how to organize my scripts.
Right now i’m using different script corresponding to the different menu. Those scripts update some static variables in the code and then elements linked to this value are updated on the scene.
I was wondering if they where any documentation, video, post or example on how to organize the UI scripting in unity (I didn’t find those for unity 4.6 UI )?
I was also wondering how we can qualify the unity UI pattern (Model View ViewModel, …) ?
I’m maybe unclear, but if you have successfully built a complex UI in unity, i would be happy to know about her global organization.
I recommend using Unity’s built-in functionality as much as possible. This minimizes the amount of code you need to write, debug, document, and maintain.
For UIs, use the Event System (tutorial). Make your script variable non-static. Add an event to your UI element. Tie the variable to the event. When the UI element changes, Unity will automatically update the variable.
You can implement MVVM, MVC, or whatever other architecture you want. Unity doesn’t enforce any specific architecture.
I was also looking for small exemple of MVVM, MVC pattern implemented in unity project cause i have a hard time understanding how to use those pattern with unity, if someone know how to find one it would be great.
The Dialogue System for Unity is a real world example of using MVC. Please feel free to skim through the API documentation, for example ConversationController. The Dialogue System runs branching conversations tree. The model is the conversation tree (a connected structure of dialogue lines). The view is the UI (text onscreen, player response menu). The controller mediates between the model and the view.