MVVM Community Toolkit for Unity (plugin)
Last night, I decided to jump back into Unity and Noesis again and take a little break from UE5 and C++, and decided that I wanted to improve upon my existing MVVM architecture/patterns. But I quickly realized that it might be a better usage of my time to simply get the .NET MVVM Community Toolkit working as a little plugin bundle for Unity, to unlock the full power of modern MVVM approaches and maintain compatibility and consistency with standard .NET ecosystem tooling and libraries. So I collected all of the assemblies (DLLs) from NuGet, bundled them together and configured the Roslyn source analyzers and generators for Unity and created a little plugin bundle that's super easy to install (simply drag and drop the "Assets" folder into your project and merge them, or copy "Plugins/" into your "Assets/" folder).
I created a MVVM-Toolkit-Unity for the plugin with an "alpha" release for community testing. I'm already using it to great effect in a Unity project!
If you've ever worked with MVVM Toolkit in WPF, UWP, Avalonia or any other XAML-based UI framework, you'll know how much productivity and power this unlocks! Writing view-models becomes really easy and clean:
I wanted to share this because I was both surprised no one else has done this yet and figured it would be a great productivity boost for those in the NoesisGUI community using Unity/C#, and it wasn't particularly hard to put together. I cobbled it together from the NuGet packages and set it up in a Unity project, but in the future I'll probably either compile a fork with special Unity configurations (targeting .NET Framework/Standard) or use a PowerShell script to resolve the NuGet packages and create the binary bundle and files.
For more information, please see:
Microsoft Learn Documentation
Source Generators Documentation
I also recommend getting the "MVVM Toolkit Sample App" from the Microsoft Store:
Sample App
Please enjoy, and let me know about your experience using the full power of the MVVM Toolkit in Unity with NoesisGUI! :-)
Regards,
Aaron
Edit:: Github URL fixed!
I created a MVVM-Toolkit-Unity for the plugin with an "alpha" release for community testing. I'm already using it to great effect in a Unity project!
If you've ever worked with MVVM Toolkit in WPF, UWP, Avalonia or any other XAML-based UI framework, you'll know how much productivity and power this unlocks! Writing view-models becomes really easy and clean:
Code: Select all
[Serializable] public abstract partial class ViewModelBase: ObservableObject {
[SerializeField, ObservableProperty] string _name ;
protected ViewModelBase( string? name = null ) => _name = name ?? GetType( ).Name ;
}
[Serializable] public partial class MainViewModel: ViewModelBase {
public string BuildInfo => $"v{Application.version} | {DateTime.Now:yyyy}" ;
[RelayCommand] void OnNewCampaign( ) => Debug.Log( nameof(OnNewCampaign) ) ;
[RelayCommand] void OnContinue( ) => Debug.Log( nameof(OnContinue) ) ;
[RelayCommand] void OnLoadGame( ) => Debug.Log( nameof(OnLoadGame) ) ;
[RelayCommand] void OnOptions( ) => Debug.Log( nameof(OnOptions) ) ;
[RelayCommand] void OnExit( ) => Application.Quit( ) ;
}
For more information, please see:
Microsoft Learn Documentation
Source Generators Documentation
I also recommend getting the "MVVM Toolkit Sample App" from the Microsoft Store:
Sample App
Please enjoy, and let me know about your experience using the full power of the MVVM Toolkit in Unity with NoesisGUI! :-)
Regards,
Aaron
Edit:: Github URL fixed!
"Make it exist,"
-- Arkaen Solutions
-- Arkaen Solutions
-
- TheHappyYachter
- Posts: 4
- Joined:
Re: MVVM Community Toolkit for Unity (plugin)
I've had a little play with this and I am really impressed. It really seems to bring the ease of the MVVM toolkit to Unity. There's one persistent error with your first release I see with Unity 6 which is:
Code: Select all
Assembly 'Assets/Plugins/MVVM Toolkit/Microsoft.CodeAnalysis.Workspaces.dll' will not be loaded due to errors:
Unable to resolve reference 'System.Reflection.Metadata'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.
Unable to resolve reference 'Microsoft.CodeAnalysis'. Is the assembly missing or incompatible with the current platform?
Reference validation can be disabled in the Plugin Inspector.Who is online
Users browsing this forum: No registered users and 1 guest