Exemplo n.º 1
0
    public AvatarCacheOrDownload(string url, CallBackDownloadImage callback, bool needTextureNull)
    {
        if (PlayerPrefs.HasKey(url))
        {
            byte[]    bytes = System.Convert.FromBase64String(PlayerPrefs.GetString(url));
            Texture2D text  = new Texture2D(0, 0, TextureFormat.ARGB32, false);
            text.LoadImage(bytes);

            if (text == null)
            {
                PlayerPrefs.DeleteKey(url);
                goto LOADNULL;
            }

            if (callback != null)
            {
                callback(text);
            }
            return;
        }

LOADNULL:
        if (downloading.ContainsKey(url))
        {
            downloading[url].Add(callback);
        }
        else
        {
            downloading.Add(url, new List <CallBackDownloadImage>()
            {
                callback
            });
            GameManager.Instance.StartCoroutine(_Download(url, needTextureNull));
        }
    }
Exemplo n.º 2
0
 public void LogoTexture(CallBackDownloadImage callback)
 {
     if (_logoTexture != null)
     {
         callback(_logoTexture);
     }
     else
     {
         new AvatarCacheOrDownload(imageUrl, callback);
     }
 }
Exemplo n.º 3
0
 public void AvatarTexture(CallBackDownloadImage callback)
 {
     if (_avatarTexture != null)
     {
         callback(_avatarTexture);
     }
     else
     {
         new AvatarCacheOrDownload(_avatarUrl, callback);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 /// Lấy ảnh từ ID
 /// </summary>
 public static void GetAvatarFromId(int id, CallBackDownloadImage callback)
 {
     if (id == 0)
     {
         if (callback != null)
         {
             callback((Texture)Resources.Load("Images/Avatar/NoAvatar", typeof(Texture)));
         }
         return;
     }
     new AvatarCacheOrDownload(ServerWeb.URL_GET_AVATAR_FROM_ID + id, callback);
 }
Exemplo n.º 5
0
 public void LoadTexture(CallBackDownloadImage callback)
 {
     if (_image != null)
     {
         callback(_image);
     }
     else
     {
         ServerWeb.GetImageFromUrl(imageUrl, "", delegate(UnityEngine.Texture texture)
         {
             _image = texture;
             callback(_image);
         });
     }
 }
Exemplo n.º 6
0
    static IEnumerator _DownloadImage(string url, string pathResourcesDefaultImage, CallBackDownloadImage callback)
    {
        Texture _texture;

        if (string.IsNullOrEmpty(url))
        {
            _texture = (Texture)Resources.Load(pathResourcesDefaultImage, typeof(Texture));
        }
        else
        {
            WWW www = new WWW(url);
            yield return(www);

            if (www.error != null)
            {
                _texture = (Texture)Resources.Load(pathResourcesDefaultImage, typeof(Texture));
            }
            else
            {
                _texture = www.texture;
            }
        }
        callback(_texture);
    }
Exemplo n.º 7
0
 /// <summary>
 /// Download ảnh từ Url web
 /// </summary>
 /// <param name="url">Url sẽ download ảnh</param>
 /// <param name="pathResourcesDefaultImage">Image mặc định nếu không thể download</param>
 /// <param name="callback">Callback method khi download xong</param>
 public static void GetImageFromUrl(string url, string pathResourcesDefaultImage, CallBackDownloadImage callback)
 {
     GameManager.Instance.StartCoroutine(_DownloadImage(url, pathResourcesDefaultImage, callback));
 }