我一直在努力将facebook整合到我的项目中,并且我已经成功地在一些在线教程的帮助下成功完成了这项工作但是我确实有一个持续存在的问题...
代码设置为使用
暂停游戏Time.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"];
}
&#13;
关于可能导致此问题的任何想法?
BTW:我使用的是团结5。
答案 0 :(得分:0)
我猜您在显示Facebook UI时不需要暂停游戏。你可以称之为:
FB.Init(SetInit);