Search Unity

Split screen multitasking - how do you detect when it's being used?

Discussion in 'iOS and tvOS' started by Dreamwriter, Aug 18, 2016.

  1. Dreamwriter

    Dreamwriter

    Joined:
    Jul 22, 2011
    Posts:
    472
    We are adding support for split screen multitasking to our game, but we need to know when the player switches to it, so we can adjust our game's layout. How can we detect this?
     
  2. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    Check the screen resolution, if it's different from the last frame, they you know that either orientation changed or split screen mode was enabled.
     
  3. Dreamwriter

    Dreamwriter

    Joined:
    Jul 22, 2011
    Posts:
    472
    Yeah, I was hoping there would be something more elegant, especially since the user could even start the game in split screen mode and then go to full screen. We're gonna have to detect if the screen resolution changes more than just swapping height and width.
     
  4. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    Check if there's a notification on the native side for split screen mode. If so just implement it and invoke a UnitySendMessage call.
     
  5. Dreamwriter

    Dreamwriter

    Joined:
    Jul 22, 2011
    Posts:
    472
    What I ended up doing was check out what Unity reported for the aspect ratios when in the various split-screen states, and checking for those at game start and when the Application returned from Pause (which always happens when switching between split modes). There are five unique split-screen sizes, their camera.aspect values are:

    Landscape Wide 0.95800078
    Landscape Half-screen 0.6621094
    Landscape Thin 0.3662109
    Portrait Thin: 0.2745242
    Portrait Wide: 0.4677892
     
  6. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    There is no guarantee those aspect values will always be comparable, such is the nature of floats, it's not very bullet proof to do an == or assume those are the only Aspects. Did you test multi monitor?

    I guess if it's only iOS you'll be OK, but would still make the tests approx.
     
  7. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    Doesn't Mathf.Approximately() help for situations like this?
     
  8. Dreamwriter

    Dreamwriter

    Joined:
    Jul 22, 2011
    Posts:
    472
    Oh yeah, I didn't test for the exact values, I basically did things like " > 0.62f && < 0.7f" (I didn't want as accurate as Mathf.Approximately does, in case Apple changes the aspect ratios slightly in the future - my layouts should have a little wiggle room).
     
  9. r618

    r618

    Joined:
    Jan 19, 2009
    Posts:
    1,305
    that's good to know

    don't assume anything about concrete ratios though. there might be more of them in the future, even maybe freely resizable split mode/s for apps in iOS plus two versions for example.
     
  10. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    Why do you need to know this? I mean, unity's ui system automatically adjusts to this setting assuming you setup your anchors correctly.
     
  11. Dreamwriter

    Dreamwriter

    Joined:
    Jul 22, 2011
    Posts:
    472
    The UI system does, but our game has more in it than just UI :p Also, the portrait-thin split screen is quite the extreme case, so even the UI system had problems with that one.
     
  12. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    The UI system is flexible, it adapts to any aspect ratio. Can you not make your game the same way? What kind of game are you making?
     
  13. Dreamwriter

    Dreamwriter

    Joined:
    Jul 22, 2011
    Posts:
    472
    I can't imagine hardly any game at all ever that would look its best in the thin portrait split-screen aspect unless it was designed specifically for that (or an overhead vertical shooter or something). Particularly if it used automated code to rearrange things for any aspect ratio in general, as opposed to someone manually designing an interface specifically around such a super tall, thin aspect. Which is what we did, it took all of a couple hours to create 5 new customized layouts for our game to look and play good in the 5 split-screen aspect ratios. If we couldn't have done it, we wouldn't have supported the multitasking at all. We had already created customized layouts for landscape, portrait, tablet landscape, tablet portrait, even iPhone 4 aspect, to make sure our game looked the best no matter how the player wanted to play.

    I mean, think about it. Let's say you are making a 2D fighting game. Wouldn't it be a hell of a lot better in portrait-thin to change the life bars to vertical along the sides rather than tiny hard-to-read things over the top? Or change an onscreen virtual d-pad/button the same way, put the d-pad at the bottom and the buttons directly above it so you can keep them full size? Sure, the 4.6 UI system is very cool, and the way it can auto-adjust using the anchoring system is great (and I found it a lot easier to work with than the similar feature in NGUI), but there are some extreme cases where a personal touch can make a big difference for game quality.
     
  14. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    Another thing to note is that you don't have to support split screen mode. Games generally don't support it. It's usually left for general/productivity apps in my opinion.
     
  15. hippogames

    hippogames

    Joined:
    Feb 5, 2015
    Posts:
    234
    If someone needs to detect if the app is running/switched to Split Screen, there is a simple solution, just check if Screen.width fits any of known (at the moment) iPad resolution sizes (portrait + landscape): 2048, 2732, 2224, 1668, 1536 px.
    var knownScreenSizes = new List<int> { 2048, 2732, 2224, 1668, 1536 };
    var fullScreen = knownScreenSizes.Contains(Screen.width);
    var splitScreen = !fullScreen;

    BTW You can check it it's iPad using UnityEngine.iOS.Device.generation.ToString().Contains("iPad");