Created
August 28, 2021 17:00
-
-
Save tedliou/05efb1c6fddb338f961b709e02c1cb64 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
// Include Facebook namespace | |
using Facebook.Unity; | |
public class FacebookController : MonoBehaviour | |
{ | |
// Awake function from Unity's MonoBehavior | |
void Awake() | |
{ | |
if (!FB.IsInitialized) | |
{ | |
// Initialize the Facebook SDK | |
FB.Init(InitCallback, OnHideUnity); | |
} | |
else | |
{ | |
// Already initialized, signal an app activation App Event | |
FB.ActivateApp(); | |
} | |
} | |
private void InitCallback() | |
{ | |
if (FB.IsInitialized) | |
{ | |
// Signal an app activation App Event | |
FB.ActivateApp(); | |
// Continue with Facebook SDK | |
// ... | |
} | |
else | |
{ | |
Debug.Log("Failed to Initialize the Facebook SDK"); | |
} | |
} | |
private void OnHideUnity(bool isGameShown) | |
{ | |
if (!isGameShown) | |
{ | |
// Pause the game - we will need to hide | |
Time.timeScale = 0; | |
} | |
else | |
{ | |
// Resume the game - we're getting focus again | |
Time.timeScale = 1; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment