The Goal
I wanted to solve the 'Spaghetti UI' problem in Unity. Managing complex UI flows with manual scene references and SetActive calls is a nightmare. I set out to build a framework inspired by ASP.NET MVC to manage UI through pure code.
What I Built
I developed a custom MVC/MVVM framework that moves UI control away from the scene and into centralized controllers.
- Controller-Driven Flow: Wrote a navigation system where you can switch screens using code (like
RedirectToAction). The framework handles all the view transitions automatically. - Modular Views: Created a system for Partial Views and View Groups, allowing for complex UI composition and reusable components.
- Navigation Stack: Built a
ViewManagerthat tracks UI history. The 'Back' button works automatically, restoring the previous view and its data. - Typed ViewModels: Enforced strict data-binding where every view is paired with a specific ViewModel, catching errors at compile-time instead of runtime.
- VContainer Integration: Integrated VContainer for Dependency Injection. This keeps controllers decoupled from their services, making the system easy to test and extend.
Takeaways
- Decoupling is Key: Moving UI logic into pure C# classes made the project much easier to maintain and test.
- Scalability: The framework allowed me to add new, complex menus without worrying about breaking existing UI states.