Search Unity

Execute code before the Made With Unity splash screen

Discussion in 'Android' started by gfaraj, Apr 1, 2017.

  1. gfaraj

    gfaraj

    Joined:
    Jul 11, 2016
    Posts:
    35
    My app supports both Android mobile and Android TV devices. I use Portrait mode for mobile devices, while I *have* to use Landscape mode for Android TV devices.

    I had achieved this by setting the default orientation to Auto Rotation and running this in my first script (have this script as -400 in Script Execution Order settings):

    private void InitOrientation()
    {
    UsesLandscape = AppHelper.IsTvDevice;

    Screen.orientation = UsesLandscape ? ScreenOrientation.LandscapeLeft : ScreenOrientation.Portrait;
    Screen.orientation = ScreenOrientation.AutoRotation;
    Screen.autorotateToLandscapeLeft = UsesLandscape;
    Screen.autorotateToLandscapeRight = false;
    Screen.autorotateToPortrait = !UsesLandscape;
    Screen.autorotateToPortraitUpsideDown = false;
    }

    This was working pretty well using Unity 5.5.1, but now I've upgraded to 5.5.2 and the Unity splash screen starts in Landscape mode even if my phone is oriented as Portrait. When my first scene starts, it runs the code above and goes to the correct orientation. But this causes a nasty orientation change between the Unity splash and my first scene on mobile phones.

    I would like to run the code above before the Unity splash screen starts. Is this possible? Is there any other way to support different orientations depending on the device the app is running?
     
  2. pafinator

    pafinator

    Joined:
    Mar 11, 2017
    Posts:
    4
    Have you found a solution yet? It seems in 5.5.0, the Awake() methods were called while the splashscreen was displaying. Now, however, they're called after it ends. This means that there's a delay after the splashscreen ends while the engine executes Awake(), and also that you can't play music in Awake() and have it play during the splashscreen.
     
  3. gamefish

    gamefish

    Joined:
    Jul 5, 2013
    Posts:
    14
  4. noobogami

    noobogami

    Joined:
    Jul 24, 2021
    Posts:
    44
    there is a attribute you can use for this
    [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSplashScreen)]