Unity3d in the development of Android Http pit (spit Groove

Source: Internet
Author: User

In the General U3D network development, the direct use of the WWW class is enough normal use, but I found that using www download large files, will cause the whole process of the situation (not clear whether I personal computer problems), so simply use Httpwebrequest/httpwebresponse + Await/async to replace www.

U3d is still used in the lower mono version, so it is not supported (Await/async). Task<t> is not supported accurately, and there are some bugs (I can be sure of two), now most hope is the U3d update mono version, write code can be more cool!

Helpless, only the reference asyncenumerator and u3d itself coroutine to achieve a self-contained coroutine library, tested in the PC, and found that sometimes asynchronous read may occur without (back) call AsyncCallback, There was something wrong with the computer, and nothing happened after the restart.

The build cheer Android version is put on the phone and tested ... It's blown! At this point, the first step I think of is u3d under the HttpWebRequest and so on Android? Because it is reasonable to say that if the build succeeds, it should be supported, so a new clean project is created that contains only HTTP -related.

Put it in again:webexception! Output information is a bunch of English, in view of my limited English level and information can not be copied, so immediately abandoned the internet to find the reason for the idea. I guess the app doesn't have access to the network (I didn't look at it during the installation).

Therefore, add another script that tests the native WWW: (to prove that it is not my Code problem (escape)

 Public classDownloadwww:monobehaviour {//Use this for initialization    voidStart () {Startcoroutine (Download ()); } IEnumerator Download () {www www=NewWWW ("http://cn.bing.com"); yield returnwww; foreach(varHinchwww.responseHeaders) T+ = H.key +"  "+ H.value +"\ n"; T+=Www.text; }    stringT; intC; voidOngui () {Guilayout.button (c++ +"   ! "+t); }}

Continue to build on the phone, this installation I can slowly see clearly: The application needs new permissions-network access. If so, after the addition of the WWW, even the original code can run normally.

guess again, yes, I am not a qualified programmer, I do not want to verify:

Application access is increased only if the script is found to be using a class such as www or networkxxx when u3d compiles the code, otherwise the network cannot be accessed even if you use only HttpWebRequest or a socket.
Of course, you can also increase the network permissions on Android itself.

Finally: Although the title of this article is written in the groove, and I would like to Turkey to write good articles, but found that the level of writing to decline in the primary level, when and as a journal to see.

Unity3d in the development of Android Http pit (spit Groove

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.