Robin B.
Robin B.

Reputation: 71

Enforce Landscape orientation on Windows 8.1 for Unity project

I have exported an app created in Unity 5.2.1f1 to Visual Studio for further processing. I did apply the following settings to the Package.appxmanifest:

Supported Rotations:

After export to a WP8.1 device (Nokia Lumia with Lumia Denim), both with Debug and Release/Master configuration, rotating the phone still results in the app switching from Landscape to Portrait mode.

Next, I changed the following lines in the generated App.xaml.cs:

this.InitializeComponent(); 
appCallbacks = new AppCallbacks();

into this:

this.InitializeComponent();
Windows.Graphics.Display.DisplayInformation.AutoRotationPreferences = Windows.Graphics.Display.DisplayOrientations.Landscape | Windows.Graphics.Display.DisplayOrientations.LandscapeFlipped;
appCallbacks = new AppCallbacks();

in an attempt to reinforce the settings done in the Package.appxmanifest. Still to no avail, the app still rotates freely. I also checked for further calls to AutoRotationPreferences (thought maybe some other auto-generated code), but didn't find anything.

Are there any further options I could try, any detail I might have overseen, or do I use some deprecated approach to solving this problem? Any help would be greatly appreciated!

Upvotes: 2

Views: 706

Answers (2)

Mandur
Mandur

Reputation: 153

If you want to configure such settings in Unity with the Windows store, you should do so in the Unity tool. It seems, the config defined there somewhat override the package manifest in the VS solution.

To do so go to build settings menu in Unity (Ctrl+Shift+B), press on player settings and open the resolution and presentation tile on the blade displaying to the right. Simply select here the Orientations allowed for the auto-rotation. This should do the trick.

Unity

Hope this fixes the issue.

Upvotes: 1

Hellium
Hellium

Reputation: 7356

I know this is an old post, but I found this link providing a link to a blog post indicating how you can disable portrait mode in code.

public static void SetScreenOrientationToLandscape()
{
    SetDisplayAutoRotationPreferences( (int) ORIENTATION_PREFERENCE.ORIENTATION_PREFERENCE_LANDSCAPE |
        (int) ORIENTATION_PREFERENCE.ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED );
}

public enum ORIENTATION_PREFERENCE
{
    ORIENTATION_PREFERENCE_NONE = 0x0,
    ORIENTATION_PREFERENCE_LANDSCAPE = 0x1,
    ORIENTATION_PREFERENCE_PORTRAIT = 0x2,
    ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED = 0x4,
    ORIENTATION_PREFERENCE_PORTRAIT_FLIPPED = 0x8
}
[System.Runtime.InteropServices.DllImport( "User32.dll" )]
public static extern bool SetDisplayAutoRotationPreferences( int value );

Upvotes: 2

Related Questions