public void OnBtnRankingClicked() { FacebookHandle.TO_DO = FacebookHandle.WhatToDo.Invite; if (FB.IsLoggedIn) { friendListUI.SetActive(true); FBGraph.GetFriends(); if (FBGraph.HavePublishActions) { Debug.Log("Success - Check log for details"); FBGraph.PostScore(MapGenerator.CurrentLevel); } else { FacebookHandle.Instance.CallFBLoginForLeaderboard(result => { if (!string.IsNullOrEmpty(result.RawResult)) { Debug.Log("Success - Check log for details"); FBGraph.PostScore(MapGenerator.CurrentLevel); } }); } } else { FacebookHandle.Instance.FBLogin(); } }
private void AuthCallback(ILoginResult result) { if (FB.IsLoggedIn) { // AccessToken class will have session details var aToken = Facebook.Unity.AccessToken.CurrentAccessToken; // Print current access token's User ID Debug.Log(aToken.UserId); // Print current access token's granted permissions foreach (string perm in aToken.Permissions) { Debug.Log(perm); } if (SceneManager.GetActiveScene().name == "start") { FBGraph.GetPlayerInfo(); } else if (TO_DO == WhatToDo.Invite) { FBGraph.GetFriends(); } else if (TO_DO == WhatToDo.Share) { FacebookHandle.ShareLink(); } } else { Debug.Log("User cancelled login"); } }
private void OnLoginComplete() { Debug.Log("OnLoginComplete"); if (!FB.IsLoggedIn) { Facebook.interactable = true; return; } // Begin querying the Graph API for Facebook data FBGraph.GetPlayerInfo(); //FBGraph.GetInvitableFriends(); }
public static void PostScore(int score, Action callback = null) { var query = new Dictionary <string, string>(); query["score"] = score.ToString(); FB.API( "/me/scores", HttpMethod.POST, delegate(IGraphResult result) { Debug.Log("PostScore Result: " + result.RawResult); // Fetch fresh scores to update UI FBGraph.GetScores(); }, query ); }
// ---------------- Challange Friends Panel Functions ----------------- public void FriendsBtn() { FBGraph.GetFriends(); foreach (GameObject panel in FriendsPanels) { if (panel.name == "FriendsPanel") { panel.SetActive(true); } else { panel.SetActive(false); } } BackEnd.instance.GetFBUserData(FBGraph.userFriendsIds); SoundManager._instance.PlaySound(SoundManager._instance.btn); }
private void OnLoginComplete() { Debug.Log("OnLoginComplete"); if (!FB.IsLoggedIn) { // Reenable the Login Button LoginButton.interactable = true; return; } // Show loading animations LoadingText.SetActive(true); // Begin querying the Graph API for Facebook data FBGraph.GetPlayerInfo(); FBGraph.GetFriends(); FBGraph.GetInvitableFriends(); FBGraph.GetScores(); }
// Use this for initialization void Load() { print("Friends :" + FacebookHandler.Instance.Friends.Count); if (FBGraph.IsFriendListAvailable()) { Destroy(defaultText_FriendList.gameObject); foreach (object friend in FacebookHandler.Instance.Friends) { string name = (friend as Dictionary <string, object>)["name"] as string; GameObject textObj = new GameObject(name); Text t = textObj.AddComponent <Text>(); t.text = name; textObj.transform.parent = contentT; } } else { defaultText_FriendList.text = "Invite your friends!"; FBGraph.Invite(); } }
// The Graph API for Scores allows you to publish scores from your game to Facebook // This allows Friend Smash! to create a friends leaderboard keeping track of the top scores achieved by the player and their friends. // For more information on the Scores API see: https://developers.facebook.com/docs/games/scores // // When publishing a player's scores, these scores will be visible to their friends who also play your game. // As a result, the player needs to grant the app an extra permission, publish_actions, in order to publish scores. // This means we need to ask for the extra permission, as well as handling the // scenario where that permission wasn't previously granted. // public static void PostScore(int score, Action callback = null) { // Check for 'publish_actions' as the Scores API requires it for submitting scores if (FBLogin.HavePublishActions) { var query = new Dictionary <string, string>(); query["score"] = score.ToString(); FB.API( "/me/scores", HttpMethod.POST, delegate(IGraphResult result) { Debug.Log("PostScore Result: " + result.RawResult); // Fetch fresh scores to update UI FBGraph.GetScores(); }, query ); } else { // Showing context before prompting for publish actions // See Facebook Login Best Practices: https://developers.facebook.com/docs/facebook-login/best-practices PopupScript.SetPopup("Prompting for Publish Permissions for Scores API", 4f, delegate { // Prompt for `publish actions` and if granted, post score FBLogin.PromptForPublish(delegate { if (FBLogin.HavePublishActions) { PostScore(score); } }); }); } }
void LoadScore() { List <object> friends = FacebookHandler.Instance.Friends; print("Friends :" + friends.Count); if (FBGraph.IsFriendListAvailable()) { Destroy(defaultText_FriendList.gameObject); for (int i = 0; i < players.Length; i++) { players[i].gameObject.SetActive(false); } for (int i = 0; i < friends.Count; i++) { var score = ((friends[i] as Dictionary <string, object>)["score"]) as string; var user = ((Dictionary <string, object>)friends[i])["user"] as Dictionary <string, object>; string name = ((user as Dictionary <string, object>)["name"]) as string; score = "Stage " + score + " " + name; Debug.Log(score); players[i].gameObject.SetActive(true); players[i].text = score.ToString(); } } }
public void LoadLeaderboard() { //Results = new List<FBresult>() { FAKE RESULTS // new FBresult(Resources.Load<Texture>("Profile1"), 1), // new FBresult(Resources.Load<Texture>("Profile2"), 2), // new FBresult(Resources.Load<Texture>("Profile3"), 3), // new FBresult(Resources.Load<Texture>("Profile4"), 4), // new FBresult(Resources.Load<Texture>("Profile5"), 5), // new FBresult(Resources.Load<Texture>("Profile6"), 6), // new FBresult(Resources.Load<Texture>("Profile7"), 7), // new FBresult(Resources.Load<Texture>("Profile8"), 8) //}; List <FBresult> Results = null; if (FB.IsLoggedIn) { FBGraph.GetFriends(); FBGraph.GetScores(() => { Results = new List <FBresult>(); for (int i = 0; i < Game.Scores.Count; i++) { var entry = (Dictionary <string, object>)Game.Scores[i]; var user = (Dictionary <string, object>)entry["user"]; //((string) user["name"]).Split(new char[]{' '})[0] Texture picture; if (Game.FriendImages.TryGetValue((string)user["id"], out picture)) { Results.Add(new FBresult(GraphUtil.GetScoreFromEntry(entry), picture)); } else { Results.Add(new FBresult(GraphUtil.GetScoreFromEntry(entry), (string)user["id"])); } } Results = Results.OrderByDescending(c => c.score).ToList(); for (int i = 0; i < Results.Count; i++) { var e = Instantiate(LeaderboardElement); e.transform.SetParent(LeaderboardElementGroup.transform, false); LeaderboardElement refer = e.GetComponent <LeaderboardElement>(); LeaderboardElementGroup.SetActive(true); if (Results[i].image == null) { refer.initalise(Results[i].score, Results[i].id); } else { refer.initalise(Results[i].score, Results[i].image); } refer.Displacer.position = new Vector3(-1000, 0, 0); LeanTween.value(refer.Displacer.gameObject, refer.Displacer.localPosition.x, 0f, 1f).setEaseInOutCubic().setDelay(0.1f * (Results.Count - i)).setOnUpdate((f) => { refer.Displacer.localPosition = new Vector3(f, 0, 0); }); } LeaderboardStopLoading(); }); } else { LeaderboardStopLoading(); LeaderboardElementGroup.SetActive(true); var e = Instantiate(Resources.Load <GameObject>("LoginPleaseFacebook")); e.transform.SetParent(LeaderboardElementGroup.transform, false); var dif = e.transform.GetChild(0); AnimatableLeader.Add(dif.GetComponent <Text>()); dif.transform.position = new Vector3(-1100, 0, 0); LeanTween.value(dif.gameObject, dif.localPosition.x, 0f, 1f).setEaseInOutCubic().setOnUpdate((f) => { dif.localPosition = new Vector3(f, 0, 0); }); } }
public IEnumerator CoGetMatchesHistory() { ManuManager._instance.LoadingPupUp.SetActive(true); Debug.Log("CoGetMatchesHistory" + "|||||||||||||||||||||||"); WWWForm wwwform = new WWWForm(); wwwform.AddField("p", currentPlayer.PlayerID + "||." + 5); WWW www = new WWW(webServiceLink + "/fbresulthistory.php", wwwform); for (int i = 0; i < ManuManager._instance.ResultsContentHolder.transform.childCount; i++) { Destroy(ManuManager._instance.ResultsContentHolder.transform.GetChild(i).gameObject); } ManuManager._instance.ResultsContentHolder.GetComponent <RectTransform> ().localPosition = Vector3.zero; yield return(www); if (www.error == null) { Debug.Log(www.text); var serializer = new XmlSerializer(typeof(PlayerMatchesResult), new XmlRootAttribute("PlayerMatches")); using (TextReader reader = new StringReader(www.text)) { var playerMatchesResult = (PlayerMatchesResult)serializer.Deserialize(reader); for (int i = 0; i < playerMatchesResult.Play.Count; i++) { ResultFeild resultFeild = Instantiate(ResultFeild).GetComponent <ResultFeild> (); resultFeild.transform.SetParent(ManuManager._instance.ResultsContentHolder.transform); ManuManager._instance.ResultsContentHolder.GetComponent <RectTransform> ().localPosition = new Vector3(ManuManager._instance.ResultsContentHolder.GetComponent <RectTransform> ().localPosition.x, ManuManager._instance.ResultsContentHolder.GetComponent <RectTransform> ().localPosition.y - 365, 0); if (playerMatchesResult.Play [i].HostFacebookId == currentPlayer.FbId) { resultFeild.PSetName(playerMatchesResult.Play [i].HostUsername); resultFeild.PSetRank(playerMatchesResult.Play [i].HostUserRank); resultFeild.PSetScore(playerMatchesResult.Play [i].HostUserScoreMulti); resultFeild.PSetFBID(playerMatchesResult.Play [i].HostFacebookId); FBGraph.GetFBImage(playerMatchesResult.Play [i].HostFacebookId, resultFeild.PPic); resultFeild.FSetName(playerMatchesResult.Play [i].GuestUsername); resultFeild.FSetRank(playerMatchesResult.Play [i].GuestUserRank); resultFeild.FSetScore(playerMatchesResult.Play [i].GuestUserScoreMulti); resultFeild.FSetFBID(playerMatchesResult.Play [i].GuestFacebookId); FBGraph.GetFBImage(playerMatchesResult.Play [i].GuestFacebookId, resultFeild.FPic); resultFeild.SetResult(int.Parse(playerMatchesResult.Play [i].HostUserScore), int.Parse(playerMatchesResult.Play [i].GuestUserScore)); } else { resultFeild.FSetName(playerMatchesResult.Play [i].HostUsername); resultFeild.FSetRank(playerMatchesResult.Play [i].HostUserRank); resultFeild.FSetScore(playerMatchesResult.Play [i].HostUserScoreMulti); resultFeild.FSetFBID(playerMatchesResult.Play [i].HostFacebookId); FBGraph.GetFBImage(playerMatchesResult.Play [i].HostFacebookId, resultFeild.FPic); resultFeild.PSetName(playerMatchesResult.Play [i].GuestUsername); resultFeild.PSetRank(playerMatchesResult.Play [i].GuestUserRank); resultFeild.PSetScore(playerMatchesResult.Play [i].GuestUserScoreMulti); resultFeild.PSetFBID(playerMatchesResult.Play [i].GuestFacebookId); FBGraph.GetFBImage(playerMatchesResult.Play [i].GuestFacebookId, resultFeild.PPic); resultFeild.SetResult(int.Parse(playerMatchesResult.Play [i].GuestUserScore), int.Parse(playerMatchesResult.Play [i].HostUserScore)); } } //add The List is empty statment. if (ManuManager._instance.ResultsContentHolder.transform.childCount == 0) { GameObject EmptyListFeild = Instantiate(EmptyListField3); EmptyListFeild.transform.SetParent(ManuManager._instance.ResultsContentHolder.transform); } reader.Close(); } //yield return new WaitForSeconds (0.5f); ManuManager._instance.LoadingPupUp.SetActive(false); } else { Debug.Log(www.error + " error"); ManuManager._instance.ConnictionErrorPanel.SetActive(true); } }
public IEnumerator CoGetGuestPendingMatches(bool ShowPobUp) { Debug.Log("CoGetGuestPendingMatches" + "|||||||||||||||||||||||"); WWWForm wwwform = new WWWForm(); wwwform.AddField("p", currentPlayer.PlayerID + "||." + 2); WWW www = new WWW(webServiceLink + "/fbpendsessions.php", wwwform); for (int i = 0; i < ManuManager._instance.FriendsRequestsHolder.transform.childCount; i++) { Destroy(ManuManager._instance.FriendsRequestsHolder.transform.GetChild(i).gameObject); } ManuManager._instance.FriendsRequestsHolder.GetComponent <RectTransform> ().localPosition = Vector3.zero; yield return(www); if (www.error == null) { Debug.Log(www.text); var serializer = new XmlSerializer(typeof(PlayerMatches), new XmlRootAttribute("PlayerMatches")); using (TextReader reader = new StringReader(www.text)) { var playerMatches = (PlayerMatches)serializer.Deserialize(reader); for (int i = 0; i < playerMatches.Match.Count; i++) { FriendsRequestsFeild friendsRequestsFeild = Instantiate(FriendsRequestsFeild).GetComponent <FriendsRequestsFeild> (); friendsRequestsFeild.transform.SetParent(ManuManager._instance.FriendsRequestsHolder.transform); ManuManager._instance.FriendsRequestsHolder.GetComponent <RectTransform> ().localPosition = new Vector3(ManuManager._instance.FriendsRequestsHolder.GetComponent <RectTransform> ().localPosition.x, ManuManager._instance.FriendsRequestsHolder.GetComponent <RectTransform> ().localPosition.y - 150, 0); friendsRequestsFeild.SetName(playerMatches.Match [i].OpUserName); friendsRequestsFeild.SetRank(playerMatches.Match [i].OpUserRank); friendsRequestsFeild.SetScore(playerMatches.Match [i].OpUserScore); friendsRequestsFeild.SetFBID(playerMatches.Match [i].OpUserFacebookId); // friendsRequestsFeild.SetTime (Convert.ToDateTime (playerMatches.Match [i].Expiry)); friendsRequestsFeild.SetFBSessionID((playerMatches.Match [i].FacebookSession)); friendsRequestsFeild.SetTime(Convert.ToDateTime(playerMatches.Match [i].Remainingtime)); LastFBSessionID = playerMatches.Match [i].FacebookSession; foreach (Text text in ManuManager._instance.notificationsNum) { if (playerMatches.Match.Count > 0) { text.transform.parent.gameObject.SetActive(true); text.text = playerMatches.Match.Count.ToString(); if (ShowPobUp) { ManuManager._instance.NotificationsPupUp.SetActive(true); } //TODO PupUP for Notification } else { text.transform.parent.gameObject.SetActive(false); } } FBGraph.GetFBImage(playerMatches.Match [i].UserFacebookId, friendsRequestsFeild.Pic); } //add The List is empty statment. if (playerMatches.Match.Count == 0) { GameObject EmptyListFeild = Instantiate(EmptyListField2); EmptyListFeild.transform.SetParent(ManuManager._instance.FriendsRequestsHolder.transform); } reader.Close(); } ManuManager._instance.LoadingPupUp.SetActive(false); } else { Debug.Log(www.error + " error"); ManuManager._instance.ConnictionErrorPanel.SetActive(true); } }
public IEnumerator CoGetHostPendingMatches() { Debug.Log("CoGetHostPendingMatches" + "|||||||||||||||||||||||"); WWWForm wwwform = new WWWForm(); wwwform.AddField("p", currentPlayer.PlayerID + "||." + 1); WWW www = new WWW(webServiceLink + "/fbpendsessions.php", wwwform); for (int i = 0; i < ManuManager._instance.MyFriendsRuquestsHolder.transform.childCount; i++) { Destroy(ManuManager._instance.MyFriendsRuquestsHolder.transform.GetChild(i).gameObject); } ManuManager._instance.MyFriendsRuquestsHolder.GetComponent <RectTransform> ().localPosition = Vector3.zero; yield return(www); if (www.error == null) { Debug.Log(www.text); var serializer = new XmlSerializer(typeof(PlayerMatches), new XmlRootAttribute("PlayerMatches")); using (TextReader reader = new StringReader(www.text)) { var playerMatches = (PlayerMatches)serializer.Deserialize(reader); for (int i = 0; i < playerMatches.Match.Count; i++) { MyRequestsFeild myFriendsField = Instantiate(MyRequestsFeild).GetComponent <MyRequestsFeild> (); myFriendsField.transform.SetParent(ManuManager._instance.MyFriendsRuquestsHolder.transform); ManuManager._instance.MyFriendsRuquestsHolder.GetComponent <RectTransform> ().localPosition = new Vector3(ManuManager._instance.MyFriendsRuquestsHolder.GetComponent <RectTransform> ().localPosition.x, ManuManager._instance.MyFriendsRuquestsHolder.GetComponent <RectTransform> ().localPosition.y - 150, 0); myFriendsField.SetName(playerMatches.Match [i].OpUserName); myFriendsField.SetRank(playerMatches.Match [i].OpUserRank); myFriendsField.SetScore(playerMatches.Match [i].OpUserScore); myFriendsField.SetFBID(playerMatches.Match [i].OpUserFacebookId); myFriendsField.SetTime(Convert.ToDateTime(playerMatches.Match [i].Remainingtime)); LastFBSessionID = playerMatches.Match [i].FacebookSession; FBGraph.GetFBImage(playerMatches.Match [i].OpUserFacebookId, myFriendsField.Pic); } //add The List is empty statment. if (playerMatches.Match.Count == 0) { GameObject myFriendsField = Instantiate(EmptyListField1); myFriendsField.transform.SetParent(ManuManager._instance.MyFriendsRuquestsHolder.transform); } reader.Close(); } //ManuManager._instance.OpenLayout (LayoutStates._FriendsListPanel.ToString ()); } else { Debug.Log(www.error + " error"); ManuManager._instance.ConnictionErrorPanel.SetActive(true); } }
//----------------------------------- Facebook Services ---------------------------------- public IEnumerator CoGetFBUserData(List <string> _FBID) { WWWForm wwwform1 = new WWWForm(); wwwform1.AddField("p", currentPlayer.PlayerID); WWW www1 = new WWW(webServiceLink + "/pendfbusers.php", wwwform1); yield return(www1); if (www1.error == null) { Debug.Log(www1.text); var serializer = new XmlSerializer(typeof(PendingGuests), new XmlRootAttribute("PendingGuests")); using (TextReader reader = new StringReader(www1.text)) { var pendingList = (PendingGuests)serializer.Deserialize(reader); pendingUsers = pendingList.FacebookId; } } else { Debug.Log(www1.error + " error"); ManuManager._instance.ConnictionErrorPanel.SetActive(true); } for (int i = 0; i < ManuManager._instance.FriendsContentHolder.transform.childCount; i++) { Destroy(ManuManager._instance.FriendsContentHolder.transform.GetChild(i).gameObject); } ManuManager._instance.FriendsContentHolder.GetComponent <RectTransform> ().localPosition = Vector3.zero; foreach (string fbid in _FBID) { WWWForm wwwform = new WWWForm(); wwwform.AddField("p", fbid); WWW www = new WWW(webServiceLink + "/fbuserdata.php", wwwform); yield return(www); if (www.error == null) { Debug.Log(www.text); var serializer = new XmlSerializer(typeof(Player), new XmlRootAttribute("Player")); using (TextReader reader = new StringReader(www.text)) { var player = (Player)serializer.Deserialize(reader); if (player.PlayerID != "-1") { FriendFeild friendsField = Instantiate(FriendsFeild).GetComponent <FriendFeild> (); friendsField.transform.SetParent(ManuManager._instance.FriendsContentHolder.transform); ManuManager._instance.FriendsContentHolder.GetComponent <RectTransform> ().localPosition = new Vector3(ManuManager._instance.FriendsContentHolder.GetComponent <RectTransform> ().localPosition.x, ManuManager._instance.FriendsContentHolder.GetComponent <RectTransform> ().localPosition.y - 150, 0); friendsField.SetName(player.PlayerName); friendsField.SetRank(player.UserRank); friendsField.SetScore(player.TotalScore); friendsField.SetFBID(fbid); if (pendingUsers.Contains(fbid)) { friendsField.SetBtn(false); } else { friendsField.SetBtn(true); } FBGraph.GetFBImage(fbid, friendsField.Pic); } } } else { //TODO close the Loading screen & Player logined Debug.Log(www.error + " error"); ManuManager._instance.ConnictionErrorPanel.SetActive(true); } } FBGraph.GetInvitableFriends(); }
public void OnBtnInviteClicked() { FBGraph.Invite(); }