Scripts

From HoloDevelopers
Jump to: navigation, search
  • UWP file type association

For UWP apps for mixed reality a file type association can be specified, either in the Player settings in Unity, or in the Package.appxmanifest file.

UWPfiletypeassociation.png

This file type association is handy when you want a file or URL to a file to be opened in your App. The App.cs script then can be adapted to make use of your file in your app, like in the sample below:

      private void ApplicationView_Activated(CoreApplicationView sender, IActivatedEventArgs args)
       {
           CoreWindow.GetForCurrentThread().Activate();
           if (args.Kind == ActivationKind.File)
           {
               FileActivatedEventArgs eventArgs = args as FileActivatedEventArgs;
               UnityEngine.WSA.Application.InvokeOnAppThread(() =>
               {
                   GameObject go = GameObject.Find("MyManager");
                   if (go && eventArgs.Files.Count>0)
                   {
                       List<string> arr = new List<string>();
                       foreach(var t in eventArgs.Files)
                       {
                           arr.Add(t.Path);
                       }
                       MySceneManager msc = go.GetComponent<MySceneManager>();
                       if(msc!=null)
                       {
                           msc.Init(arr.ToArray());
                       }
                   }
               }, false);
           }
       }

A similar method can be used to open custom protocol based URL's, like when you start the URL with x3dx://... Only here the ActivationKind should be of type Protocol

  • How to handle URI activation (HTML, Protocol)[1]