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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

How to disable rotate screen utility by code?

Discussion in 'Windows' started by teexit, Aug 25, 2014.

  1. teexit

    teexit

    Joined:
    Jul 5, 2012
    Posts:
    26
    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?
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,670
    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.
     
  3. teexit

    teexit

    Joined:
    Jul 5, 2012
    Posts:
    26
    Thank you for replay.

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

    Is it has manifest?
     
  4. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,670
    Oh, I assumed WSA.
    What exactly happens for you?
     
  5. teexit

    teexit

    Joined:
    Jul 5, 2012
    Posts:
    26
    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.
     
  6. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,670
    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.
     
  7. teexit

    teexit

    Joined:
    Jul 5, 2012
    Posts:
    26
    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.
     
  8. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,527
  9. teexit

    teexit

    Joined:
    Jul 5, 2012
    Posts:
    26
    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.
     
  10. teexit

    teexit

    Joined:
    Jul 5, 2012
    Posts:
    26
  11. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,527
    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?
     
    Last edited: Aug 27, 2014
  12. teexit

    teexit

    Joined:
    Jul 5, 2012
    Posts:
    26
    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.)
     
  13. Chimique

    Chimique

    Joined:
    Jul 18, 2014
    Posts:
    4
    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 ?
     
  14. teexit

    teexit

    Joined:
    Jul 5, 2012
    Posts:
    26
    No, it's no need to write c++ and compile to dll.

    Just use p/invoke.

    In my case...

    Code (CSharp):
    1. public static void SetScreenOrientationToLandscape()
    2.     {
    3.         if (!isWin8OrHigher())
    4.         {
    5.             return;
    6.         }
    7.  
    8.         SetDisplayAutoRotationPreferences((int)ORIENTATION_PREFERENCE.ORIENTATION_PREFERENCE_LANDSCAPE |
    9.             (int)ORIENTATION_PREFERENCE.ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED);
    10.     }
    11.  
    12. public enum ORIENTATION_PREFERENCE
    13.     {
    14.         ORIENTATION_PREFERENCE_NONE = 0x0,
    15.         ORIENTATION_PREFERENCE_LANDSCAPE = 0x1,
    16.         ORIENTATION_PREFERENCE_PORTRAIT = 0x2,
    17.         ORIENTATION_PREFERENCE_LANDSCAPE_FLIPPED = 0x4,
    18.         ORIENTATION_PREFERENCE_PORTRAIT_FLIPPED = 0x8
    19.     }
    20.     [DllImport("User32.dll")]
    21.     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.
     
  15. Chimique

    Chimique

    Joined:
    Jul 18, 2014
    Posts:
    4
    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.