Unity games for Surface Duo

Important

This article describes functionality and guidance that is in public preview and may be substantially modified before it's generally available. Microsoft makes no warranties, express or implied, with respect to the information provided here.

The Surface Duo Android SDK can be incorporated into Unity mobile games to allow the game view to adapt to the dual-screens and hinge.

Follow the steps below to add the SDK package and access the functionality using Unity's native Android integration.

Installation

  1. Update mainTemplate.gradle to download the Surface Duo Android SDK:

    maven {
        url 'https://pkgs.dev.azure.com/MicrosoftDeviceSDK/DuoSDK-Public/_packaging/Duo-SDK-Feed/maven/v1'
    }
    

    and

    dependencies {
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.61"
        implementation "com.microsoft.device:dualscreen-layout:0.9.0"
    }
    
  2. Copy this script SurfaceDuoScreenHelper.cs into your game project.

  3. Add the dual screen methods to enhance your game for dual-screen devices.

Game preview

To help with your game development, use the game resolution picker to create custom configurations for Surface Duo screens:

  • 2784×1800 – Surface Duo double portrait
  • 1800×2784 – Surface Duo double landscape
  • 1350×1800 – Surface Duo single portrait
  • 1800×1350 – Surface Duo single landscape

You can then add the following code snippet in your game to simulate the hinge area:

#if UNITY_EDITOR
// Hardcode the hinge mask for the Unity game preview
if (Screen.width == DeviceHelper.SURFACEDUO_SPANNEDWIDTH)
{ // double-portrait
    GUI.backgroundColor = Color.gray;
    GUI.Box(new Rect(x: DeviceHelper.SURFACEDUO_SCREENWIDTH, y: 0, width: DeviceHelper.SURFACEDUO_HINGEWIDTH, height: DeviceHelper.SURFACEDUO_SCREENHEIGHT),"");
}
else if (Screen.height == DeviceHelper.SURFACEDUO_SPANNEDHEIGHT)
{ // double-landscape
    GUI.backgroundColor = Color.gray;
    var r = new Rect(x: 0, y: DeviceHelper.SURFACEDUO_SCREENWIDTH, width: DeviceHelper.SURFACEDUO_SCREENHEIGHT, height: DeviceHelper.SURFACEDUO_HINGEWIDTH);
    GUI.Box(r, "");
}
#endif

Note

These values are just to simulate the hinge area in the preview – you should not hardcode these values in your game code, instead use the APIs provided to query for the screen and hinge dimensions.

This Unity screenshot shows the game preview showing the hinge:

Unity editor game preview screenshot