using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;

public class LoadImageHelper : MonoBehaviour
{
    string defaultUrl = "https://zx-cdn.zhangxinhulian.com/images/2020/10/193e4723463e0f84fc3ff70408813a3d8e7a9cd8.png";
    /// <summary>
    /// use this to load image
    /// </summary>
    /// <param name="texture"></param>
    /// <param name="url"></param>
    public void LoadImage(RawImage rawImage, string url)
    {
        if (string.IsNullOrEmpty(url))
        {
            url = defaultUrl;
        }
        StartCoroutine(LoadTeture(url, (tex) => {
            rawImage.texture = tex;
        }));
    }

    IEnumerator LoadTeture(string url, Action<Texture2D> cb)
    {
        yield return LoadImageMgr.instance.LoadImage(url, cb);
    }

}
