Hi Unity users,
hopefully this is the right place to ask this.
Short-story:
- Has any of you got any experience/advises to share regarding MVVM, DI and IoC in Unity3D? Any success stories to share? Which packages/assets from the store you used (if any).
- Have you tried NData combined with StrangeIoC or Zenject (why one over the other?)
- The UnityTestTools?
Long-story:
-
I’m trying to move forward in Unity experience by making a small experiment. It’s basically a Tycoon type of small prototype. Why a Tycoon? From the outside it might look very simple, but it’s actually a quite complete experience… it has lots of UI work, gameplay logic, metagame, social integration, multiplayer, several screens and play modes, data persistence, they lend themselves to IAPs (since they are mostly free to play nowadays), etc.
-
My background is C#, XNA days, where I learned to program, mostly gameplay and graphics programming. A few of the games that I started with some friends in those days got really far, prizes and all… however, they get to a point where change is extremely resistant, adding any little feature becomes a daunting task, etc you know the drill. Game never gets finished.
-
Since WPF, XNA/Silverlight integration efforts of the community and others, MVVM (and similar design patterns) came to light with MVVMLight Toolkit, Dependency Injection and IoC libraries, Unit Testing, etc… sounded very interesting.
-
To be honest, without a specific project at hand to try these out, my time was just spent reading about them, understanding about ‘Mocks’, best practices, etc… documentation and examples is infinite (I wonder if, for me, it is just faster to just hack away code).
-
Coming back to Unity, these type of libraries start surfacing once again. And with good reason, Unity’s SendMessage or any other of Stringified events seems like a nice a idea for the first 20minutes of usage.
It would be nice to give them a fair try. Except that I’m again at that infinite loop-hole trying to understand and find ‘the perfect’ usage for these.
I have gone on a shopping spree… got NGUI, FullInspector (seriously recommend this one), NData, FingerGestures, etc…
I ask of you:
- Have you tried gluing these all together successfully in a lean way? Do you do UnitTesting at all?
- Have you used Zenject (has nice features, for example, the ITickable interface, basically an equivalent for XNAs IUpdateable)
- Have you used StrangeIoC (comes with a feature complete signals system, that is GC friendly. And a Bind-Anything-To-Anything framework)
- NData?
MVVM question:
- What do you think of Monobehaviors? People seem to recommend to use this as a ‘View’… however, these can objects can have: Colliders, Meshes, Animations, Custom classes, and many many more components attached to it (and it’s expected to be like that). Sounds like a super-fat view in my opinion.
- StrangeIoC proposes the approach of ‘Mediators’ which is another Monobehavior that does the middleman between the target monobehavior and some business logic.
Am I asking the right questions? Anything you would like to advise (i.e. ‘just code away’ : p)
Cheers and thanks!
## Editing to have more info on the acronyms used mercilessly:
MVVM: Stands for Model-View-ViewModel. Design pattern that tries to separate the concerns of an UI (View), Data (Model) and the BusinessLogic (ViewModel). Very similar to others like Model-View-Presenter, Model-View-Controller, etc. The idea is to seriously decouple the UI from the logic of the application… changes and notifications are done via ‘Commands’ and ‘Events’.
IoC: Stands for Inversion Of Control. Classes don’t have the control of instancing new classes (mostly) anymore. Somebody does it for them.
DI: Dependency Injection. The idea is that classes are and logic are programmed towards interfaces. Specific or concrete implementations are ‘injected’ to the classes that require it. i.e.
- You have a Character, and it uses an IWeapon? he will get it, magically.
- But which one?. You would configure it via an IoC. in the IoC you can say Bind().To(); Everytime something needs an IWeapon it would give it a NetworkEnabledWeapon. Your character code would not change.
- You have levels. They use IEnemyFactory. You want a singleton for all your levels: Bind.To().Single(); (syntaxes depend on the IoC of choice).
NData: on the Asset Store. Add-on, for NGUI enabling it to use MVVM (see above). Bought already, haven’t used it. Judging from the videos it looks very impressive. Kudos to them for coming up with this.
FullInspector2 Asset Store. Unity’s inspector and serializing capabilities in overdrive mode. List, Dictionaries, Generics, Interfaces, you name it… all of that becomes serializeable and shows on your inspector windows for easy configuration. This description doesn’t do it full justice. Really.
StrangeIoC and Zenject: Inversion of control libraries. Still wrapping my head around which one to choose. For my specific situation at hand.