How to disable rotate screen utility by code?

In win 8 system , it supports auto-rotate screen utility.
Our game is run at desktop(not store app)
Then, we want our game is just only support landscape.
But, I have no ideal to process this.
Is there have any native API that can lock rotate or disable rotate?

You can disable rotation by setting supported rotations to landscape only.
Unity has API to set supported orientations, but in your case it would be best to them in the manifest.

Thank you for replay.

But, my platform is standalone and not "windows store app" or "windows phone app".

Is it has manifest?

Oh, I assumed WSA.
What exactly happens for you?


We deploy our game to surface pro 3.

When we rotate screen, screen is rotate from landscape to portiate.

We want our game is just support landscape(like iOS or wp8).

In some reason, we select standalone to our target on desktop.

Then, we encounter auto-rotation problem.

Why not Windows Store Apps? I mean you can release your game as both Standalone and WSA, first being for desktop only. Making standalone app and targeting tablet is a bit odd.

On Windows tablet it is possible to lock screen, but I don't know if you can do ii programmatically.
What you can do via Unity API, is to detect screen size changes and rotate everything accordingly. See Screen class.

We has some reason that we choice standalone.

  1. Our first target is iOS and Android. And, we use some plugins that just only support iOS, Android and standalone.(for example: PlayMaker).

  2. We have write some plugin, and it only run at iOS, Android and standalone. (for example, render system font texture)

  3. Time schedule.
    So, I do not have other choice...

But, at first time, we have try build win store app or wp8.

Hi,

you can probably do it by using this Windows 8 API:

https://software.intel.com/en-us/blogs/2013/01/10/handling-windows-8-auto-rotate-feature-in-your-application

Though, don't forget to set it back once you're done with your game.


Thank you!

I will try it.

I have other questions want to ask.

  1. unity support dialog to set fullscreen and screen resolution. I want to write my own setting dialog, and I know set resolution can use command line to pass value(like, -screen-width). But, how to pass fullscreen value? I have try to set "Screen.FullScreen" property in game, and it will cause a weird effect. So, I want to know if have command line can support this.

  2. When I execute our game, it always show Unity logo. Is it can set like iOS splash image?

I do not want open other thread to ask these questions, so I ask here.

Hi Tautvydas Zilys,

I have try add this function, and it work perfectly.

There are no need to set it back.

It just effect its application.

Good to know, I'm glad you've solved it!

You can change the splashscreen image in the player settings. You can also change defaults for fullscreen in player settings as well.

P. S. What doesn't work in Screen.fullscreen property?

But, splash screen image is show on config dialog banner.

We want to set our studio logo when game is start, instead of show on config dialog. (The splash image is Unity's logo by default.)

Screen.fullscreen property means...

We want to customize our config dialog. The default config dialog contains "Windowed" check box, and it can control if need to fullscreen.

Our custom config dialog execute game by System.Diagnostice.Process and pass some command line arguments. (Such as, -screen-width or -screen-height)

Now, we want to add a check box that it can set if need to show in fullscreen mode.

In unity document, I cannot find any command about fullscreen.

Now, I pass value by command line args to switch to fullscreen in game, and it will cause a wired gameplay...

If I set fullscreen and play game, then disable fullscreen and play it, again.

It will execute in fullscreen and switch to window mode. (Because I control it by script).

[Work flow]
My custom config dialog(fullscreen is checked) -> execute game -> switch fullscreen -> close game.
My custom config dialog(fullscreen is not checked) -> execute game(it will show fullscreen) -> execute script than became window mode.

So, I want to know if it has a flag to set our game is run in fullscreen or not.

PS: We want to create custom config dialog have some reasons. 1. Unity provide config dialog is very uniform. 2. We don't want to show "Input setting" in config.(because, our game can control by keyboard, mouse and touch screen. Joystick setting is not necessary.)


Hi,

I'm facing the same rotation screen issue on Windows 8.1 Desktop.

I've read the article but i don't know how to proceed. The code appears do be C++. Do we have to compile it to a dll and use it as a plugin in Unity ? Or can I rewrite it directly in a C# script ?

No, it's no need to write c++ and compile to dll.

Just use p/invoke.

In my case...

public static void SetScreenOrientationToLandscape()
    {
        if (!isWin8OrHigher())
        {
            return;
        }

        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
    }
    [DllImport("User32.dll")]
    public static extern bool SetDisplayAutoRotationPreferences(int value);

This setting is just effect this process. It means if you set this value, it does not effect other application.

Thanks for reply !

So actually SetDisplayAutoRotationPreferences is a function provided by user32.dll for windows development and the enum is here for better understanding of the values.