using System;
using System.Collections;
using UnityEngine;

namespace mgaia.Utils
{
    /// <summary>
    /// Extensões do objeto Texture2D
    /// </summary>
    /// <owner>Victor</owner>
    public static class Texture2DExtensions
    {
        /// <summary>
        /// Carrega uma textura a partir de uma URL
        /// </summary>
        public static IEnumerator LoadFromUrl(this Texture2D texture, string url)
        {
            WWW downloadImageRequest = new WWW(url);

            yield return downloadImageRequest;

            downloadImageRequest.LoadImageIntoTexture(texture);
        }

        /// <summary>
        /// Carrega uma textura a partir de uma URL
        /// </summary>
        public static Texture2D LoadFromUrl(string url)
        {
            Texture2D image = new Texture2D(1, 1, TextureFormat.DXT1, false);
            image.LoadFromUrl(url);

            return image;
        }
    }
}