【问题标题】:trouble integrating facebook into a unity android project将 facebook 集成到统一的 android 项目中的麻烦
【发布时间】:2015-08-06 12:40:36
【问题描述】:

我一直在尝试将 facebook 集成到我的项目中,并且在一些在线教程的帮助下我成功地做到了这一点,但是我确实有一个持续存在的问题...

代码设置为暂停游戏使用

时间.timescale = 0;当 facebook 窗口启动并使用 Time.timescale = 1 恢复播放时;当它不是

但这并没有发生,暂停游戏的函数永远不会被调用......

代码如下:

using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 using System.Collections.Generic;
 
 public class FBHolder : MonoBehaviour {
 
     public GameObject UIFBIsLoggedIn;
     public GameObject UIFBNotLoggedIn;
     public GameObject UIFBAvatar;
     public GameObject UIFBUserName;
     
 
     public GameObject ScoreEntryPanel;
     public GameObject ScoreScrollList;
 
     private List<object> scoreslist = null;
 
     private Dictionary<string, string> profile = null;
 
     void Awake()
     {
         FB.Init (SetInit, onHideUnity);
     }
 
     private void SetInit()
     {
         Debug.Log ("FB Init Done");
 
         if(FB.IsLoggedIn)
             {
                 Debug.Log ("FB Logged In");
                 managefbmenus(true);
             }
         else
             {
                 managefbmenus(false);
             }
 
     }
 
     private void onHideUnity(bool isGameShown)
     {
         if(!isGameShown)
             {
                 Debug.Log ("Pause Game");
                 Time.timeScale = 0;
             }
         else
             {
                 Time.timeScale = 1;
             }
     }
 
     public void FBLogin()
     {
         FB.Login ("email,publish_actions", Authcallback);
     }
 
     void Authcallback(FBResult result)
     {
         if(FB.IsLoggedIn)
             {
                 Debug.Log ("FB Login Worked");
                 managefbmenus(true);
             }
         else
             {
                 Debug.Log ("FB Login Failed");
                 managefbmenus(false);
             }
     }
 
     void managefbmenus(bool isLoggedIn)
     {
         if(isLoggedIn)
             {
                 UIFBIsLoggedIn.SetActive(true);
                 UIFBNotLoggedIn.SetActive(false);
                 SetScore();
 
                 //Get profile picture
                 FB.API(Util.GetPictureURL("me", 128, 128), Facebook.HttpMethod.GET, DealWithProfilePicture);
                 FB.API("/me?fields=id,first_name", Facebook.HttpMethod.GET,DealwithUserName);
                 //Get username
             }
         if(!isLoggedIn)
             {
                 UIFBIsLoggedIn.SetActive(false);
                 UIFBNotLoggedIn.SetActive(true);
             }
     }
 
 
     void DealWithProfilePicture(FBResult result)
     {
         if(result.Error != null)
         {
             Debug.Log ("Problem getting profile picture");
             FB.API(Util.GetPictureURL("me", 128, 128), Facebook.HttpMethod.GET, DealWithProfilePicture);
             return;
         }
         Image UserAvatar = UIFBAvatar.GetComponent<Image> ();
         UserAvatar.sprite = Sprite.Create (result.Texture, new Rect(0, 0, 128, 128), new Vector2(0, 0));
     }
 
     void DealwithUserName(FBResult result)
     {
         if(result.Error != null)
         {
             Debug.Log ("Problem getting username");
             FB.API("/me?fields=id,first_name", Facebook.HttpMethod.GET,DealwithUserName);
             return;
         }
         profile = Util.DeserializeJSONProfile(result.Text);
 
         Text UserMsg = UIFBUserName.GetComponent<Text>();
 
         UserMsg.text = "Hello, " + profile ["first_name"];
     }

关于可能导致此问题的任何想法?

顺便说一句:我正在使用统一 5。

【问题讨论】:

    标签: android facebook unity3d integrate


    【解决方案1】:

    我猜你不需要在显示 Facebook UI 时暂停游戏。您可以将其称为:

     FB.Init(SetInit); 
    

    【讨论】:

    • 您可以使用单独的空 ui 面板来避免与您的底层 UI 交互。您可以查看FriendSmash Sample Code 找出您的错误所在。
    • 首先,我要感谢您的帮助,但我想指出,我是一名新手程序员,通常会从在线教程中获得帮助,这就是我获得这一切的方式facebook集成这首先工作,除了那一点点外,一切确实按预期工作。 '正在使用与我的大不相同,我所缺少的只是在显示 facebook 弹出对话框时调用 onHideUnity 函数......
    猜你喜欢
    • 1970-01-01
    • 2021-05-30
    • 2018-10-22
    • 2016-05-05
    • 2011-07-10
    • 1970-01-01
    • 2019-02-01
    • 1970-01-01
    相关资源
    最近更新 更多