void Awake() { goMenu = false; DFB.FBInit(); showGift = true; showFullBanner = false; }
public void SendAskFriendButton() { string mUserIds = ""; List <Transform> arrItem = gridView.gameObject.GetComponent <UIGrid>().GetChildList(); for (int i = 0; i < arrItem.Count; i++) { if (arrItem[i].FindChild("Checkbox").gameObject.GetComponent <UIToggle>().value) { mUserIds += arrItem[i].gameObject.GetComponent <ItemSelectFriend>().UserId + ","; } } DFB.FBAskForLife(mUserIds.Split(','), result => { if (!String.IsNullOrEmpty(result.Error)) { Debug.Log(result.Error); } else { Debug.Log(result.Text); CloseButton(); } }); }
public void SendInviteFriend() { string mUserIds = ""; List <Transform> arrItem = gridView.gameObject.GetComponent <UIGrid>().GetChildList(); for (int i = 0; i < arrItem.Count; i++) { if (arrItem[i].FindChild("Checkbox").gameObject.GetComponent <UIToggle>().value) { if (mUserIds.Length < 1) { mUserIds += arrItem[i].gameObject.GetComponent <ItemSelectFriend>().UserId; } else { mUserIds += "," + arrItem[i].gameObject.GetComponent <ItemSelectFriend>().UserId; } } } Debug.Log(" Count FRIEND --- " + mUserIds.Length); DFB.FBRequestDirect(mUserIds.Split(','), "Invite Your Friends", "Play this game with me!", (result) => { int leng = mUserIds.Split(',').Length; Debug.Log(result.Text); var dict = Json.Deserialize(result.Text) as IDictionary; if (dict != null && dict["request"] != null) { //--------------Achievement 22------------------------------------ DialogAchievement.AddDataAchievement(22, leng); CloseButton(); } }); }
public void SendHelpButton() { string mUserIds = ""; List <Transform> arrItem = gridView.gameObject.GetComponent <UIGrid>().GetChildList(); for (int i = 0; i < arrItem.Count; i++) { if (arrItem[i].FindChild("Checkbox").gameObject.GetComponent <UIToggle>().value) { mUserIds += arrItem[i].gameObject.GetComponent <ItemSelectFriend>().UserId + ","; } } DFB.FBSendLife(mUserIds.Split(','), result => { int leng = mUserIds.Split(',').Length; if (!String.IsNullOrEmpty(result.Error)) { Debug.Log(result.Error); } else { Debug.Log(result.Text); var dict = Json.Deserialize(result.Text) as IDictionary; if (dict != null && dict["request"] != null) { //--------------Achievement 1------------------------------------ DialogAchievement.AddDataAchievement(1, leng - 1); CloseButton(); } } }); }
public void DeleteItemButton(Facebook.FacebookDelegate callback = null) { if (callback == null) { callback = result => { if (!String.IsNullOrEmpty(result.Error)) { Debug.LogError(result.Error); } else { //Cong tim khi nguoi dung nhan AudioControl.AddHeart(1); if (this != null) { Transform gridView = this.transform.parent;//This => Grid gridView.GetComponent <UIGrid>().RemoveChild(this.transform); Destroy(this.gameObject); } } }; } //Delete Request && Item if (requestId.Length > 0) { DFB.FBDeleteRequest(requestId, callback); } else { Debug.LogError("Request id not valid: " + requestId); } }
public void ShowDialogHelpFriend() { Show = true; gridView.parent.GetComponent <UIScrollView>().ResetPosition(); gridView.transform.parent.GetComponent <UIPanel>().clipOffset = new Vector2(); gridView.transform.parent.localPosition = new Vector2(); this.transform.FindChild("SendLife").gameObject.SetActive(true); this.transform.FindChild("SendInvite").gameObject.SetActive(false); this.transform.FindChild("SendAskLife").gameObject.SetActive(false); this.transform.FindChild("ForeGround").FindChild("Title").gameObject.GetComponent <UILabel>().text = MissionControl.Language["Help_friend_detail"]; this.transform.FindChild("ForeGround").FindChild("Logo").FindChild("name").GetComponent <UILabel>().text = MissionControl.Language["Friend_list"]; this.transform.FindChild("SelectAll").FindChild("Label").GetComponent <UILabel>().text = MissionControl.Language["Select_all"]; this.transform.FindChild("SendLife").FindChild("Label").GetComponent <UILabel>().text = MissionControl.Language["Send"]; DFB.FBGetUserFriend(100, result => { try { if (!String.IsNullOrEmpty(result.Error)) { Debug.LogError(result.Error); dialogLoading.gameObject.SetActive(false); transform.parent.parent.GetComponent <MissionControl>().ShowConfirm(); } else { if (dialogLoading.gameObject.activeInHierarchy) { RemoveAllItem(); var dict = Json.Deserialize(result.Text) as IDictionary; Debug.Log(JsonHelper.FormatJson(result.Text)); List <object> arrDanhSachBanBe = dict["data"] as List <object>; int size = arrDanhSachBanBe.Count; int startNumber = 0; if (size > max_friend_list) { size = max_friend_list; startNumber = UnityEngine.Random.Range(0, arrDanhSachBanBe.Count - max_friend_list); } for (int i = startNumber; i < size + startNumber; i++) { Dictionary <string, object> data = arrDanhSachBanBe[i] as Dictionary <string, object>; AddItemSelectFriendAPI(data, true); } LeanTween.scale(gameObject, new Vector3(1f, 1f, 1f), 0.3f).setUseEstimatedTime(true).setEase(LeanTweenType.easeInOutBack); } } } catch (Exception e) { Debug.Log("--------------------catch error StartCoroutine-------------------" + e.Message); transform.parent.parent.GetComponent <MissionControl>().ShowConfirm(); } }); }
public void AcceptAllButton() { List <Transform> arrItemReceive = gridViewReceive.gameObject.GetComponent <UIGrid>().GetChildList(); List <Transform> arrItemRequest = gridViewRequest.gameObject.GetComponent <UIGrid>().GetChildList(); if (transform.FindChild("TabReceiveOn").gameObject.activeInHierarchy) { for (int i = 0; i < arrItemReceive.Count; i++) { arrItemReceive[i].GetComponent <ItemReceive>().DeleteItemButton(); } lbInbox.gameObject.SetActive(true); } else if (arrItemRequest.Count > 0) { string mUserId = ""; for (int i = 0; i < arrItemRequest.Count; i++) { mUserId += arrItemRequest[i].gameObject.GetComponent <ItemReceive>().UserId + ","; } DFB.FBSendLife(mUserId.Split(','), result => { if (!String.IsNullOrEmpty(result.Error)) { Debug.Log(result.Error); } else { Debug.Log(result.Text); fb_result = result.Text; var dict = Json.Deserialize(result.Text) as IDictionary; if (dict["cancelled"] != null) { fb_result += " Bam cancel => ko xoa request"; Debug.Log(" Bam cancel => ko xoa request"); } else { fb_result += " Xoa list arrItemRequest.Count " + arrItemRequest.Count; for (int i = 0; i < arrItemRequest.Count; i++) { arrItemRequest[i].GetComponent <ItemReceive>().DeleteItemButton(); //arrItemRequest.RemoveAt(i); } } ShowNoMessage(); } }); } }
//Send backrequest and delete curent request public void SendButton() { DFB.FBSendLife(this.userId.Split(','), result => { if (!String.IsNullOrEmpty(result.Error)) { Debug.Log(result.Error); } else { IDictionary dict = Json.Deserialize(result.Text) as IDictionary; bool cancel = dict["cancelled"] != null && (bool)dict["cancelled"]; if (!cancel) { DeleteItemButton(); } } }); }
//Dung Monobehaviour cua cha no. vi nhieu luc no ko active tren Hierarchi thi fai dung den cha cua no public void SetData(MonoBehaviour monobehavior, string mUserId = "") { this.UserId = mUserId; if (mUserId.Length > 0) { //Load avatar va save no laj neu chua co trong bo nho cache string nameImage = mUserId + ".jpg"; string dirPath = Application.persistentDataPath + "/cacheavatar/"; string filePath = dirPath + nameImage; if (System.IO.File.Exists(filePath)) { WWW imageToLoadPath = new WWW("file://" + filePath); Texture2D texture2d = new Texture2D(128, 128, TextureFormat.RGB24, false); imageToLoadPath.LoadImageIntoTexture(texture2d); this.GetComponent <UITexture>().mainTexture = texture2d; } else { if (FB.IsLoggedIn) { DFB.FBLoadAndSaveAvatar(monobehavior, "" + UserId, texture => { byte[] bytes = texture.EncodeToJPG(); if (!System.IO.Directory.Exists(dirPath)) { System.IO.Directory.CreateDirectory(dirPath); Debug.Log("Create directory"); } System.IO.File.WriteAllBytes(filePath, bytes); try { this.GetComponent <UITexture>().mainTexture = texture; } catch (Exception e) { Debug.Log("---------------ERROR------------------" + e.Message); } }, false, 128, 128); } } } }
public void ButtonFB() { if (FB.IsLoggedIn) { DataCache.SaveAchievementCache(true); Transform confirm = Instantiate(DilogConfirm) as Transform; confirm.GetComponent <DialogConfirm>().ShowDialog(MissionControl.Language["LOGOUT"], MissionControl.Language["Logout_confirm"], () => { //Dang xuat .submit tat ca du lieu len server, sau do xoa sach data DFB.FBLogout(); transform.parent.parent.GetComponent <MissionControl>().LogoutButton(); DataCache.DeleteUserData(); DataCache.GetAchievementCacheData(); LoadingScene.ShowLoadingScene("Mission", true); }); } else { transform.parent.parent.GetComponent <MissionControl>().LoginButton(false); } ChangeLanguage(); }
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(); } }
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); }
public void SetData(Dictionary <string, object> info, MonoBehaviour monoBehavier = null) { this.requestId = info["id"] as string; this.data = info["data"] as string; Dictionary <string, object> sender = info["from"] as Dictionary <string, object>; this.userId = sender["id"] as string; string from_name = sender["name"] as string; string messageShow = ""; Texture icon = iconLife; if (data == DString.DATA_SEND_LIFE)//khi ban be gui mang den cho minh { messageShow = "gave you a life. Accept and send back!"; if ("Vietnamese".Equals(VariableSystem.language)) { messageShow = "tặng bạn 1 tim. Chấp nhận và gửi lại tim!"; } } else if (data == DString.DATA_ASK_LIFE)//Khi ban be nho minh cho mang { messageShow = "need a life. Accept and send back!"; if ("Vietnamese".Equals(VariableSystem.language)) { messageShow = "cần giúp đỡ. Chấp nhận để gửi tim!"; } } //Load avatar va save no laj neu chua co trong bo nho cache string nameImage = userId + ".jpg"; string dirPath = Application.persistentDataPath + "/cacheavatar/"; string filePath = dirPath + nameImage; if (System.IO.File.Exists(filePath)) { WWW imageToLoadPath = new WWW("file://" + filePath); Texture2D texture2d = new Texture2D(128, 128, TextureFormat.RGB24, false); imageToLoadPath.LoadImageIntoTexture(texture2d); this.transform.FindChild("Avatar").GetComponent <UITexture>().mainTexture = texture2d; } else { if (monoBehavier == null) { monoBehavier = this; } DFB.FBLoadAndSaveAvatar(monoBehavier, "" + userId, texture => { byte[] bytes = texture.EncodeToJPG(); if (!System.IO.Directory.Exists(dirPath)) { System.IO.Directory.CreateDirectory(dirPath); Debug.Log("Create directory"); } System.IO.File.WriteAllBytes(filePath, bytes); this.transform.FindChild("Avatar").GetComponent <UITexture>().mainTexture = texture; }, false, 128, 128); } this.transform.FindChild("IconItem").GetComponent <UITexture>().mainTexture = icon; this.content = from_name + ": " + messageShow; transform.FindChild("Content").gameObject.GetComponent <UILabel>().text = content; transform.FindChild("ButtonSend").FindChild("Label").GetComponent <UILabel>().text = MissionControl.Language["Send"]; }
public void SetDataAPI(Dictionary <string, object> info, MonoBehaviour monoBehavier, bool isAppUser = false) { UserId = info["id"] + ""; UserName = info["name"] as string; transform.FindChild("Name").gameObject.GetComponent <UILabel>().text = UserName; if (isAppUser) { //Load avatar va save no laj neu chua co trong bo nho cache string nameImage = UserId + ".jpg"; string dirPath = Application.persistentDataPath + "/cacheavatar/"; string filePath = dirPath + nameImage; if (System.IO.File.Exists(filePath)) { WWW imageToLoadPath = new WWW("file://" + filePath); Texture2D texture2d = new Texture2D(128, 128, TextureFormat.RGB24, false); imageToLoadPath.LoadImageIntoTexture(texture2d); try { this.transform.FindChild("Avatar").GetComponent <UITexture>().mainTexture = texture2d; } catch (Exception e) { Debug.LogError(e.Message); } } else { if (monoBehavier == null) { monoBehavier = this; } DFB.FBLoadAndSaveAvatar(monoBehavier, "" + UserId, texture => { byte[] bytes = texture.EncodeToJPG(); if (!System.IO.Directory.Exists(dirPath)) { System.IO.Directory.CreateDirectory(dirPath); Debug.Log("Create directory"); } System.IO.File.WriteAllBytes(filePath, bytes); try { this.transform.FindChild("Avatar").GetComponent <UITexture>().mainTexture = texture; } catch (Exception e) { Debug.Log(e.Message); } }, false, 128, 128); } } else { Dictionary <string, object> pic = info["picture"] as Dictionary <string, object>; Dictionary <string, object> picData = pic["data"] as Dictionary <string, object>; string url = picData["url"] as string; try { StartCoroutine(DFB.LoadPictureEnumerator(url, texture => { Util.Log("MyPictureCallback"); try { this.transform.FindChild("Avatar").GetComponent <UITexture>().mainTexture = texture; } catch (Exception e) { Debug.LogError(e.Message); } })); } catch (Exception e) { Debug.Log("--------------------catch error StartCoroutine-------------------" + e.Message); } } }