When the Windows Mixed Reality platform was introduced a couple of applications had these really cool 3D app launchers you could place somewhere in the mixed reality world and launch the app when selecting them. Unfortunately back then, there was no way for developers to use this feature for their own applications. Luckily those days are gone, Microsoft introduced new APIs in the 2017 Fall Creators Update (RS3) for their immersive headsets. Since April 2018 Update (RS4) even HoloLens devices can use them.
As you might know, most of the Windows Mixed Reality appilcations out there are made using the Unity Engine. Once you are done developing and want to deploy to a device, you’re going to do a Unity build which will create a Visual Studio Solution for us targeting the Universal Windows Platform. All good so far. Now if you’ve read through the 3D app launchers documentation you’ll notice that in order for them to work, there is some changes we need to do to the Visual Studio project file and the appmanifest file for them to work. This is where things get complicated, since those changes are gone when you create a new Unity build in a different folder or build your app using continuous integration somewhere in the cloud. So let’s fix this by creating a Unity post build script to do the required changes for us whenever we build. Credit for most part of the code goes to Edd Smith, Head of Creative Tech at Fracture Reality. I applied some minor tweaks to get it working with IL2CPP scripting backend.
First, we’ll create scriptable object to conveniently hold our 3D launcher data. So create a folder 3DLauncher in your Unity project Assets folder. Then create a new Script file and name it AppLauncher3D. Insert the following code:
Once Unity has compiled the script, you’ll get a new menu item in the Editor Assets menu under Assets->Create->3D App Launcher. Next create a new folder Editor in your 3DLauncher folder and create another script file in it, name it AppLauncher3DEditor. This script is going to use the
UnityEditor namespace, that’s why it must be inside a folder called Editor, so it’s not included when building for the target platform. Anyway, here’s the code:
Let’s break this into smaller pieces:
This is our entry point. Since we added the
PostProcessBuild attribute to this static method, Unity will execute it, once it has finished building the UWP solution and give as the path to the exported project. Since Unity will do this, even when not targeting the UWP platform, we have to make sure, we are targeting it. Then we lookup the AppLauncher3D asset we created to read the configuration from it. Remember it contains the path to the .glb file and eventually overrides bounding box and center.
This is where we peform the 3 steps necessary for the 3D launcher to work:
- Add the required definition to the package manifest
- Add the asset to the project and mark is as deployment content
- Copy the .glb file into the projects assets folder
I’ll leave it up to you to dig into the specific methods and discover them!
And we’re done! Go ahead and create a .glb file for your 3D launcher, then add it to your Unity project assets and create the scriptable object asset to configur it. Build your project and you’ll have a shiny new 3D app launcher!