Search Unity

[SOLVED] How do you get split screen size

Discussion in 'iOS and tvOS' started by monark, Dec 18, 2017.

  1. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,598
    So I have a situation where I need to know the actual size of the frame that Unity is getting rendered into.
    Now normally you can use Screen.width and Screen.height to find this out.
    However if, as in my case, you aren't always rendering at full size and you use Screen.SetResolution(x,y) then that doesn't work any more as Screen.width and height are overridden and remain fixed for the duration of the app regardless of the frame changing size.
    So how to get the actual pixel size of the iOS window?
    I've tried all sorts of options in a little plugin script but nothing seems to get me any values I can use.
    The closest I've come to is by using
    int width = [UIScreen mainScreen].nativeBounds.size.width;
    But that also doesn't change size once you override the screen resolution.

    But there must be somewhere I can read the window frame size from for a split screen view, no?
     
  2. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,598
    By hacking UnityView.mm I can get the values I need from

    CGSize renderSize = CGSizeMake(size.width * self.contentScaleFactor, size.height * self.contentScaleFactor);

    But I'm hoping there is a more elegant way to do this...
     
  3. monark

    monark

    Joined:
    May 2, 2008
    Posts:
    1,598
    So I ended up with this plugin function which appears to work so far

    Code (CSharp):
    1. extern "C"
    2. {
    3.     void getScreenSize()
    4.     {
    5.         float scaleFactor = UnityGetGLView().contentScaleFactor;
    6.         int width = (int)(UnityGetGLView().frame.size.width * scaleFactor);
    7.         int height = (int)(UnityGetGLView().frame.size.height * scaleFactor);
    8.         NSString *tmp = [NSString stringWithFormat:@"%d:%d", width, height];
    9.         const char *str = [tmp UTF8String];
    10.         UnitySendMessage("Scripts", "screenSize", str);
    11.     }
    12. }
    And just call it when the app is unpaused