Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Aubrey-Falconer · Dec 19, 2011 at 03:13 AM · www

Extra WWW download statistics?

My game loads AssetBundles off the internet while players watch a % climb from 0 to 100, which is rather boring. I am working on a more elegant loading interface, and it would be quite cool if I could show players (at a minimum) how many MB they have downloaded, and how many MB are left to download.

I know most webservers provide the total size of a file in the initial http request response, but is there any way to get this information through Unity's WWW object? Accessing www.size before the download is complete results in a runtime error. "You are trying to load data from a www stream which has not completed the download yet."

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image cregox · Jun 06, 2013 at 08:37 PM 0
Share

I hope it is possible too, but I doubt it. Did you find any good solution?

If you don't need async operations, you can do it safely with `WebRequest.GetResponse` but I've need it to be async and I've been trying to do it on `BeginGetResponse` without much success.

avatar image xKroniK13x · Jun 06, 2013 at 08:43 PM 0
Share

Why couldn't you have a simple script find the total size of the file you are downloading, and then with the percentage do a simple calculation. Say it's 23.4$$anonymous$$B, and at 8%, 23.4*.08 = #$$anonymous$$B downloaded.

You could use PHP to do this script, or the assetbundle on the server could be named according to this size... so like, ASSET_23.4.unity3d, and then use a command to get the 23.4 by removing the .unity3d and information before _.

avatar image cregox · Jun 06, 2013 at 08:49 PM 0
Share

Because we want to simplify things, $$anonymous$$roni$$anonymous$$

avatar image xKroniK13x · Jun 06, 2013 at 09:41 PM 0
Share

I provided an example in an answer below. Not too hard!

avatar image bhuvanesh22 · Apr 01, 2016 at 06:15 AM 0
Share

hi x$$anonymous$$roni$$anonymous$$13x , can I get this script in c# for unity... please.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by ina · Dec 19, 2011 at 03:25 AM

Check out responseheaders! http://answers.unity3d.com/questions/23003/http-reponse-headers.html

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Aubrey-Falconer · Dec 19, 2011 at 04:02 AM 1
Share

Awesome!

Unfortunatley, it doesn't work. Unity's WWW class won't share the response headers it received from the server until it has fully downloaded the file from the server. Why this is, I can't imagine...

If I try to access the ResponseHeadersString from the www class directly, I get this: "'UnityEngine.WWW.get_responseHeadersString()' is inaccessible due to its protection level."

Am I stonewalled, or might there be a way around this?

avatar image
0

Answer by xKroniK13x · Jun 06, 2013 at 09:26 PM

It's pretty simple to implement a naming system that would work; just add the size into the file name. I wrote a script for doing that. You can have as many underscores in the name as you want, just the size has to be after the last. I used ASSET_BUNDLE_24.1.unity3d as a tester for this.

 var assetBundleExtension : String; //The extension, minus the '.' , so unity3d for .unity3d
 
 function Start() {
     assetBundleExtension = "." + assetBundleExtension;
     DownloadAssetBundle("http://full/url/to/bundle_size.unity3d");
 }
 
 function DownloadAssetBundle (url : String) {
     var fileNameWithExt = Path.GetFileName(url);
     var fileName = fileNameWithExt.Replace(assetBundleExtension, "");
     fileName = fileName.Substring(0, fileName.LastIndexOf('_'));
     var fileSize = (fileNameWithExt.Replace(fileName + "_", "")).Replace(assetBundleExtension, "");
     print("Downloading asset bundle: " + fileName + ", size: " + fileSize + "MB.");
 }

Throw that in a new UnityScript file and check it out. Just call on the DownloadAssetBundle() function with the url in the parenthesis, and it will decipher all of it for you. Then, you can access fileSize, so if it's at, say, 8%, you could do

var currentSize = .08 * fileSize;

That should do it! I didn't test multiplying it by a percent, you may have to parseint on it, if so just google it. Real simple.

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image cregox · Jun 06, 2013 at 10:01 PM 0
Share

And how will you guess the size to get the url file name?

avatar image xKroniK13x · Jun 06, 2013 at 10:19 PM 0
Share

You wouldn't. When you create the assetbundle and upload it to the server, you say how big it is. So when you create the bundle, you check out the size. Alternatively, however you upload it, you can have the PHP script rename it to have the size in $$anonymous$$B at the end.

avatar image cregox · Jun 06, 2013 at 10:23 PM 0
Share

"check out the size" where? Alternatively? What was the first option?! Which PHP script? If it's going to rename the file, again, how can I tell unity to download a file which I don't know its name?!

Clearly I'm not really following how this would work at all. You got a bundle file on the server with its size on its name, but you don't know which version it is and thus what size it is. How can this work?!

avatar image xKroniK13x · Jun 07, 2013 at 03:26 PM 0
Share

You provided it with a URL to make it download in the past, correct? There's no other way than to provide Unity with a URL. It's no different.

avatar image cregox · Jun 07, 2013 at 07:13 PM 0
Share

Ok, now I'm almost sure you were the one not following. But unfortunately, I don't think I can explain. $$anonymous$$aybe if you try it. Get your script and make it work. $$anonymous$$aybe you will see what I meant. It just can't work. Conceptually broken.

The whole point of getting the file size is that we don't know it before hand. So we can't set the URL with the file size in its name if we don't know it!!

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Display Ftp List 1 Answer

Progress when using WWW.LoadFromCacheOrDownload 2 Answers

how to enter another request from www with c# 1 Answer

How to stop a WWW which is in progress? 0 Answers

WWW.texture with a wildcard in the URL 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges