【发布时间】:2022-12-31 02:50:06
【问题描述】:
使用 Facebook 的 Unity SDK 开发适用于 Android 的 Unity 游戏,但在将游戏发布到 google play 内部测试后,它抛出 NullReferenceException。当我在 Unity 上测试本地 apk 时,它工作得很好。
日志猫
2022-08-21 21:20:15.811 26811-28518/? E/Unity: NullReferenceException: Facebook object is not yet loaded. Did you call FB.Init()?
at Facebook.Unity.FB.get_FacebookImpl () [0x00000] in <00000000000000000000000000000000>:0
at Facebook.Unity.FB.LogInWithReadPermissions (System.Collections.Generic.IEnumerable`1[T] permissions, Facebook.Unity.FacebookDelegate`1[T] callback) [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.Events.UnityEvent.Invoke () [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.EventSystems.StandaloneInputModule.ProcessTouchPress (UnityEngine.EventSystems.PointerEventData pointerEvent, System.Boolean pressed, System.Boolean released) [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.EventSystems.StandaloneInputModule.ProcessTou\
FB初始化
void Awake()
{
Instance = this;
MoreGame.SetActive(false);
if (!FB.IsInitialized)
{
// Initialize the Facebook SDK
FB.Init(InitCallback, OnHideUnity);
}
else
{
// Already initialized, signal an app activation App Event
FB.ActivateApp();
}
initGameScene();
}
private void InitCallback()
{
if (FB.IsInitialized)
{
// Signal an app activation App Event
FB.ActivateApp();
FB.Android.RetrieveLoginStatus(LoginStatusCallback);
// 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;
}
}
【问题讨论】: