Unity3D/Tips

[펌/수정] Get size of an online assetbundle and progress in Kb ?

blueasa 2018. 4. 18. 16:06

[TroubleShooting]


[에러메시지]

NotSupportedException: .... System.Net.WebRequest.GetCreator (System.String prefix) System.Net.WebRequest.Create (System.Uri requestUri)


PC/iOS에서는 잘 되는데 Android에서 위와 같은 NotSupportedException이 난다.(현재 Unity v5.6.5f1)

검색해보니 게임코디에 아래와 같은 답변을 해주신 분이 있다.



  비회원: 
kimsama

NotSupportedException: .... System.Net.WebRequest.GetCreator (System.String prefix) System.Net.WebRequest.Create (System.Uri requestUri) 모바일에서 위의 에러로 인해 HttpWebReaquest 를 사용하지 못하는 경우라면 여기 링크의 내용 참고하시기 바랍니다. http://www.vovchik.org/blog/13001 간단하게 우회하는 방법이 나와 있습니다.

[출처] http://lab.gamecodi.com/board/zboard.php?id=GAMECODILAB_QnA_etc&page=2&sn1=&divpage=1&sn=off&ss=on&sc=on&select_arrange=headnum&desc=asc&no=2617



그래서 링크(http://www.vovchik.org/blog/13001)에서 말해준 대로 Wrapping을 해서 Android에서 돌려보니 잘된다!!

(kimsama님 감사합니다!)


내가 추가 및 수정한 소스는 아래와 같다.


// Wrapper Class
using System;
using System.Net;

public class HttpRequestCreator : IWebRequestCreate 
{
	public WebRequest Create(Uri uri)
	{
		return new HttpWebRequest(uri);	
	}
}


    //Get size of the asset
    HttpRequestCreator cHttpRequestCreator = new HttpRequestCreator();            // modify
    System.Net.WebRequest req = cHttpRequestCreator.Create(new Uri(assetURL));    // modify
    req.Method = "HEAD";

    float ContentLength;
    using (System.Net.WebResponse resp = req.GetResponse())
    {
        float.TryParse(resp.ContentLength.ToString(), out ContentLength);
    }

    while (!download.isDone)
    {
        if (progressBar != null)
	    {
            progressBar.LabelInformations = "Downloading Assets";
            progressBar.Progress = download.progress;
            progressBar.AssetSize = ContentLength / 1000000; //(Mb)
	    }
	    yield return null;
    }






- CDN에 있는 파일 사이즈를 어떻게 알 수 없나 하고 찾다가 테스트 해보고 잘 되길래 올려 놓음.

  (PC/iOS는 잘되는데 Android가 에러나서 위와 같이 고침)

    1. //Get size of the asset
    2. System.Net.WebRequest req = System.Net.HttpWebRequest.Create(assetURL);
    3. req.Method = "HEAD";
    4. float ContentLength;
    5. using (System.Net.WebResponse resp = req.GetResponse())
    6. {
    7. float.TryParse(resp.ContentLength.ToString(), out ContentLength);
    8. }
    9. while (!download.isDone)
    10. {
    11. if (progressBar != null)
    12. {
    13. progressBar.LabelInformations = "Downloading Assets";
    14. progressBar.Progress = download.progress;
    15. progressBar.AssetSize = ContentLength / 1000000; //(Mb)
    16. }
    17. yield return null;
    18. }


[출처] https://answers.unity.com/questions/1035361/get-size-of-an-online-assetbundle-and-progress-in.html




반응형