Unity3d hot update

Source: Internet
Author: User
In this era, it is so common that everyone has a deep understanding of what download is. This article only shares and introduces the downloaded code.

 

First, the download system has several missions. First, keep the Client Version library up-to-date. Second, the download should be able to compare and download at least. Third, the download should be as fast as possible.

 

In fact, we did not write a download system, because there are actually few lines of code. Here we will introduce a module that downloads and saves the cache through HTTP, reads the first package from streamingassets, loads resources, and integrates the three functions.
Source code location https://github.com/lightszero/easydown

Keep up to date

To solve the first and second problems, we should try to scatter the downloaded resources. In this way, files can be downloaded in the file unit, and existing local files will not be downloaded. To achieve this goal, we have to determine whether to update a file before downloading it, because traffic is wasted after downloading. You need to know whether a file should be updated. A simple method is to provide a simple feature information for each file, first download the feature information, and then decide whether to download the entire file. Take the feature information of a large file, which is the work of the digest algorithm. Hash, CRC32, MD5, and sha1. Here we select the best sha1 Algorithm for the feature information of our file. First, we need to generate feature information for the files we intend to download. You can download these test files and tool source code from GitHub. Click "check" to display the above information and tell you what has happened to the version and your previous version. Do not delete the generated allver.ver.txt file. It will record the total version. Each check will be based on the previous version and then click Generate version to update all version files.

 

Here we add a group design version generation tool that uses the folder in its own path as the group unit for client download, for easy processing, for example, you can put high-resolution resources and low-resolution resources in two groups respectively. As long as the client simply switches the group name, you can implement resource switching. For example, two groups are generated here. Each group has its own ver file <ignore_js_op>. Let's take a look at the ver file name. The strange thing in the middle is the sha1 feature string, even if the file only changes one byte, the feature strings generated are different. The last step is the file size. In this way, we only need to obtain the ver file and know the size of the file before downloading it. In this way, we have a mechanism to keep the file version up to date. We only need to download the ver file first, and then determine whether the files in each group have changed, how many files have changed, and then download them. Put these test files on an HTTP server, and then proceed to <ignore_js_op>

Client download

How to download the client? For more information, see the code description <ignore_js_op>. The first feature of the code-based resource management system is the download server address. The second parameter is a callback function for the HTTP address of the allver.ver.txt file. Because the initialization Resource System downloads the ver file online, it takes time, therefore, the third parameter to be notified using the callback function is a list <string>, which is used to notify the resource manager of the groups to be checked. You may wonder, how can there be groups that do not check? For example, if our game is to be used on several platforms and some resources are not commonly used, we place them on different platforms so that we will not check resources on other platforms on one platform. Note that resmgr must be updated all the time, because neither download nor load is completed immediately, resmgr must be monitored all the time <ignore_js_op>
Using macros, you can get a special string for each platform and mix them with the group name. Then, you can automatically select a platform-specific group to download the program. The fourth default parameter is the number of concurrent downloads, the default value is 1. to make full use of the download bandwidth, you can change it to 2. Changing more concurrency doesn't make much sense, and the effect of 3 concurrency and 2 concurrency won't be very different. <Ignore_js_op> taskstate is a simple statistical tool provided by resource manager. It is used to obtain several tasks that are being executed and completed. Getneeddownloadres provides an independent notification callback for resources that need to be downloaded and then cyclically downloads and downloads each resource. However, here we demonstrate how to start batch download, it will not be processed separately. Finally, the waitfortaskfinish function will wait until all tasks are completed and then call back to us. This completes the entire download process.

Download progress

For the download progress, we can use taskstate to calculate the number of simple files, or we can calculate the length of each file in the downlist. Demonstrate a simple <ignore_js_op> note that resmgr must be updated all the time, because neither download nor load is completed immediately. resmgr must be monitored all the time.

Load and use

Whether the file is the latest locally or just downloaded, whether it is the first package resource or the resource to be updated, our loading method is the same <ignore_js_op>

090019392251263. PNG (18.53 kb, downloads: 0)

Download the attachment and save it to the album.

Upload

Obtain the corresponding group from verlocal and local version management of resmgr, extract the file from the group, and then call the beginloadxxx method of file. <ignore_js_op> we provide four load interfaces, in fact, one bytes is enough, and all other resources come from bytes. We will talk about it in the loading section. However, considering the common usage, we encapsulate the string texture2d assetbundle. The following other resources must be loaded, and multiple files need to be combined before they can be loaded. We will put these files in the loading article for research. Now you have the most important update module for hot update, and it is completely for free.

Unity3d hot update

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.