After Device Authentication and initializing with Gamesparks through the Splash Screen, my next scene has Facebook Login and Custom Login. I managed to make login through Facebook work but I have no idea how to implement a scene change upon completion. I tried using SceneManager.LoadLevel ( ) but I don’t know how to tie it in to only activate after Facebook Login is successful. Just leaving it as is changes the scene even if I hit “Send Cancel” when asked for the Facebook Token.
So my question is, is it possible to trigger a scene change after the script successfully completes?
Here is the code for my Facebook Login:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using System;
using GameSparks.Core;
using GameSparks.Api;
using GameSparks.Api.Responses;
using GameSparks.Api.Requests;
using Facebook;
using Facebook.Unity;
public class FacebookScript : MonoBehaviour
{
void Awake()
{
FB.Init(SetInit, OnHideUnity);
}
void SetInit()
{
if (FB.IsLoggedIn)
{ GSFacebookLogin(AfterFBLogin);
Debug.Log("FB is logged in");
}
else
{
Debug.Log("FB is not logged in");
}
}
void OnHideUnity(bool isGameShown)
{
if (!isGameShown)
{
Time.timeScale = 0;
}
else
{
Time.timeScale = 1;
}
}
public void FBlogin()
{
List<string> permissions = new List<string>();
permissions.Add("public_profile");
permissions.Add("user_friends");
FB.LogInWithReadPermissions(permissions, AuthCallBack);
}
void AuthCallBack(IResult result)
{
if (result.Error != null)
{
Debug.Log(result.Error);
}
else
{
if (FB.IsLoggedIn)
{
Debug.Log("FB is logged in");
}
else
{
Debug.Log("FB is not logged in");
}
}
}
void GameSparksFBConnect(ILoginResult result)
{
if (FB.IsLoggedIn)
{
Debug.Log("Logging into gamesparks with facebook details");
GSFacebookLogin(AfterFBLogin);
}
else
{
Debug.Log("Something wrong with FB");
}
}
//this is the callback that happens when gamesparks has been connected with FB
private void AfterFBLogin(GameSparks.Api.Responses.AuthenticationResponse _resp)
{
Debug.Log(_resp.DisplayName);
}
//delegate for asynchronous callbacks
public delegate void FacebookLoginCallback(AuthenticationResponse _resp);
//This method will connect GS with FB
public void GSFacebookLogin(FacebookLoginCallback _fbLoginCallback)
{
Debug.Log("");
new GameSparks.Api.Requests.FacebookConnectRequest()
.SetAccessToken(AccessToken.CurrentAccessToken.TokenString)
.Send((response) =>
{
if (!response.HasErrors)
{
Debug.Log("Logged into gamesparks with facebook");
_fbLoginCallback(response);
}
else
{
Debug.Log("Error Logging into facebook");
}
});
}
}