コード例 #1
0
    public void ToggleFacebookLink()
    {
        if (PF_PlayerData.accountInfo.FacebookInfo != null)
        {
            Action <bool> afterCheck = (bool response) =>
            {
                if (response == true)
                {
                    //unlink
                    UnityAction afterUnlink = () =>
                    {
                        Text txt = this.linkToFaceBook.GetComponentInChildren <Text>();
                        txt.color = Color.red;
                        txt.text  = GlobalStrings.LINK_FB_BTN_MSG;
                        this.facebookPicture.overrideSprite = null;
                        Debug.Log("NEED ACCOUNT REFRESH???");
                        PF_PlayerData.accountInfo.FacebookInfo = null;
                        this.changedLoginState = true;
                    };

                    PF_PlayerData.UnlinkFBAccount(afterUnlink);
                }
            };

            DialogCanvasController.RequestConfirmationPrompt(GlobalStrings.CONFIRM_UNLINK_PROMPT, GlobalStrings.CONFIRM_UNLINK_MSG, afterCheck);
        }
        else
        {
            // link
            UnityAction afterLink = () =>
            {
                Text btnText = this.linkToFaceBook.GetComponentInChildren <Text>();
                btnText.text  = GlobalStrings.UNLINK_FB_BTN_MSG;
                btnText.color = Color.green;


                Debug.Log("NEED ACCOUNT REFRESH???");
                this.changedLoginState = true;
                PF_PlayerData.accountInfo.FacebookInfo = new UserFacebookInfo();

                UnityAction <Texture2D> afterGetPhoto = (Texture2D tx) =>
                {
                    facebookPicture.overrideSprite = Sprite.Create(tx, new Rect(0, 0, 128, 128), new Vector2());
                };

                StartCoroutine(FacebookHelperClass.GetPlayerProfilePhoto(FetchWebAsset, afterGetPhoto));
            };

            PF_PlayerData.LinkFBAccount(afterLink);
        }
    }