A <十二> discussion on the hot update strategy of hand Tour resources in Unity Hand Tour

Source: Internet
Author: User
Tags md5

The last time we learned how to package resources. This time we can use the game, and we'll explore the incremental update strategy for a hands-on resource. Note Oh, just resources oh. For updates to the code, we'll look at it later. Theoretically, this scheme can be updated with a variety of static resources, not just assetbundle packaged.

(Reproduced please specify the original address http://blog.csdn.net/janeky/article/details/17666409)principleThere are several ways to install the hands now. One is to install programs and resources locally when you install them. The other is to install only the program and a small amount of necessary resources, and then at the start of the time to download the missing resources complete. Hand tours are generally not recommended as with traditional page tours, loading resources during the run, which can lead to poor user experience. The two installation modes above are essentially the same in updating resources. are both the version of the comparison server resource and the version of the local resource to determine which resources to download (including those that need to be updated and new).
Practice1. Resource packaging.
Before resources are packaged, you need to plan the interdependencies between resources. Extract some common things and minimize unnecessary coupling. Some of the better practices are that all objects are made as prefab as possible, the fewer things in the scene, the better, "Everything is dynamically loaded".
2. Generate File MD5
The MD5 of the document is not described in detail here. You can simply understand it as a status tag for a file. If the file changes, then its MD5 must be changed, the simple move file is not changed. MD5 authentication can also act as a security verification to ensure that local files are not tampered with. For example, we often download the software from the Internet, usually give a MD5 value, you downloaded, compare the downloaded file MD5 value, you can know that the file has not been tampered with. When the release is released, we need to calculate the MD5 value for all packaged files and then save them in a configuration file. On this part of the work, I have previously written a visual gadget (Https://github.com/kenro/File_Md5_Generator) and now share it with everyone. If you feel useful, remember to hit the stars Oh:)
3. Version comparison
Load the local version.txt first, and cache the results. Download the server's version.txt, compare it to the local version, and filter out the resources that need to be updated and added
4. Download Resources
Download the updated resource in turn, or replace it if the local already has an old resource, or save the new

5. Update the local version configuration file Version.txt

Replace the local version.txt with the version.txt of the server. This is done to ensure that the update will not be repeated the next time it is started.

6. Load the Assetbundle locally to test the display.

Here a model is made prefab, packaged into Assetbundle. After the program is loaded locally, it is displayed in the scene 7. Update the assetbundle of the server to regenerate the version number file.

8. Repeat the 6 steps

We can verify that our program does not have any changes and the resources have been updated. The latest model is already shown in the scene.

On the above process, I wrote a demo demo with a small presentation. Instead of using a Web server, I use another local folder as the resource server directory. The directories here are tested only for versions under Windows. If you want to be on the phone platform, you need to remember to update the relevant path.[CSharp]  View plain copy using unityengine;   using system.collections;   using  system.collections.generic;   using system.text;   using system.io;      public class resupdate : monobehaviour   {        public static readonly string VERSION_FILE =  "Version.txt";        public static readonly string LOCAL_RES_URL =  " file://" + Application.dataPath + "/res/";       public  static readonly string server_res_url =  "file:///C:/Res/";        public static readonly string local_res_path = application.datapath  +  "/res/";          private Dictionary<string,  String>&nbSp localresversion;       private Dictionary<string, string>  serverresversion;       private List<string> NeedDownFiles;        private bool NeedUpdateLocalVersionFile = false;          void start ()        {            //initialization             Localresversion = new dictionary<string, string> ();            ServerResVersion = new Dictionary<string, string> ();            needdownfiles = new list<string > ();              //load local version configuration             startcoroutine (DownLoad (local_res_url + version_file,  Delegate (www localversion)            {                //Save local version                parseversionfile (localversion.text, localresversion );               //Load server-side version configuration    

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.