Migrating to MRKT2: Using Extension Services for Dependency Injection

Learn more about dependency injection and extension services for MRTK2.

Coming from business development, you might get a little shock coming into Unity. Traditionally, game developers are much more focused on making the outside prettier than the inside. Things like dependency injection are kind of unheard of or considered 'too heavy' for game development. But if you are still in the process of development, actually being able to access a consistent (mock) data service instead of the real live data service might be a big advantage, especially when that data service is rate limited or expensive.

You may also like: Migrating to MRTK2: Interacting With the Spacial Map

The Mixed Reality Toolkit 2 offers a great feature for that: extension services. And it's actually pretty easy to use, and I am going to show a simple sample. I have written about this in a very early alpha stage almost a year ago, but it's now to a point that it's actually usable.

Migrating to MRTK2: Manipulating Holograms by Grabbing

To be honest, the title of this blog post is a bit weird, because in the Mixed Reality Toolkit 1, the concept of grabbing was unknown, as HoloLens 1 does not support this kind of gestures. But nevertheless, as I am on this quest of documenting all the gems I discover while migrating an existing app to Mixed Reality Toolkit 2, this is one of the things I came across. So, I am shoehorning it in this blog post series — the 8th installment of it already. And the fun thing about this one is that although there is a demo project available, I will be writing no code at all. The whole concept of manipulation by grabbing can be done by simply dragging MRTK2 components on top of a game object. Let's get started.

'Far Manipulation'

This is really extremely simple. If I want to make a cube draggable in the 'classic' sense — that is, point a cursor to it, pinch, and move my hand, and then the cube follows, all you have to do is add a ManipulationHandler to the cube, with default settings:

Migrating to MRTK2: Missing Singleton and 3DTextPrefab

If you are migrating from the HoloToolkit to Mixed Reality Toolkit 2 'cold turkey,' as I am doing for my AMS HoloATC app, a lot of things break, as I already said in the first post of this series. For things that you can tap, you can simply change the implementing interface from IInputClickHandler or IManipulationHandler to a couple of other interface and change the signature a bit — that's not complex, only tedious, depending on how much you have used it.

What I found really hard was the removal of the Singleton class and the 3DTextFab. I used both quite extensively. The first one I needed for like data access classes as the concept of services that was introduced in the Mixed Reality Toolkit 2 was not yet available, and the other... well basically all my texts were 3DTextPrefabs so any kind of user feedback in text format was gone. Because so much breaks at the same time, it's very hard to step by step rebuilding your app to a working condition. Basically you have to change everything before something starts to work again. Since I was still learning by doing, there was no way to test if I was doing things more or less right. I got stuck and took a radical approach.