Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

PlayerPref from App.xaml.cs

Discussion in 'Windows' started by xlarrode, Nov 28, 2013.

  1. xlarrode

    xlarrode

    Joined:
    Nov 9, 2012
    Posts:
    19
    Hi,
    I have overrided the
    Code (csharp):
    1.  void OnActivated(IActivatedEventArgs args)
    on App.xaml.cs in order to get the URL from the specific file i want to open on my app.

    Now i want to set this URL on the PlayerPref in Unity.
    Any ideas how i can do that ?

    I know that we can do this on IOS so maybe it's the same on Metro...
     
  2. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,875
    You already reference UnityEngine.dll from your application, so you can access UnityEngine.PlayerPrefs without problems.

    But, I am guessing OnActivated event will be called before Unity is initialized, so do this:
    * Subscribe to appCallbacks.Initialized event, which is called when Unity is initalized
    * Save URL in some variable in App.xaml.cs
    * In your initialized callback, write something like:
    appCallbacks.InvokeOnAppThread(new AppCallbackItem(() =>
    {
    UnityEngine.PlayerPrefs.SetString("URL", myURL);
    }
    ), false);

    Hope that helps.