Search Unity

Pass value from Edge to Unity

Discussion in 'VR' started by eedok, Oct 13, 2017.

  1. eedok

    eedok

    Joined:
    Sep 21, 2009
    Posts:
    194
    Is there a way to pass values from a browser to Unity? I attempted to use clipboard.js and the clipboard but it doesn't seem to work on the hololens, is there another way to pass values to Unity from the browser?
     
  2. Unity_Wesley

    Unity_Wesley

    Unity Technologies

    Joined:
    Sep 17, 2015
    Posts:
    558
    Have your tried using google sheets? I have seen people using that in their projects to write and read data from a google sheet inside of an app
     
  3. eedok

    eedok

    Joined:
    Sep 21, 2009
    Posts:
    194
    I don't think google sheets will work for what I want to do, but I guess I need to explain my needs further.

    I have a custom web application that you need to log in to, and it uses Azure Multi-Factored authentication, once you log in you get a security token. I need a way to pass the token from the browser to Unity. My first attempt was trying to just put the token in the clipboard then access it in unity, while this works on other platforms, it does not work on hololens. So I'm wondering if there's another way to pass the value to unity (possibly a custom URI handler)?
     
  4. eedok

    eedok

    Joined:
    Sep 21, 2009
    Posts:
    194
    Found some documentation on URI handling for WSA in this dark corner of Unity documentation: https://docs.unity3d.com/560/Documentation/Manual/windowsstore-assocation-launching.html

    Using this I can now launch my program with foo://bar but I can't seem to figure out how to access the bar part after the :// the example project has it as part of UnityEngine.WSA.Application.arguments but when I run the app on hololens UnityEngine.WSA.Application.arguments is always empty
     
  5. eedok

    eedok

    Joined:
    Sep 21, 2009
    Posts:
    194
    Replying to my own reply, as this has been solved, and so this will show up if anyone finds this page in a search:

    In order to access the arguments after the ://, you have to grab the Uri in the ApplicationView_Activated function in App.cs, and then pass it to Unity using InvokeOnAppThread like so:

    Code (csharp):
    1.  
    2.         private void ApplicationView_Activated(CoreApplicationView sender, IActivatedEventArgs args)
    3.         {
    4.             if (args.Kind == ActivationKind.Protocol)
    5.             {
    6.                 var arg = args as ProtocolActivatedEventArgs;
    7.                
    8.                 m_AppCallbacks.InvokeOnAppThread(
    9.                     () =>
    10.                     {
    11.                         UnityClass.DoThingBasedOnUri(arg.Uri.AbsoluteUri); //Replace this with the unity class you want receiving the data
    12.                     }, false);
    13.             }
    14.             CoreWindow.GetForCurrentThread().Activate();
    15.         }
    16.  
     
  6. Unity_Wesley

    Unity_Wesley

    Unity Technologies

    Joined:
    Sep 17, 2015
    Posts:
    558
    Glad to see you found a solution for the problem, thank you for posting the answer. I learned a lot from this post