playgameservices / play-games-plugin-for-unity

Google Play Games plugin for Unity
Other
3.46k stars 966 forks source link

SignOut event/callback #1623

Closed elitvynov closed 7 years ago

elitvynov commented 7 years ago

Hi, Play Games Native UI has ability to sign out (from achievements/leaderboards UI menu). I would like to know, does plugin have ability to listen this event? We need this uncommon functionality to track, if player does logout from game. In this case we save his choice and don't ask him to authenticate next time he launches the game.

I think we can simulate this event using Update or OnApplicationPause Unity's events, where we can check last and current Social.localUser.authenticated state. But, maybe we have a better solution?

elitvynov commented 7 years ago

Additional information: I've tried to use OnApplicationPause Unity's event. The logic is next:

public void OnApplicationPause(bool pause)
{
    // player opens Leaderboard UI
    if (pause)
    {
        // let's save current state
        _isAuthenticated = Social.localUser.authenticated;
    }
    // return to the game
    else
    {
        Debug.Log("unpause _isAuthenticated = " + _isAuthenticated + ", " + Social.localUser.authenticated);

        // player has logged out from native UI
        if (_isAuthenticated && Social.localUser.authenticated == false)
        {
            // player did log out from Play Games
        }
    }
}

The problem is, when I logout from Play Games and return to the game, I got next log: unpause _isAuthenticated = true, true

So, the problem is, Plugin thinks player still logged in, and I cannot use this approach to detect logout event. Meanwhile, after my log I see log information from Plugin: Showing UI Internal callback: ERROR_NOT_AUTHORIZED Invoking user callback on game thread Recived UI Internal callback: ERROR_NOT_AUTHORIZED Starting Auth Transition. Op: SIGN_OUT status: ERROR_NOT_AUTHORIZED Can you please suggest me any workaround, how to catch this sign out event from plugin?

claywilkinson commented 7 years ago

There really is no one place to fire an event for signing out. The best approach would be to check IsAuthenticated() in an coroutine or when you would do something different based on the state.

elitvynov commented 7 years ago

Yeap, I made this check via coroutine