Exemple #1
0
 //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);
             }
         }
     }
 }
Exemple #2
0
    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);
         }
     }
 }