-
Notifications
You must be signed in to change notification settings - Fork 966
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement new Authenticate method with different interactivities and …
…enumerated result codes. PiperOrigin-RevId: 289671807 Change-Id: I5c3b67ff8631cec3369696c034ee3b499558eba6
- Loading branch information
1 parent
c5c81bd
commit b1357da
Showing
9 changed files
with
284 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
source/PluginDev/Assets/GooglePlayGames/BasicApi/SignInHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace GooglePlayGames.BasicApi | ||
{ | ||
public class SignInHelper | ||
{ | ||
private static int True = 0; | ||
private static int False = 1; | ||
private const string PromptSignInKey = "prompt_sign_in"; | ||
|
||
public static SignInStatus ToSignInStatus(int code) | ||
{ | ||
Dictionary<int, SignInStatus> dictionary = new Dictionary<int, SignInStatus>() | ||
{ | ||
{ | ||
/* CommonUIStatus.UI_BUSY */ -12, SignInStatus.AlreadyInProgress | ||
}, | ||
{ | ||
/* CommonStatusCodes.SUCCESS */ 0, SignInStatus.Success | ||
}, | ||
{ | ||
/* CommonStatusCodes.SIGN_IN_REQUIRED */ 4, SignInStatus.UiSignInRequired | ||
}, | ||
{ | ||
/* CommonStatusCodes.NETWORK_ERROR */ 7, SignInStatus.NetworkError | ||
}, | ||
{ | ||
/* CommonStatusCodes.INTERNAL_ERROR */ 8, SignInStatus.InternalError | ||
}, | ||
{ | ||
/* CommonStatusCodes.DEVELOPER_ERROR */ 10, SignInStatus.DeveloperError | ||
}, | ||
{ | ||
/* CommonStatusCodes.CANCELED */ 16, SignInStatus.Canceled | ||
}, | ||
{ | ||
/* CommonStatusCodes.API_NOT_CONNECTED */ 17, SignInStatus.Failed | ||
}, | ||
{ | ||
/* GoogleSignInStatusCodes.SIGN_IN_FAILED */ 12500, SignInStatus.Failed | ||
}, | ||
{ | ||
/* GoogleSignInStatusCodes.SIGN_IN_CANCELLED */ 12501, SignInStatus.Canceled | ||
}, | ||
{ | ||
/* GoogleSignInStatusCodes.SIGN_IN_CURRENTLY_IN_PROGRESS */ 12502, SignInStatus.AlreadyInProgress | ||
}, | ||
}; | ||
|
||
return dictionary.ContainsKey(code) ? dictionary[code] : SignInStatus.Failed; | ||
} | ||
|
||
/// <summary> | ||
/// Used during authentication to save if the user should be prompted to interactive sign in next time they | ||
/// try to authenticate with SignInInteractivity.CanPromptOnce. | ||
/// </summary> | ||
/// <param name="value"></param> | ||
public static void SetPromptUiSignIn(bool value) | ||
{ | ||
PlayerPrefs.SetInt(PromptSignInKey, value ? True : False); | ||
} | ||
|
||
/// <summary> | ||
/// Used during authentication with SignInInteractivity.CanPromptOnce to understand whether or not the user should be | ||
/// prompted to interactive sign in. | ||
/// </summary> | ||
/// <returns></returns> | ||
public static bool ShouldPromptUiSignIn() | ||
{ | ||
return PlayerPrefs.GetInt(PromptSignInKey, True) != False; | ||
} | ||
|
||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
source/PluginDev/Assets/GooglePlayGames/BasicApi/SignInInteractivity.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
namespace GooglePlayGames.BasicApi | ||
{ | ||
public enum SignInInteractivity | ||
{ | ||
/// <summary>no UIs will be shown (if UIs are needed, it will fail rather than show them).</summary> | ||
NoPrompt, | ||
|
||
/// <summary> | ||
/// This may show UIs, consent dialogs, etc. | ||
/// At the end of the process, callback will be invoked to notify of the result. | ||
/// Once the callback returns true, the user is considered to be authenticated | ||
/// forever after. | ||
/// </summary> | ||
CanPromptAlways, | ||
|
||
/// <summary>When this is selected, PlayGamesPlatform.Authenticate does the followings in order: | ||
/// 1. Attempt to silent sign in. | ||
/// 2. If silent sign in fails, check if user has previously declined to sign in and don’t prompt interactive | ||
/// sign in if they have. | ||
/// 3. Check the internet connection and fail with NO_INTERNET_CONNECTION if there is no internet connection. | ||
/// 4. Prompt interactive sign in. | ||
/// 5. If the interactive sign in is cancelled, then memorize this for the 2nd step of the next sign. | ||
/// </summary> | ||
CanPromptOnce | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.