Unity3d hot update book-resource loading (I) starting from assetbundle

Source: Internet
Author: User

Unity3d dynamic resource download. Is there any solution? Yes, assetbundle is a general solution. Any book will spend a lot of time introducing assetbundle.

Let's also talk about assetbundle.

We try to analyze the resource loading mechanism provided by unity3d comprehensively

1. Resources // embedded resources. You can use resources. Load to load any type of resources, which cannot be dynamically modified.

2. streamingassets // use Io or www. Load as the package resource. Www. Load can load any type of resources, Io is limited to bytes and text.

3. Download and load WWW from the network

4. Load assetbundle from the network at www

I and II obviously do not have the hot update effect, so we will not discuss it here.

3 and 4 are all loaded from the network. What are their differences.

First of all, 3. There is no cache. We obviously don't want users to waste traffic repeatedly, which is not desirable.

Then 4, assetbundle provides a version number for cache comparison, which can better serve the update target.

Assetbundle is the solution that unity3d has prepared for us. It is no wonder that every book will introduce assetbundle in a major article, which is also referred to as AB.

Every book tells you that AB is very powerful. AB helps you solve cross-platform problems and solve dependencies.

In this series, we don't want to talk about what others are talking about. We want to tell you some secrets.

Is assetbundle an angel or a devil?

First of all, AB is really good and powerful. It can store all the resources of unity, including textures, materials, shader, and presets.

Then we can support each platform. This is the first trap. Note that each platform supports not multiple platforms.

Each platform needs to be exported separately. What is the difference between each platform? The answer is "nothing.

So why should each platform export data separately? Considering the quality relationship of each platform, unity makes quality-related differences.

The biggest quality difference comes from textures.

Some platform textures are not compressed, and some platform textures need to be compressed. Different compression algorithms are applied based on different platform features, which are compressed before being saved in the package.

This is what AB does for you.

It sounds very considerate. Wait, do you forget a specific proposition called UI.

The compressed image may cause quality loss. We usually do not compress the UI texture.

Then the UI will touch another problem of AB.

Taking ngui as an example, the resource relationships of ngui are complex, with textures-gallery-Layout

Different la s often cross-reference textures

If AB is used to separate and package each interface to provide users with a minimum amount of resource updates, this task can be described as a disaster.

The things pushed by hot updates are in file units, while the use of AB in the case of small-granularity files with complicated reference relationships is a disaster.

AB's differential compilation on each platform is not optional, but mandatory. If you have three platforms, web, IOS, and Android, You have to export them three times in any case.

What should we do without assetbundle?

Download the part file and assemble it.

It is completely feasible for the UI situation. Save the layout and gallery as text, download the text and textures, and assemble them.

For other scene clips, AB is still the only choice when animations and textures need to be compressed.

Unity does not provide a method to compress textures at runtime, and animations are not easy to access. It can only compress dxt at runtime, and only supports PC and WP8.

Is loading various resources messy? No.

In essence, it can be processed in bytes.

Texture can be loaded from bytes

Strings can be loaded from bytes.

AB can be loaded from bytes

Custom binary storage is bytes.

Therefore, as long as our download system provides the download of bytes and caches it, all the resources will be loaded from bytes.

The download section is introduced in another topic.

The next section describes how to save the UI layout to a file and restore it.

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.