Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Reference to AppCallback.Instance or some initialization logic from the "Unity side"?

Discussion in 'Windows' started by Maisey, Sep 13, 2016.

  1. Maisey

    Maisey

    Joined:
    Feb 17, 2014
    Posts:
    300
    Hello,

    Is there some way to access the AppCallback instance from the Unity-side? Or some other undocumented callback in which I can do stuff before Unity initializes things in the MainPage.xaml.cs?

    Why do I need this?

    One basic example (not actually what I'm trying to do) would be to be able to set the 'PreferredLaunchViewSize' before Unity render stuff etc.
    Code (CSharp):
    1. ApplicationView.PreferredLaunchViewSize=newSize(480,800);
    2. ApplicationView.PreferredLaunchWindowingMode=ApplicationViewWindowingMode.PreferredLaunchViewSize;
    Some UI-elements is only intialized correctly if the ratio is correct from the start (which it isn't some times).

    I know I can add this directly to MainPage.xaml.cs, but I'd like to avoid doing manual stuff before each new "clean" build.

    Thanks!
     
  2. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,647
  3. Maisey

    Maisey

    Joined:
    Feb 17, 2014
    Posts:
    300
    So, in other words, there's no way to do something before Unity does "initialize" it's stuff? And there's no way to access the AppCallbacks-item?

    Thanks!
     
  4. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,647
    Well, C# scripts in your project cannot be invoked before Unity does its initialization. AppCallbacks is created before Unity initialization is done, but you can only use it in C# files like App.xaml.cs, MainPage.xaml.cs, etc which are in generated solution.

    I probably haven't answered your original question - "Is there some way to access the AppCallback instance from the Unity-side?", the answer is no, if I understood correctly what "Unity side" is, but you can use https://docs.unity3d.com/ScriptReference/WSA.Application.html
     
  5. Maisey

    Maisey

    Joined:
    Feb 17, 2014
    Posts:
    300
    Thank you Tomas for your answers!

    I "solved" my issue by doing something completely unrelated. :)