Forum Discussion

DStephensJr's avatar
DStephensJr
Copper Contributor
Jun 10, 2021

Unity Surface Duo Sample is broken

The sample project at https://github.com/microsoft/surface-duo-sdk-unity-samples doesn't reliably support device rotation on the Surface Duo.

 

But first, a big thanks to Craig Dunn (sorry, don't know the @.) for the much improved explanation of the Unity gradle setup (https://devblogs.microsoft.com/surface-duo/dual-screen-games-with-unity-for-android/).

 

I build the project with no changes (except the gradle fixes) and run it on the Duo.  Initially, it detects the orientation and adjusts the screen size and orientation, but after a few rotations, it gets stuck and draws and reports LandscapeLeft while in Portrait on the left panel, but moving to the right doesn't matter. Eventually, the display starts flipping rapidly between display modes on its own.

 

Spanning the two screens appears to basically work, but rotation to Portrait modes draws upside down consistently for both detected modes.

 

I actually suspect the included jar file, but I'm at a loss to deal with this issue.  

 

Beyond that, I don't find other complaints, so I wonder it I have done something else wrong.

 

And it doesn't build in Unity 2020 or 2021 versions either. 

 

I would like to do something that supports the Duo and multi-displays, but I'm stuck here.  Any clues?

 

Thanks.

 

 

3 Replies

  • DStephensJr I haven't looked at Unity in a while, but I can confirm that last version update we did was for 2019.4 because it's the LTS version. It seems like each version of Unity slightly changes how it integrates with gradle and native packages, so will have to investigate newer versions to see if there's anything we need to update.

     

    The DisplayMask jar file is our core dual-screen library, so the issues are more likely to be the sample itself, or interactions with how Unity is detecting device orientation. 

     

    Note that LandscapeLeft versus LandscapeRight refers to the the orientation with respect to the phone's controls, it does not refer to the left/right screens of the Surface Duo.

     

    While it's not likely to be the cause of any of these issues, could you share which Unity version you're building with and which OS version your Surface Duo is running? 

     

    • DStephensJr's avatar
      DStephensJr
      Copper Contributor
      I am using the latest Unity released build. Unity 2012.1.10f1
      My Duo reports build number 2021.419.70.

      I did update the sample app with the items I previously described (gradle and properties, maven does not appear to be necessary and may mean properties changes are unnecessary as well).

      Both the 2019 Unity and the 2021Unity compilations have terribly scrambled behaviors for the screen orientation. In Dual (spanned) mode, the portrait orientations are inverted from the device to the screen. That is, Device reports Device reports Portrait and Screen reports PortraitUpsideDown and displays upside down. When Device reports PortraitUpsideDown, Screen reports Portrait, but the display remains upside down.

      I don't think it has anything do with the Sample, but it could be Unity or something in the interaction of the Duo with Unity. Razer Phone 2 works (correctly) as expected.

      Thanks again.
    • DStephensJr's avatar
      DStephensJr
      Copper Contributor

      Craig_Dunn 

      Thanks for the reply.

      Yes.  Every minor dot release of Unity seems to bring more trouble.

       

      I have been able to move a little forward with Unity 2021.1.

      This is what I've done:

      Project Settings -> Player -> Publish Settings:

      Build

        Custom Main Gradle Template = Checked. "mainTemplate.Gradle"

        Custom Gradle Properties Template = Checked. "gradleTemplate.properties"

       

      in mainTemplate.Gradle, added a section from the sample duo-screenhelper/Screenshots/mainTemplate.gradle.

      =====

      allprojects {

      repositories {

      mavenCentral()
      google()
      jcenter()
      flatDir {
      dirs 'libs'

      }
      maven {

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

      }

      }

      =====

       

      and from code examination and a little digging,

      =====

      dependencies {

      implementation "com.microsoft.device.dualscreen:screenmanager-displaymask:1.0.0-beta2"

      **DEPS**}

      =====

       

      This forced a change in Project Settings -> Player -> Other Settings

      • Identification -> Minimum  API Level = Android 5.0 (API 21).

       

      For GradleTemplate.properties I had to add a couple lines:

      android.useAndroidX=true
      android.enableJetifier=true
      Another build error from changes forced these updates.

       

      I also added into the code Input.DeviceOrientation.  I wanted to compare it against the Screen.Orientation to see if they matched (not always) and if there was something I could do to force the correct answer.

       

      Currently, I finally get "IsDeviceSurfaceDuo" to return true.  I am altering my own project and it may be causing some issues, but I have also checked on a Razer Phone 2 and everything has worked as expected.

       

      I hope that this can be helpful to anyone that may be experiencing similar issues.  I also hope, that I haven't introduced more problems in the process. 😉

       

      :-Dan (@DStephensJr) 

Resources