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

Set target resolution per Device

Discussion in 'iOS and tvOS' started by cuttlefish-creations, Aug 24, 2015.

  1. cuttlefish-creations

    cuttlefish-creations

    Joined:
    Jun 28, 2015
    Posts:
    21
    Hi,

    I'm searching for a way to set target resolution to 'best performance' only on iphone 4 and some Ipad Versions.
    The only ways I have found on the internet are: using IphoneGeneration. But that seems to be deprecated. Or editing the AppController.mm in xcode. But I don't understand how.

    Is anyone familiar with how this should be handled.

    Regards
     
  2. Alexey

    Alexey

    Unity Technologies

    Joined:
    May 10, 2010
    Posts:
    1,602
  3. cuttlefish-creations

    cuttlefish-creations

    Joined:
    Jun 28, 2015
    Posts:
    21
    ahaaa :)

    Thank you, did not seem to find that! :p ... I did however fixed it overnight by editing Devicesettings.mm (instead of AppController.mm) in Xcode, and that fixed everything :). Very easy to set a multiplication of the Resolution!
    Thank you anyway.
     
  4. thecodes

    thecodes

    Joined:
    Jul 9, 2015
    Posts:
    20
    Here is a pure script way of doing this. I use the awake function on a script attached to the camera, but you could stick it on any object I suppose.

    I wanted my cut scene to be full res on these devices because the cut scenes in my case are not GPU intensive but looked horrible in "performance mode".

    The code has two parts, one that sets a few variables (scaledWidth, and scaledHeight). On change scene function I set the the width and height to their scaled variants, you can just change the last line in the awake function to scaledWidth and scaledHeight and remove the LoadScene function if you aren't using a full res cut scene.

    Code (CSharp):
    1.    
    2.  
    3.     int scaledWidth = -1;
    4.     int scaledHeight = -1;
    5.  
    6.     void Awake() {
    7.  
    8.  
    9.         if (SystemInfo.deviceType == DeviceType.Handheld) {
    10.  
    11.  
    12.             int devWidth = Display.main.systemWidth;
    13.             int devHeight = Display.main.systemHeight;
    14.  
    15.             Debug.Log ( "devwidth=" + devWidth + " devheight=" + devHeight );
    16.             Debug.Log ( "width=" + Screen.width + " height=" + Screen.height );
    17.  
    18.             // the scaled resolution, we want to remember this because
    19.             // when we need to set it back for performance just as we swap scenes
    20.             scaledWidth = devWidth;
    21.             scaledHeight = devHeight;
    22.  
    23.             switch (UnityEngine.iOS.Device.generation) {
    24.  
    25.                 case UnityEngine.iOS.DeviceGeneration.iPadMini1Gen :
    26.                 case UnityEngine.iOS.DeviceGeneration.iPad2Gen :
    27.  
    28.                     Debug.Log ( "gen 2 ipad" );
    29.  
    30.                     scaledWidth = 600;
    31.                     scaledHeight = 800;
    32.  
    33.                     break;
    34.  
    35.                 case UnityEngine.iOS.DeviceGeneration.iPadMini2Gen :
    36.                 case UnityEngine.iOS.DeviceGeneration.iPad3Gen :
    37.                    
    38.                     Debug.Log ( "gen 3 ipad" );
    39.                    
    40.                     scaledWidth = 1200;
    41.                     scaledHeight = 1600;
    42.                    
    43.                     break;
    44.  
    45.                 // add more cases as needed.
    46.  
    47.             }
    48.                
    49.             Screen.SetResolution ( devWidth, devHeight, true);
    50.  
    51.         }
    52.  
    53.     }
    54.  
    55.     // note in practice you want to do this after you fade the
    56.     // scene out to black or some other color because the
    57.     // change in resolution is ugly.
    58.     void LoadScene () {
    59.  
    60.         Application.LoadLevel ("some_scene");
    61.         Debug.Log ("done");
    62.  
    63.         if (scaledWidth != -1)
    64.                 Screen.SetResolution ( scaledWidth, scaledHeight, true);
    65.  
    66.  
    67.     }
    68.  
    69.