How To: Scene Change After Facebook Login?
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");
}
});
}
}
Found the solution; added the Scene$$anonymous$$anager.LoadScene(2) in the "if/else" statement on line 75. If anyone has a better way, let me know!
Answer by appvillas · Aug 29, 2018 at 06:18 AM
Just Add This to your Script.
private void OnPlayfabFacebookAuthComplete(LoginResult result)
{
// SetMessage("PlayFab Facebook Auth Complete. Session ticket: " + result.SessionTicket);
SceneManager.LoadScene("Main Menu");
}
Your answer
Follow this Question
Related Questions
how can i use facebook authentication for pc games? 0 Answers
If you install the Google Play Game Plugin, you will not be able to sign in to Facebook. (iOS) 1 Answer
MarshalDirectiveException: Cannot marshal type 'System.Collections.Generic.IEnumerable`1' 4 Answers
Unity + Django + Facebook 0 Answers
Using Facebook Login unity Pc Build 0 Answers