Rivello Multimedia Consulting has multiple frameworks for MVC in Unity.
-- | Requires MonoBehaviour? | Lightweight? | More Info | Created | Updated |
---|---|---|---|---|---|
uMVCS | ✔️ | ✔️ (Light) | See Below | 2018 | 2023 |
Mini MVCS | ❌ | ✔️ (Even Lighter!) | rmc-mini-mvcs | 2023 | 2024 |
The UMVCS library for Unity is a custom framework embracing the MVCS architecture.
MVCS is one of many solutions for organizing a Unity projec efficiently. It may or may not be the best solution for you.
The UMVCS library a solution for MVCS architecture within Unity. It is heavily-dependent on MonoBehaviour as a It has no dependencies on 3rd party libraries.
The UMVCS MVCS library for Unity Development is free. Created by Rivello Multimedia Consulting.
It has few classes and a flexible pattern. Following the conventions of MVCS requires discipline as the system is purposefully light and flexible. For example the a model instance can access another model instance, but it is recommended not to do so.
UMVCS is flexible and does not prevent actor-actor communication. However, best practices are to limit communication.
Communication Channels
- Methods - The caller scope has a reference to the called scope and "calls a method" in the typical sense. This is the most coupled communication channel
- Events - Observer pattern where the reciever has a reference to the sender
- Commands - Observer pattern where the reciever has no reference to the sender. This is the least coupled communication channel
Communication Suggestions
-- | To Model | To View | To Controller | To Service |
---|---|---|---|---|
From Model | ❌ | ❌ | ✔️(Events) | ❌ |
From View | ❌ | ❌ | ✔️(Events) | ❌ |
From Controller | ✔️(Methods) | ✔️(Methods/Commands) | ✔️(Commands) | ✔️(Methods) |
From Service | ❌ | ❌ | ✔️(Events) | ❌ |
Communication Diagram
MVCS is one of many solutions for organizing a Unity projec efficiently. It may or may not be the best solution for you.
MVCS Pros | MVCS Cons |
---|---|
Code is highly maintainable | Code is highly repetitive |
Code is highly extensible | Project navigation requires more time |
Faster to update an existing project | Slower To start a new project |
Adding a new feature is prescriptive | Adding a new feature may require more classes |
Faster learning curve to onboard veterans | Slower learning curve to onboard newbies |
Suggested for projects of medium/large scope | Not Suggested for projects of small scope |
Model is highly testable (TDD) | |
Coding invites less debate | Coding requires more discipline |
Appropriateness For Games
For projects where runtime optimization is essential, coding directly (without MVCS), may yield better performance.
However, that is likely a subsection of a game. The rest of the game may still benefit from MVCS. There is indeed flexibility for such a hybrid solution.
The UMVCS library for Unity is a custom framework embracing the MVCS architecture.
MVCS is one of many solutions for organizing a Unity projec efficiently. It may or may not be the best solution for you. Enjoy!
You can either use the Unity Package Manager Window (UPM) or directly edit the manifest file. The result will be the same.
UPM
To use the Package Manager Window, first add a Scoped Registry, then click on the interface menu ( Status Bar → (+) Icon → Add Package By Name ...
).
Manifest File
Or to edit the Packages/manifest.json
directly with your favorite text editor, add a scoped registry then the following line(s) to dependencies block:
{
"scopedRegistries": [
{
"name": "npmjs",
"url": "https://registry.npmjs.org/",
"scopes": [
"com.rmc"
]
}
],
"dependencies": {
"com.rmc.rmc-umvcs": "1.5.6"
}
}
Package should now appear in package manager.
You can either use the Unity Package Manager (UPM) Window or directly edit the manifest file. The result will be the same.
UPM
To use the Package Manager Window click on the interface menu ( Status Bar → (+) Icon → Add Package From Git Url ...
).
Manifest File
Or to edit the Packages/manifest.json
directly with your favorite text editor, add following line(s) to the dependencies block:
{
"dependencies": {
"com.rmc.rmc-umvcs": "https://github.com/SamuelAsherRivello/rmc-umvcs.git"
}
}
The package can optionally be set as testable. In practice this means that tests in the package will be visible in the Unity Test Runner.
Open Packages/manifest.json
with your favorite text editor. Add following line after the dependencies block:
{
"dependencies": {
},
"testables": [ "com.rmc.rmc-umvcs" ]
}
Some packages include optional samples with clear use cases. To import and run the samples:
- Open Unity
- Complete the package installation (See above)
- Open the Package Manager Window
- Select this package
- Select samples
- Import
Unity Target
- Standalone MAC/PCUnity Version
- Any Unity Editor 2021.x or higherUnity Rendering
- Any Unity Render PipelineUnity Aspect Ratio
- Any Unity Game View
Created By
- Samuel Asher Rivello
- Over 25 years XP with game development (2024)
- Over 11 years XP with Unity (2024)
Contact
- Twitter - @srivello
- Git - github.com/SamuelAsherRivello
- Resume & Portfolio - SamuelAsherRivello.com
- LinkedIn - Linkedin.com/in/SamuelAsherRivello <--- Say Hello! :)
License
Provided as-is under MIT License | Copyright © 2024 Rivello Multimedia Consulting, LLC