Пример #1
0
 public void LoginButton()
 {
     AudioControl.DPlaySound("Click 1");
     if (FB.IsInitialized)
     {
         if (!isShowLogin)
         {
             isShowLogin = true;
             if (!FB.IsLoggedIn)
             {
                 DFB.FBLogin(result =>
                 {
                     if (FB.IsLoggedIn)
                     {
                         if (String.IsNullOrEmpty(PlayerPrefs.GetString(DataCache.FB_ID, "")))
                         {
                             FB.API("v2.2/me", Facebook.HttpMethod.GET, rsl =>
                             {
                                 IDictionary dict1 = Json.Deserialize(rsl.Text) as IDictionary;
                                 if (dict1 != null && dict1["id"] != null)
                                 {
                                     DFB.UserId   = "" + dict1["id"];
                                     DFB.UserName = "" + dict1["name"];
                                     PlayerPrefs.SetString(DataCache.FB_ID, DFB.UserId);
                                     PlayerPrefs.SetString(DataCache.FB_USER, DFB.UserName);
                                     try
                                     {
                                         AudioControl.getMonoBehaviour().StartCoroutine(DHS.PostMeInfo(DFB.UserId, DFB.UserName, "" + dict1["locale"], "" + dict1["last_name"]));
                                     }
                                     catch (Exception e)
                                     {
                                         Debug.Log("--------------------catch error StartCoroutine-------------------" + e.Message);
                                     }
                                 }
                             });
                         }
                         else
                         {
                             DFB.UserId   = PlayerPrefs.GetString(DataCache.FB_ID);
                             DFB.UserName = PlayerPrefs.GetString(DataCache.FB_USER);
                         }
                         HideLoginDialog();
                     }
                     else
                     {
                         isShowLogin = false;
                         ShowCofirm();
                     }
                 });
             }
             else
             {
                 HideLoginDialog();
             }
         }
     }
     else
     {
         ShowCofirm();
     }
 }
Пример #2
0
    public void LoginButton(bool hideLoading = true)
    {
        //MobilePlugin.getInstance().ShowToast("Click login");
        string error = "";

        //AudioControl.DPlaySound("Click 1");
        try
        {
            if (FB.IsInitialized)
            {
                if (FB.IsLoggedIn)
                {
                    HideLoginDialog();
                    GetFriendsList();
                    loginButton.gameObject.SetActive(false);
                    transform.FindChild("Button").FindChild("ButtonShowMessage").gameObject.SetActive(true);
                    //    transform.FindChild("Button").FindChild("ButtonInviteFriend").gameObject.SetActive(true);
                    //       transform.FindChild("Button").FindChild("ButtonHelpFriend").gameObject.SetActive(true);
                }
                else
                {
                    DFB.FBLogin(result =>
                    {
                        //MobilePlugin.getInstance().ShowToast("FB.IsLoggedIn " + FB.IsLoggedIn);
                        if (FB.IsLoggedIn)
                        {
                            loginButton.gameObject.SetActive(false);
                            transform.FindChild("Button").FindChild("ButtonShowMessage").gameObject.SetActive(true);
                            //     transform.FindChild("Button").FindChild("ButtonInviteFriend").gameObject.SetActive(true);
                            //    transform.FindChild("Button").FindChild("ButtonHelpFriend").gameObject.SetActive(true);
                            //get friends list
                            GetFriendsList();
                            //count message
                            CountMessage();
                            //Get info user
                            if (String.IsNullOrEmpty(PlayerPrefs.GetString(DataCache.FB_ID, "")))
                            {
                                FB.API("v2.2/me", Facebook.HttpMethod.GET, rsl =>
                                {
                                    IDictionary dict1 = Json.Deserialize(rsl.Text) as IDictionary;
                                    if (dict1 != null && dict1["id"] != null)
                                    {
                                        DFB.UserId   = "" + dict1["id"];
                                        DFB.UserName = "" + dict1["name"];
                                        PlayerPrefs.SetString(DataCache.FB_ID, DFB.UserId);
                                        PlayerPrefs.SetString(DataCache.FB_USER, DFB.UserName);
                                        try
                                        {
                                            AudioControl.getMonoBehaviour().StartCoroutine(DHS.PostMeInfo(DFB.UserId, DFB.UserName, "" + dict1["locale"], "" + dict1["last_name"]));
                                        }
                                        catch (Exception e)
                                        {
                                            ShowConfirm();
                                            Debug.Log("--------------------catch error StartCoroutine-------------------" + e.Message);
                                            error = "" + e.Message;
                                        }
                                    }
                                });
                            }
                            else
                            {
                                DFB.UserId   = PlayerPrefs.GetString(DataCache.FB_ID);
                                DFB.UserName = PlayerPrefs.GetString(DataCache.FB_USER);
                            }
                        }
                        else
                        {
                            ShowConfirm();
                        }
                    });
                }
            }
            else
            {
                DFB.FBInit();
                ShowConfirm();
            }
        }
        catch (Exception e)
        {
            ShowConfirm();
            Debug.Log("--------------------Error Login FB-------------------" + e.Message);
            error = "" + e.Message;
        }
        //MobilePlugin.getInstance().ShowToast("error " + error);
    }