using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class UIPopupTutorial : MonoBehaviour
{
public Button btnClose;
public Button btnNext;
public Text txtPageNum;
private int currentPage = 1;
private int totalPage = 5;
public void Init()
{
this.btnNext.onClick.AddListener(() => {
if (this.currentPage < this.totalPage)
{
this.currentPage++;
var str = string.Format("{0}/{1}", this.currentPage, this.totalPage);
Debug.Log(str);
this.txtPageNum.text = str;
}
});
this.btnClose.onClick.AddListener(() => {
this.Close();
});
}
public void Open()
{
this.gameObject.SetActive(true);
}
public void Close()
{
this.gameObject.SetActive(false);
Firebase.Analytics.FirebaseAnalytics.LogEvent("end_tutorial", "page", this.currentPage);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using GooglePlayGames;
using GooglePlayGames.BasicApi;
using UnityEngine.SocialPlatforms;
using UnityEngine.SceneManagement;
public class App : MonoBehaviour
{
public enum ePlayMode
{
TEST, BUILD
}
public Text versionText;
public Text txtid;
public Text txtUserName;
public Text txtState;
public Text txtAuthenicate;
public Image thumb;
public Button btnStart;
public ePlayMode playMode;
public UIPopupTutorial popupTutorial;
void Start()
{
versionText.text = Application.version;
if (this.playMode == ePlayMode.TEST)
this.btnStart.gameObject.SetActive(true);
else
this.btnStart.gameObject.SetActive(false);
//this.btnStart.gameObject.SetActive(false);
this.btnStart.onClick.AddListener(() =>
{
SceneManager.LoadScene("GameScene");
SceneManager.LoadSceneAsync("GameScene").completed += (oper) =>
{
var gameMain = GameObject.FindObjectOfType<GameMain>();
gameMain.Init(Social.localUser.id);
};
});
Debug.Log("================================> Init GPGS");
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
.EnableSavedGames()
.RequestIdToken()
.Build();
PlayGamesPlatform.InitializeInstance(config);
// recommended for debugging:
PlayGamesPlatform.DebugLogEnabled = true;
// Activate the Google Play Games platform
PlayGamesPlatform.Activate();
Debug.Log("================================> Authenticate");
// authenticate user:
PlayGamesPlatform.Instance.Authenticate(SignInInteractivity.CanPromptAlways, (result) =>
{
this.txtAuthenicate.text = result.ToString();
if (result == SignInStatus.Success)
{
var localUer = (PlayGamesLocalUser)Social.localUser;
var googleIdToken = localUer.GetIdToken();
Debug.LogFormat("googleIdToken : {0}", googleIdToken);
Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
Firebase.Auth.Credential credential =
Firebase.Auth.GoogleAuthProvider.GetCredential(googleIdToken, null);
auth.SignInWithCredentialAsync(credential).ContinueWith(task => {
if (task.IsCanceled)
{
Debug.LogError("SignInWithCredentialAsync was canceled.");
return;
}
if (task.IsFaulted)
{
Debug.LogError("SignInWithCredentialAsync encountered an error: " + task.Exception);
return;
}
Firebase.Auth.FirebaseUser newUser = task.Result;
Debug.LogFormat("User signed in successfully: {0} ({1})",
newUser.DisplayName, newUser.UserId);
this.popupTutorial.Init();
this.popupTutorial.Open();
});
}
// handle results
Debug.Log("================================>" + result);
Debug.Log("================================>" + Social.localUser);
Debug.Log("================================>" + Social.localUser.authenticated);
this.txtid.text = Social.localUser.id;
this.txtUserName.text = Social.localUser.userName;
this.txtState.text = Social.localUser.state.ToString();
StartCoroutine(this.WaitForLoadThumb(() =>
{
Debug.Log(Social.localUser.image);
this.thumb.sprite = Sprite.Create(Social.localUser.image, new Rect(0, 0, Social.localUser.image.width, Social.localUser.image.height), Vector2.zero);
this.thumb.SetNativeSize();
}));
});
}
private IEnumerator WaitForLoadThumb(System.Action callback)
{
while(true)
{
if(Social.localUser.image != null)
{
break;
}
yield return null;
}
callback();
}
}