我的游戏与facebook邀请使用unity3d集成。当切换到Android时,一切正常,但当我切换到WebGL时,我收到以下错误:
错误CS0103:名称`LoggedSuccefull'在当前上下文中不存在
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
using UnityEngine.SceneManagement;
#if FACEBOOK
using Facebook.Unity;
#endif
public class FacebookManager : MonoBehaviour {
private bool LoginEnable;
public GameObject facebookButton;
//1.3.3
private string lastResponse = string.Empty;
public static string userID;
public static List<FriendData> Friends = new List<FriendData> ();
public bool logged;
protected string LastResponse {
get {
return this.lastResponse;
}
set {
this.lastResponse = value;
}
}
private string status = "Ready";
protected string Status {
get {
return this.status;
}
set {
this.status = value;
}
}
bool loginForSharing;
public static FacebookManager THIS;
void Awake () {
if (THIS == null)
THIS = this;
else if (THIS != this)
Destroy (gameObject);
DontDestroyOnLoad (this);
}
void OnEnable () {
#if PLAYG
NetworkManager.OnLoginEvent += GetUserName;
#endif
}
void OnLevelWasLoaded () {
if (logged && SceneManager.GetActiveScene ().name == "game")
LoggedSuccefull ();
}
void OnDisable () {
#if PLAYG
NetworkManager.OnLoginEvent -= GetUserName;
#endif
}
#if PLAYG || GAMESPARKS
public FriendData GetCurrentUserAsFriend () {
//code
}
#endif
#region FaceBook_stuff
#if FACEBOOK
public void CallFBInit () {
Debug.Log ("init facebook");
FB.Init (OnInitComplete, OnHideUnity);
}
private void OnInitComplete () {
Debug.Log ("FB.Init completed: Is user logged in? " + FB.IsLoggedIn);
if (FB.IsLoggedIn) {//1.3
CallFBLogin ();
}
}
private void OnHideUnity (bool isGameShown) {
Debug.Log ("Is game showing? " + isGameShown);
}
void OnGUI () {
if (LoginEnable) {
CallFBLogin ();
LoginEnable = false;
}
}
public void CallFBLogin () {
Debug.Log ("login");
FB.LogInWithReadPermissions (new List<string> () { "public_profile", "email", "user_friends" }, this.HandleResult);
}
public void CallFBLoginForPublish () {
FB.LogInWithPublishPermissions (new List<string> () { "publish_actions" }, this.HandleResult);
}
public void CallInvite () {
this.Status = "Logged FB.AppEvent";
FB.Mobile.AppInvite (new Uri ("//URI Here"), callback: this.HandleResultInvite);
// NOTE !! create your app link here https://developers.facebook.com/quickstarts/?platform=app-links-host
}
protected void HandleResultInvite (IResult result) {
if (result == null) {
this.LastResponse = "Null Response\n";
Debug.Log (this.LastResponse);
return;
}
// Some platforms return the empty string instead of null.
if (!string.IsNullOrEmpty (result.Error)) {
this.Status = "Error - Check log for details";
this.LastResponse = "Error Response:\n" + result.Error;
Debug.Log (result.Error);
} else if (result.Cancelled) {
this.Status = "Cancelled - Check log for details";
this.LastResponse = "Cancelled Response:\n" + result.RawResult;
Debug.Log (result.RawResult);
} else if (!string.IsNullOrEmpty (result.RawResult)) {
this.Status = "Success - Check log for details";
this.LastResponse = "Success Response:\n" + result.RawResult;
} else {
this.LastResponse = "Empty Response\n";
Debug.Log (this.LastResponse);
}
}
public void CallFBLogout () {
FB.LogOut ();
//code
}
public void Share () {
if (!FB.IsLoggedIn) {
//code
}
protected void HandleResult (IResult result) {
if (result == null) {
this.LastResponse = "Null Response\n";
Debug.Log (this.LastResponse);
return;
}
// this.LastResponseTexture = null;
// Some platforms return the empty string instead of null.
if (!string.IsNullOrEmpty (result.Error)) {
this.Status = "Error - Check log for details";
this.LastResponse = "Error Response:\n" + result.Error;
Debug.Log (result.Error);
} else if (result.Cancelled) {
this.Status = "Cancelled - Check log for details";
this.LastResponse = "Cancelled Response:\n" + result.RawResult;
Debug.Log (result.RawResult);
} else if (!string.IsNullOrEmpty (result.RawResult)) {
this.Status = "Success - Check log for details";
this.LastResponse = "Success Response:\n" + result.RawResult;
LoggedSuccefull ();//1.3
} else {
this.LastResponse = "Empty Response\n";
Debug.Log (this.LastResponse);
}
}
void LoggedSuccefull () {//1.3
logged = true;
facebookButton.SetActive (false);//1.3.3
if (PlayerPrefs.GetInt ("Facebook_Logged") == 0) {
GameObject rewardPopup = Instantiate (Resources.Load ("Reward")) as GameObject;
rewardPopup.transform.GetChild (0).GetComponent<RewardIcon> ().SetIconSprite (0);
InitScript.Instance.AddGems (10);
}
PlayerPrefs.SetInt ("Facebook_Logged", 1);
PlayerPrefs.Save ();
if (SceneManager.GetActiveScene ().name != "game")
return;
//Debug.Log(result.RawResult);
userID = AccessToken.CurrentAccessToken.UserId;
GetPicture (AccessToken.CurrentAccessToken.UserId);
}
void GetUserName () {
FB.API ("/me?fields=first_name", HttpMethod.GET, GettingNameCallback);
}
private void GettingNameCallback (IGraphResult result) {
if (string.IsNullOrEmpty (result.Error)) {
IDictionary dict = result.ResultDictionary as IDictionary;
string fbname = dict ["first_name"].ToString ();
#endif
}
}
void GetPicture (string id) {
FB.API ("/" + id + "/picture", HttpMethod.GET, this.ProfilePhotoCallback);
}
private void ProfilePhotoCallback (IGraphResult result) {
if (string.IsNullOrEmpty (result.Error) && result.Texture != null) {
Sprite sprite = new Sprite ();
sprite = Sprite.Create (result.Texture, new Rect (0, 0, 50, 50), new Vector2 (0, 0), 1f);
InitScript.profilePic = sprite;
#endif
}
}
public void SaveScores () {
//code
}
public void ReadScores () {
FB.API ("/me/objects/object", HttpMethod.GET, APICallBack);
}
public void GetFriendsPicture () {
FB.API ("me/friends?fields=picture", HttpMethod.GET, RequestFriendsCallback);
}
private void RequestFriendsCallback (IGraphResult result) {
if (!string.IsNullOrEmpty (result.RawResult)) {
// Debug.Log (result.RawResult);
//code
}
//}
}
//print(firstGroup["id"] + " " + firstGroup["title"]);
}
//this.gamerGroupCurrentGroup = (string)firstGroup["id"];
}
}
if (!string.IsNullOrEmpty (result.Error)) {
Debug.Log (result.Error);
}
}
}
public void GetPictureByURL (string url, FriendData friend) {
StartCoroutine (GetPictureCor (url, friend));
}
IEnumerator GetPictureCor (string url, FriendData friend) {
Sprite sprite = new Sprite ();
WWW www = new WWW (url);
yield return www;
sprite = Sprite.Create (www.texture, new Rect (0, 0, 50, 50), new Vector2 (0, 0), 1f);
friend.picture = sprite;
// print ("get picture for " + url);
}
public void APICallBack (IGraphResult result) {
Debug.Log (result);
}
#endif
#endregion
}
public class FriendData {
public string userID;
public string FacebookID;
public Sprite picture;
public int level;
public GameObject avatar;
}
任何帮助都将受到高度赞赏