UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"implement fb login system"
// This Script is a community contribution and wasn't generated by ScripterAI using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using Facebook.Unity; public class FacebookManager : MonoBehaviour { public GameObject DialogLoggedIn; public GameObject DialogLoggedout; public GameObject DialogUserName; public GameObject DialogProfilePic,ProfilePic; void Awake(){ FB.Init(SetInit, OnHideUnity); } void SetInit(){ if(FB.IsLoggedIn){ Debug.Log("fb is loggin"); }else { Debug.Log("fb is not loggin"); } DealWithFBMenus (FB.IsLoggedIn); } void OnHideUnity(bool isGameShown){ if(!isGameShown){ Time.timeScale=0; }else { Time.timeScale=0; } } public void FBLogin(){ List<string> perms = new List<string>(); perms.Add("public_profile"); FB.LogInWithReadPermissions(perms, AuthCallback); } private void AuthCallback (IResult result) { if (result.Error != null) { Debug.Log(result.Error); } else { if(FB.IsLoggedIn){ Debug.Log("fb is loggin"); }else { Debug.Log("fb is not loggin"); } DealWithFBMenus (FB.IsLoggedIn); } } void DealWithFBMenus(bool IsLoggedIn) { if(IsLoggedIn){ DialogLoggedIn.SetActive(true); DialogLoggedout.SetActive(false); FB.API("/me?fields=first_name",HttpMethod.GET,DisplayUsername); FB.API("me/picture?type=square&height=600&width=600", HttpMethod.GET, GetPicture); }else { DialogLoggedIn.SetActive(false); DialogLoggedout.SetActive(true); } } void DisplayUsername(IResult result){ Text UserName = DialogUserName.GetComponent<Text>(); if(result.Error == null){ UserName.text = ""+result.ResultDictionary["first_name"]; }else { Debug.Log(result.Error); } } private void GetPicture(IGraphResult result) { if (result.Texture != null) { Image img = DialogProfilePic.GetComponent<Image>(); img.sprite = Sprite.Create(result.Texture, new Rect(0, 0, 600, 600), new Vector2()); Image img1 = ProfilePic.GetComponent<Image>(); img1.sprite = Sprite.Create(result.Texture, new Rect(0, 0, 600, 600), new Vector2()); } } }