Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Google Play Games Integration?

Discussion in 'Daydream' started by Claytonious, Jan 9, 2017.

  1. Claytonious

    Claytonious

    Joined:
    Feb 16, 2009
    Posts:
    553
    What, if any, integrations exist "out of the box" for Play Games services? For example, if we try to show an achievement or a leaderboard while in Daydream, what happens? I assume something terrible happens - such as trying to show regular 2D UI. Or maybe nothing. Or maybe ... just maybe ... something appropriate for Daydream happens?

    For that matter, even the default UI for showing the login is concerning - will that try to show inappropriate 2D UI while in Daydream if we use the new seamless Play Games login?

    Thanks!
     
  2. dsternfeld

    dsternfeld

    Official Google Employee

    Joined:
    Jan 3, 2017
    Posts:
    72
    Unfortunately, there is no out of the box integration for play games services. It is possible to make it work yourself, but you are correct to suspect that you will run into problems with the application displaying 2D UI.

    If you do go down that route, you will want to make sure the user is automatically signed-in, and defer sign-in if that isn't possible. When you need to display 2D UI, you will have to prompt the user to remove the headset first.

    Thanks,

    Dan
     
  3. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    752
    Are there any plans for making GPGS work properly in VR Mode? This seem kind of important
     
  4. Claytonious

    Claytonious

    Joined:
    Feb 16, 2009
    Posts:
    553
    That's really bad news. We want to at least use leaderboards. In order to accomplish that, we are going to have to ask the user if he is willing to remove the headset, and if he says yes, then somehow get ourselves back out of stereoscopic mode long enough to authenticate him, then ask him to put it back on and return to stereo after that point?

    I get that once he is already authenticated this won't be necessary on subsequent sessions, but argh!

    I also have no beef with having to show our own custom ui for the leaderboards themselves. But the authentication ui is out of our control.

    Is there anything in the roadmap to fix this @dsternfeld?
     
  5. dsternfeld

    dsternfeld

    Official Google Employee

    Joined:
    Jan 3, 2017
    Posts:
    72
    We are discussing the issue but unfortunately I don't have an answer for you yet. I suggest that you try to avoid depending upon any improvements here for the time being.

    Thanks,

    Dan
     
  6. Claytonious

    Claytonious

    Joined:
    Feb 16, 2009
    Posts:
    553
    Understood. It's a bummer but appreciate the transparency. Will see what we can do within these constraints.
     
  7. overfile

    overfile

    Joined:
    Oct 21, 2013
    Posts:
    27
    Hi Claytonious,

    Recently i publish a game with Google Play Games Services and i had the same issue.

    In my experinece, we can force to silent login in the script PlayGamesPlatform.cs, but if you force the silent in the first login, the connect is fail only in the first open game, next opening game works in silent ok, so i changed the script with:

    public void Authenticate(Action<bool, string> callback, bool silent)
    {
    // make a platform-specific Play Games client
    if (mClient == null)
    {
    GooglePlayGames.OurUtils.Logger.d(
    "Creating platform-specific Play Games client.");
    mClient = PlayGamesClientFactory.GetPlatformPlayGamesClient(mConfiguration);
    mClient.Authenticate(callback, silent);
    }
    else
    {
    mClient.Authenticate(callback, true);
    }
    // authenticate!

    }

    With this, only show one login panel and this works perfectly on Motorola Moto Z because the login panel only show in top windows area and didn't show in google daydream headset.

    I hope i'm can help you.

    Regards.
     
    Claytonious likes this.
  8. Claytonious

    Claytonious

    Joined:
    Feb 16, 2009
    Posts:
    553
    Thanks @overfile, will definitely try that!
     
  9. Dirly

    Dirly

    Joined:
    Mar 24, 2013
    Posts:
    17
    Any news on GPGS integration? I know during google I/O it sounded like they were coming up with a 2D solution within daydream to cover these kinds of things.
     
  10. Claytonious

    Claytonious

    Joined:
    Feb 16, 2009
    Posts:
    553
    ..bump ... has there been any news on this front? We would still very much like to use google play games at *least* for authentication of the user, if not the full suite. @dsternfeld ?
     
  11. Claytonious

    Claytonious

    Joined:
    Feb 16, 2009
    Posts:
    553
    BTW, @overfile, we did try that, and our app was rejected for the Daydream store because it still showed 2D ui in some scenarios. So we had to remove to get re-approved.

    So at the moment, there appears to be no safe way to use google play games with a Daydream app - there is no way to *guarantee* that 2D ui will never be shown even in all corner cases.
     
  12. Claytonious

    Claytonious

    Joined:
    Feb 16, 2009
    Posts:
    553
  13. Dirly

    Dirly

    Joined:
    Mar 24, 2013
    Posts:
    17
  14. Claytonious

    Claytonious

    Joined:
    Feb 16, 2009
    Posts:
    553
    We ran into the other usual problems of Google Play Services failing to initialize correctly due to cryptic errors, so have not yet had a chance to try it. Once we spend some time on Android again I will let you know when we do.
     
  15. dsternfeld

    dsternfeld

    Official Google Employee

    Joined:
    Jan 3, 2017
    Posts:
    72
    There is no new news on this front. You're welcome to use it, but it will require some custom work to avoid showing 2D UI.

    Thanks,

    Dan
     
  16. Dirly

    Dirly

    Joined:
    Mar 24, 2013
    Posts:
    17
  17. Dirly

    Dirly

    Joined:
    Mar 24, 2013
    Posts:
    17
  18. Dirly

    Dirly

    Joined:
    Mar 24, 2013
    Posts:
    17
    Still broken on 8.1... god this is infuriating was working on 7.1
     
  19. jandans

    jandans

    Joined:
    Dec 25, 2014
    Posts:
    1
    I'm just going to advertise some random dudes open source project here https://github.com/unity-plugins/google-services-unity

    Before I found this I was using Play Game Services plugin... and most of the time it failed to authorise... Of course the setup process is a little bit of pain, cuz atleast of my knowing you cannot disable Adwords and Firebase... and also manifest is missing some namespaces.... and if youre using unity adds it will conflict with tha unity add lib thats in the plugin..... oh and no GUI setup tool....

    After you fix those tiny issues with manifest and conflicting namespaces..... and impliment this in your code it will work from Android 5.0 to 8.0 atleast on my devices it did...
    But the issue with that plugin is that I cant get it to work with Android 4.2 and 4.4 for now.... it apears that there is some kind of incompatability with Play services lib on Android 4
     
  20. Macklin

    Macklin

    Joined:
    Jun 13, 2015
    Posts:
    3
    I recently ran into this mess while implementing Google Play Games services in a VR game for Daydream - specifically for use as a GameSparks login. While the most ideal solution would be for Google to add an in-headset VR prompt for authenticating/downloading Google Play Games (similar to how other permissions are presented in VR in Nougat upwards), the current recommended solution is to transition to 2D before providing the prompt, as to adhere to UX-D9. Your Daydream app will not be accepted to Google Play if this requirement is not met.

    This "loud" authentication process needs to occur at least once for the user, all subsequent authentications can be done silently. A silent authentication can be done by using the "silent" parameter on one of the method overloads of GooglePlayGames.Authenticate. In addition to worrying about the auth prompt, we also have to deal with the common problem of the user not having the Google Play Games app installed to their device. The plugin handles this internally during the GooglePlayGames.Authenticate process (it occurs before the actual authentication prompt, even if the silent parameter is true), and will bring up a dialogue linking the user to the Google Play store page. Since it will be drawn over the top of our VR content, we need to make sure that if the user doesn't have the app installed, we are transitioned to 2D before attempting an authentication.

    The process that I use is as follows:
    1. Check that the Google Play Games app is installed. Thankfully the property GooglePlayGames.OurUtils.PlatformUtils.Supported provides this functionality. If the app is not installed, go to step #3 and skip the initial silent auth.
    2. If the app is installed, continue with a silent auth. If the authentication returns true - the user is authenticated, if it returns false - the silent auth failed and either the user doesn't have internet access, or this is their first time authenticating this application.
    3. In this case, we need to transition to 2D. Firstly, show a world space in-VR UI telling the user to remove their device from the viewer/headset.
    4. Check for device orientation change to anything other than landscape, then unload the VR device and trigger the prompt by calling PlayGamesPlatform.Authenticate, this time without the silent flag. I also show a 2D background similar to the one shown in the link above.
    5. Wait for the authentication to return true. Once it does, show the user a button to return to VR. It should be noted that if the Google Play Games app was not installed when we called PlayGamesPlatform.Authenticate, the authentication will return false. So we'll have to call it again to bring up the prompt. It might be a good idea to have the user confirm that they have installed the application in order to perform another authentication.
    6. When the user presses the button, hide any 2D UI's, load the previously-disabled VR device, enable VR and reset the screen orientation to landscape.
    Here's the code I use when starting the auth. This example does not handle checking if Google Play Games is installed.
    Code (CSharp):
    1. // Called during the start of your application, at a time where we know the user is in VR.
    2. void DoPlatformLogin(bool silentAuth = true)
    3. {
    4.     PlayGamesPlatform.Instance.Authenticate((success) =>
    5.     {
    6.         // Authentication success
    7.         if (success)
    8.         {
    9.             // If the non-silent authentication succeeds, show the return to VR button in the 2D dialogue
    10.             if (!silentAuth)
    11.             {
    12.                 Debug.Log("UserManager - DoPlatformLogin - Non-silent authentication succeeded!");
    13.  
    14.                 // This method enables the "Return to VR" button in the 2D UI
    15.                 UI_GooglePlayGames.ShowReturnToVR(AUTH_SUCCESS);
    16.             }
    17.  
    18.             // Do whatever we want post-auth here...
    19.         }
    20.  
    21.         // Authentication failure
    22.         else
    23.         {
    24.             // If the silent auth fails it means this is the first time the user is authenticating the application. According to Daydream UX-D9, we have to switch to non-VR mode to present any 2D prompts.
    25.             if (silentAuth)
    26.             {
    27.                 Debug.Log("UserManager : DoPlatformLogin - Google Play Games silent authentication failed. Prompting the user to switch to 2D...");
    28.  
    29.                 UI_GooglePlayGames.TransitionTo2D(() => DoPlatformLogin(false));
    30.             }
    31.  
    32.             // If we're here, it means that both auth attempts failed ¯\_(ツ)_/¯
    33.             else
    34.             {
    35.                 Debug.Log("UserManager - DoPlatformLogin - Authentication failed!");
    36.  
    37.                 // Show the return to VR button, but with an error message
    38.                 UI_GooglePlayGames.ShowReturnToVR(AUTH_ERROR);
    39.             }
    40.         }
    41.  
    42.     }, silentAuth);
    43. }
    44.  

    And how I'm transitioning from and to VR
    Code (CSharp):
    1. // Static method called by DoPlatformLogin which will transition the user to 2D, and then call OnSwitched when ready. Of course you can hook the method up however you want, but in this case I use a singleton pattern for ease of use.
    2. public static void TransitionTo2D(System.Action OnSwitched)
    3. {
    4.     instance.StartCoroutine(instance.TransitionTo2DRoutine(OnSwitched));
    5. }
    6.  
    7. // This is a fairly basic routine that will be called when we have to present the user with a loud Google Play Games authentication prompt:
    8. // 1. Show a world-space UI telling the user to remove their phone from the HMD.
    9. // 2. Wait for the user to switch the device orientation to portrait or faceup
    10. // 3. Disable VR and rotate the device to portrait mode.
    11. // 4. Hide the VR world-space UI, and show the 2D screen-space UI.
    12. // 5. OnSwitched is called when we have fully transitioned to the 2D UI
    13. IEnumerator TransitionTo2DRoutine(System.Action OnSwitched)
    14. {
    15.     // Save the loaded VR device, even though it should always be "daydream"
    16.     loadedVrDevice = UnityEngine.XR.XRSettings.loadedDeviceName;
    17.  
    18.     // Save the original orientation of the VR mode, since it may be different on different devices (you never know)
    19.     vrOrientation = Screen.orientation;
    20.  
    21.     // Show the VR UI. This is the world space UI telling the user to remove their device from the viewer.
    22.     // In my case I have a fancy UI that gets transitioned in over a few seconds, so I have to wait for it (hence the yield).
    23.     yield return ToggleVRUIRoutine(true);
    24.  
    25.     // Wait indefinitely until the OS orientation reports DeviceOrientation.Portrait or DeviceOrientation.FaceUp
    26.     while (true)
    27.     {
    28. #if UNITY_EDITOR
    29.         // Provided for testing purposes
    30.         if (Input.GetKeyDown(KeyCode.Space))
    31. #else
    32.         if (Input.deviceOrientation == DeviceOrientation.Portrait || Input.deviceOrientation == DeviceOrientation.FaceUp)
    33. #endif
    34.         {
    35.             Debug.Log("UI_GooglePlayGames : TransitionTo2DRoutine - Switching to 2D and disabling VR...");
    36.             break;
    37.         }
    38.  
    39.         yield return null;
    40.     }
    41.  
    42.     // Unload Google VR device by loading the device "" or "None"
    43.     UnityEngine.XR.XRSettings.LoadDeviceByName("");
    44.  
    45.     // Wait until the loadedDeviceName is empty. You can also return null or new WaitForEndOfFrame(), but I found waiting for this property to be emptied works well
    46.     yield return new WaitUntil(() => string.IsNullOrEmpty(UnityEngine.XR.XRSettings.loadedDeviceName));
    47.  
    48.     // Switch the orientation to portrait
    49.     Screen.orientation = ScreenOrientation.Portrait;
    50.  
    51.     // Hide the VR UI (this is the same UI we enabled above)
    52.     ToggleVRUIRoutine(false);
    53.  
    54.     // Show the 2D UI, and wait for it to be shown
    55.     yield return Toggle2DUIRoutine(true);
    56.  
    57.     // Call OnSwitched (this will cause the permissions prompt to be shown)
    58.     if (OnSwitched != null)
    59.         OnSwitched();
    60. }
    61.  
    62. // This is called by the UI.Button OnClick event
    63. public void ReturnToVRButton()
    64. {
    65.     StartCoroutine(TransitionToVRRoutine());
    66. }
    67.  
    68. IEnumerator TransitionToVRRoutine()
    69. {
    70.     // Load the previously disabled VR device
    71.     UnityEngine.XR.XRSettings.LoadDeviceByName(loadedVrDevice);
    72.  
    73.     // Wait until load is complete
    74.     yield return new WaitUntil(() => UnityEngine.XR.XRSettings.loadedDeviceName == loadedVrDevice);
    75.  
    76.     // Enable VR
    77.     UnityEngine.XR.XRSettings.enabled = true;
    78.  
    79.     // Toggle the 2D UI off, and wait for it
    80.     yield return Toggle2DUIRoutine(false);
    81.  
    82.     // Reset the screen orientation
    83.     Screen.orientation = vrOrientation;
    84. }
    85.  

    Regarding the "EnableHidePopups" configuration option - this will only hide things like achievement and post-login popups that appear at the top of the screen, and will have no affect on the whether the auth or install prompts show or not. It is recommended to set this in your configuration anyway.
     
    Last edited: Mar 23, 2018
    13Flo and Claytonious like this.
  21. 13Flo

    13Flo

    Joined:
    Jun 9, 2015
    Posts:
    87
    Really helpful. Thanks Macklin!
     
  22. 13Flo

    13Flo

    Joined:
    Jun 9, 2015
    Posts:
    87
    Using EnableHidePopups() breaks the authentication process on Daydream though.
    I'm running Android 8.0 on Galaxy S8.

    I wish we could use EnableHidePopups() after authentication succeed, but that doesn't seem possible.
    PlayGamesClientConfiguration.IsHidingPopups is read only, and reinitializing is automatically skipped.

    Did anybody find a work around that issue? I guess my build will not pass the review process if my game displays 2D notifications (popups).
     
  23. 13Flo

    13Flo

    Joined:
    Jun 9, 2015
    Posts:
    87