示例#1
0
 public void Finish(byte[] data, bool isError, FileType type, string url)
 {
     //Debug.Log("Finish......................");
     if (!isError)
     {
         if (type == FileType.Image)
         {
             sf.OnFadeOut();
             videoPlayer.gameObject.SetActive(false);
             image.gameObject.SetActive(true);
             DestroyImmediate(newTexture);
             newTexture = null;
             if (NetWorkManager.imageSize.ContainsKey(url))
             {
                 if (!isReversal)
                 {
                     DefaultSizeToiFit(url, data);
                 }
                 else
                 {
                     ReversalSizeToFit(url, data);
                 }
             }
             else
             {
                 //Debug.Log("Default...........................");
                 newTexture = new Texture2D(defaultWidth, defaultHeight);
                 newTexture.LoadImage(data);
                 if (image != null)
                 {
                     image.sprite = Sprite.Create(newTexture, new Rect(0, 0, defaultWidth, defaultHeight), new Vector2(0.5f, 0.5f));
                 }
             }
         }
         else if (type == FileType.Video)
         {
             sf.OnFadeOut();
             videoPlayer.url = NetWorkManager.VideoPath + "/" + url;
             videoPlayer.gameObject.SetActive(true);
             image.gameObject.SetActive(false);
             videoPlayer.Play();
         }
     }
 }
示例#2
0
    public IEnumerator DownloadImages(string url)
    {
        bool isNet = false;

        isDowning = true;
        WWW www = null;

        if (imageDic.ContainsKey(url))
        {
            //替换本地路径
            //Debug.Log("Load from location............");
            www = new WWW(LocationPath + "/" + url);
        }
        else
        {
            isNet = true;
            //Debug.Log("Load from network............"+ (FileUrl + WWW.EscapeURL(url)));
            //www = new WWW(BaseURL + "get?name=" + url);
            www = new WWW(FileUrl + WWW.EscapeURL(url));
        }
        //定义www为WWW类型并且等于所下载下来的WWW中内容。
        yield return(www);

        isDowning = false;
        if (www.error != null)
        {
            Debug.LogError(www.error);
        }
        else
        {
            if (isNet)
            {
                imageDic.Add(url, "");
            }
            if (url.EndsWith(".mp4"))
            {
                sf.OnFadeOut();
                Debug.Log("mp4.................");
                SaveData(www.bytes, url);
                videoPlayer.url = VideoPath + "/" + url;
                videoPlayer.gameObject.SetActive(true);
                image.gameObject.SetActive(false);
                videoPlayer.Play();
            }
            else if (url.EndsWith(".jpg") || url.EndsWith("png"))
            {
                sf.OnFadeOut();
                videoPlayer.gameObject.SetActive(false);
                image.gameObject.SetActive(true);
                Texture2D newTexture = www.texture;
                byte[]    imageData  = newTexture.EncodeToJPG();
                if (image != null)
                {
                    image.sprite = Sprite.Create(newTexture, new Rect(0, 0, newTexture.width, newTexture.height), new Vector2(0.5f, 0.5f));
                }
                SaveData(imageData, url);
            }
            else
            {
                Debug.Log("url" + url + " 格式不支持!");
            }
        }
    }