Open RocksteadyDog opened 3 years ago
Hi! I can't reproduce this behaviour on 2020.3.8f1, but it looks like you got into android-specific code that simulator can't emulate but tries😁. Maybe you should wrap your code into this combination of defines:
#if UNITY_ANDROID && !UNITY_EDITOR
i did so and the problem was solved (#if !UNITY_EDITOR)
Hi, can you show me the solution?
Hi, can you show me the solution?
` using UnityEngine; using System.Collections; using System; using GooglePlayGames; using GooglePlayGames.BasicApi; // using UnityEngine.SocialPlatforms; // using Google.Play.Common; // using GooglePlayGames.BasicApi; // using GooglePlayGames.BasicApi.SavedGame; // using GooglePlayGames.OurUtils;
public sealed class PlayGamesController : SingletonMonoBehaviour
public bool IsAuthenticated() => PlayGamesPlatform.Instance.IsAuthenticated();
public static Action<bool> onSocialActivated;
////////////////////////////////////////////////////////////////////////////
string UserName => PlayGamesPlatform.Instance.localUser.userName;
////////////////////////////////////////////////////////////////////////////
void Start()
{
if (IsPlayServicesAvailable())
{
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
.EnableSavedGames()
.Build();
PlayGamesPlatform.InitializeInstance(config);
// PlayGamesPlatform.DebugLogEnabled = true;
PlayGamesPlatform.Activate();
}
}
void OnDestroy()
{
ClearSingleton();
}
////////////////////////////////////////////////////////////////////////////
public void Init(Action<bool> callback)
{
SocialLog("Init...");
if (IsEditor() || !IsPlayServicesAvailable())
{
SocialLog("Not Available");
OnDone(false);
return;
}
if (PlayGamesPlatform.Instance.IsAuthenticated())
{
SocialLog("Welcome " + UserName);
OnDone(true);
}
else
{
SocialLog("Authenticating...");
PlayGamesPlatform.Instance.Authenticate(signInInteractivity, status =>
{
if (status == SignInStatus.Success)
{
SocialLog("Welcome " + UserName);
OnDone(true);
}
else
{
SocialLog("Authentication Status: " + status);
OnDone(false);
}
if (signInInteractivity == SignInInteractivity.CanPromptAlways)
{
signInInteractivity = SignInInteractivity.CanPromptOnce;
}
});
}
void OnDone(bool authenticated)
{
if (onSocialActivated != null)
onSocialActivated(authenticated);
if (callback != null)
callback(authenticated);
}
}
void SocialLog(string text)
{
GameLog.Print("[GPGS]", text);
}
public void Connect(Action successCallback)
{
if (!IsEditor() && IsPlayServicesAvailable())
{
PlayGamesPlatform.Instance.Authenticate(result =>
{
if (result)
{
if (successCallback != null)
successCallback();
}
});
}
}
public void ForceAuthenticate()
{
signInInteractivity = SignInInteractivity.CanPromptAlways;
}
public static bool IsEditor()
{
return false;
return true;
}
public static bool IsPlayServicesAvailable() { if (IsEditor()) return false;
try
{
const string GoogleApiAvailability_Classname = "com.google.android.gms.common.GoogleApiAvailability";
AndroidJavaClass clazz = new AndroidJavaClass(GoogleApiAvailability_Classname);
AndroidJavaObject obj = clazz.CallStatic<AndroidJavaObject>("getInstance");
var androidJC = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
var activity = androidJC.GetStatic<AndroidJavaObject>("currentActivity");
int value = obj.Call<int>("isGooglePlayServicesAvailable", activity);
// 0 == success
// 1 == service_missing
// 2 == update service required
// 3 == service disabled
// 18 == service updating
// 9 == service invalid
return value == 0;
}
catch (Exception ex)
{
Debug.LogError(ex);
return false;
}
}
}
`
With device simulator authentication is in progress and i get warnings: *** [Play Games Plugin 0.10.12] 05.17.21 10:06:21 +08:00 ERROR: Exception launching token request: Field currentActivity or type signature not found UnityEngine.Debug:LogWarning (object) GooglePlayGames.OurUtils.Logger/<>c__DisplayClass10_0:b__0 () (at Assets/GooglePlayGames/OurUtils/Logger.cs:65)
GooglePlayGames.OurUtils.PlayGamesHelperObject:Update () (at
*** [Play Games Plugin 0.10.12] 05.17.21 10:06:21 +08:00 ERROR: System.Exception: Field currentActivity or type signature not found at UnityEngine._AndroidJNIHelper.GetFieldID (System.IntPtr jclass, System.String fieldName, System.String signature, System.Boolean isStatic) [0x00082] in <73adbd79bdb94a0ba2fcbcb79f3a9be2>:0
Without not
How do I solve it?