Beispiel #1
0
        public static void OnFBShare()
        {
            OverlayDialog OD = new OverlayDialog();

            OD.PreOKCallBack = delegate()
            {
                string content = "d=" + Util.GetValue("txt");

                Ajax.MakeCall("/Link.ashx?r=" + new Date().ToUTCString(), new AjaxCallback(delegate(string err, string data, XHR xhr)
                {
                    FeedParams FP  = new FeedParams();
                    FP.Name        = Strings.Title;
                    FP.Caption     = Strings.TagLine;
                    FP.Description = Strings.StandardDesc;
                    FP.Picture     = "http://chandam.apphb.com/img/fbPreView.png?r" + new Date().ToUTCString();
                    FP.Link        = "http://chandam.apphb.com/?p=" + data;
                    FP.Message     = Util.GetValue("txt");
                    FBUtil.Post(FP);
                }), HTTPMethod.POST, content, false);


                return(true);
            };

            OD.Title   = Strings.FBTitle;
            OD.Content = Util.GetValue("txt").Replace("\n", "<br/>");
            OD.Show();
        }
 void APICallback(string response)
 {
     profile = FBUtil.DeserializeJSONProfile(response);
     GameStateManager.Username = profile["first_name"];
     StartCoroutine(
         FBUtil.GetPictureTexture(facebookID : FB.UserId, callback : delegate(Texture t) { GameStateManager.UserTexture = t; })
         );
     friends = FBUtil.DeserializeJSONFriends(response);
 }
    IEnumerator GetFriendTexture(string uid)
    {
        string url = FBUtil.GetPictureURL(uid, 128, 128);
        WWW    www = new WWW(url);

        yield return(www);

        friendImages.Add(uid, (Texture)www.texture);
    }
Beispiel #4
0
    void HandleUserName(FBResult result)
    {
        if (result.Error != null)
        {
            FB.API(FBUtil.GetPictureURL("me", 128, 128), Facebook.HttpMethod.GET, HandleAvatar);
            return;
        }

        profile = FBUtil.DeserializeJSONProfile(result.Text);
        Text UserMsg = UIFB_UserName.GetComponent <Text>();

        UserMsg.text = "Hallo, " + profile["first_name"];
    }
Beispiel #5
0
    void HandleAvatar(FBResult result)
    {
        //If avatar GET call results in an error, retry calling it
        if (result.Error != null)
        {
            FB.API(FBUtil.GetPictureURL("me", 128, 128), Facebook.HttpMethod.GET, HandleAvatar);
            return;
        }
        //Get empty img of UI
        Image UserAvatar = UIFB_Avatar.GetComponent <Image>();

        //Fill this img with the correct FB profile picture
        UserAvatar.sprite = Sprite.Create(result.Texture, new Rect(0, 0, 128, 128), new Vector2(0, 0));
    }
Beispiel #6
0
        private static void SetupChandam()
        {
            FBUtil.Init();            //External First

            LoadRules();
            LoadSamples();
            LoadRandom();

            InitDesigner();
            InitList();
            ShowToolBar();
            InitNotification();
            InitRandom();

            RestoreOptions();
            ManageNotification();
        }
Beispiel #7
0
    private void ScoresCallback(FBResult result)
    {
        //Deserialize JSON result friends scores
        scoresList = FBUtil.DeserializeScores(result.Text);

        //Empty scorelist UI
        foreach (Transform item in ScoreScrollList.transform)
        {
            GameObject.Destroy(item.gameObject);
        }

        foreach (object score in scoresList)
        {
            var entry = (Dictionary <string, object>)score;
            var user  = (Dictionary <string, object>)entry["user"];

            GameObject ScorePanel;
            ScorePanel = Instantiate(ScoreEntryPanel) as GameObject;
            ScorePanel.transform.parent = ScoreScrollList.transform;

            //get name of friend + score
            Transform ScoreName  = ScorePanel.transform.Find("FriendName");
            Transform ScoreScore = ScorePanel.transform.Find("FriendScore");
            Text      scoreName  = ScoreName.GetComponent <Text>();
            Text      scoreScore = ScoreScore.GetComponent <Text>();

            scoreName.text  = user["name"].ToString();
            scoreScore.text = entry["score"].ToString();

            //get friend avatar
            Transform UserAvatar = ScorePanel.transform.Find("FriendAvatar");
            Image     userAvatar = UserAvatar.GetComponent <Image>();;

            FB.API(FBUtil.GetPictureURL(user["id"].ToString(), 128, 128), Facebook.HttpMethod.GET, delegate(FBResult pictureResult)
            {
                if (pictureResult.Error != null)
                {
                    Debug.Log(pictureResult.Error);
                }
                else
                {
                    userAvatar.sprite = Sprite.Create(pictureResult.Texture, new Rect(0, 0, 128, 128), new Vector2(0, 0));
                }
            });
        }
    }
    void ScoresCallback(string response)
    {
        scores = new Dictionary <string, object>();
        List <object> scoresList = FBUtil.DeserializeScores(response);

        foreach (object score in scoresList)
        {
            Dictionary <string, object> entry = (Dictionary <string, object>)score;
            Dictionary <string, object> user  = (Dictionary <string, object>)entry["user"];

            scores.Add((string)user["id"], entry);

            StartCoroutine(
                GetFriendTexture((string)user["id"])
                );
        }
    }
Beispiel #9
0
    //HANDLE METHOD: GET ONE achievement, GET ALL achievements - PLAYER
    void HandleGetAchievement(FBResult result)
    {
        if (result != null)
        {
            //Deserialize JSON result into usable data
            dataList = FBUtil.DeserializeScores(result.Text);
            foreach (object dataInstance in dataList)
            {
                var entry = (Dictionary <string, object>)dataInstance;
                var data  = (Dictionary <string, object>)entry["data"];

                var achievements = (Dictionary <string, object>)data["achievement"];

                namen.Add(achievements["title"].ToString());
                Debug.Log(achievements["title"].ToString());
            }
        }
    }
Beispiel #10
0
    //HANDLE METHOD: GET ALL achievements - APP
    void HandleGetAllAppAchievements(FBResult result)
    {
        //Deserialize JSON result into usable data
        if (result != null)
        {
            dataList = FBUtil.DeserializeScores(result.Text);
            foreach (object dataInstance in dataList)
            {
                var entry = (Dictionary <string, object>)dataInstance;

                List <object> images = entry["image"] as List <object>;
                foreach (object image in images)
                {
                    var imageEntry = (Dictionary <string, object>)image;
                }
            }
        }
    }
Beispiel #11
0
    void HandleFBMenus(bool isLoggedIn)
    {
        //If user is logged in menu is shown and filled with data
        if (isLoggedIn)
        {
            UIFB_IsLoggedIn.SetActive(true);
            UIFB_IsNotLoggedIn.SetActive(false);

            //get avatar
            FB.API(FBUtil.GetPictureURL("me", 128, 128), Facebook.HttpMethod.GET, HandleAvatar);

            //get username
            FB.API("/me?fields=id,first_name", Facebook.HttpMethod.GET, HandleUserName);

            // Check for Achievements
            GameControl.control.AchievementCheck();
            GameControl.control.FBlogin = true;
        }
        else
        {
            UIFB_IsLoggedIn.SetActive(false);
            UIFB_IsNotLoggedIn.SetActive(true);
        }
    }
Beispiel #12
0
    void OnGUI()
    {
        GUI.skin = MenuSkin;
        if (Application.loadedLevel != 0)
        {
            return;
        }

        MenuSkin.GetStyle("topbar").fixedWidth = Screen.width;
        GUILayout.Box("", MenuSkin.GetStyle("topbar"));
        GUI.DrawTexture(new Rect(0, 0, 256, 64), LogoTexture);

        string panelText = "Login to Facebook";

        if (FB.IsLoggedIn)
        {
            panelText = "Welcome ";
            if (GameStateManager.Username != null)
            {
                panelText += GameStateManager.Username + "!";
            }
            else
            {
                panelText += "Smasher!";
            }
        }

        if (GameStateManager.Score > 0)
        {
            panelText += "\nScore: " + GameStateManager.Score.ToString();
        }

        GUILayout.Box("", MenuSkin.GetStyle("panel_welcome"));
        if (GameStateManager.UserTexture != null)
        {
            GUI.DrawTexture(new Rect(8, 74, 150, 150), GameStateManager.UserTexture);
        }
        GUI.Label(new Rect(6 + 160 + 6, 72, 459 - (6 + 160 + 6), 160), panelText, MenuSkin.GetStyle("text_only"));

        if (!FB.IsLoggedIn)
        {
            if (GUI.Button(buttonSize, "", MenuSkin.GetStyle("button_login")))
            {
                FB.Login("email,publish_actions", LoginCallback);
            }
        }

        if (GUILayout.Button("", MenuSkin.GetStyle("button_play")))
        {
            if (friends != null && friends.Count > 0)
            {
                Dictionary <string, string> friend = FBUtil.RandomFriend(friends);
                GameStateManager.FriendName = friend["first_name"];
                GameStateManager.FriendID   = friend["id"];
                StartCoroutine(FBUtil.GetFriendPictureTexture(friend["id"]));
            }

            Application.LoadLevel("GameStage");
            GameStateManager.Instance.StartGame();
        }

        if (FB.IsLoggedIn)
        {
            if (GameStateManager.Score > 0)
            {
                if (GUILayout.Button("", MenuSkin.GetStyle("button_brag")))
                {
                    FB.Feed(
                        linkCaption: "I just smashed " + GameStateManager.Score.ToString() + " friends! Can you beat it?",
                        picture: "http://www.friendsmash.com/images/logo_large.jpg",
                        linkName: "Checkout my Friend Smash greatness!",
                        link: "http://apps.facebook.com/friendsmashunity/?challenge_brag=" + (FB.IsLoggedIn ? FB.UserId : "guest")
                        );
                }
            }


            if (GUILayout.Button("", MenuSkin.GetStyle("button_challenge")))
            {
                if (GameStateManager.Score != 0 && GameStateManager.FriendID != null)
                {
                    string[] recipient = { GameStateManager.FriendID };
                    FB.AppRequest(
                        message: "I just smashed you " + GameStateManager.Score.ToString() + " times! Can you beat it?",
                        to: recipient,
                        data: "{\"challenge_score\":" + GameStateManager.Score.ToString() + "}",
                        title: "Friend Smash Challenge!"
                        );
                }
                else
                {
                    FB.AppRequest(
                        message: "Friend Smash is smashing! Check it out.",
                        title: "Play Friend Smash with me!"
                        );
                }
            }

            TournamentCallback();
        }


        #if UNITY_WEBPLAYER
        Screen.fullScreen = GUILayout.Toggle(Screen.fullScreen, "");
        #endif
    }