Unity Export iOS Project how to reduce running memory, installation package (IPA), and post-installation size

Source: Internet
Author: User
Tags transparent color disk usage
Unity Export iOS Project how to reduce running memory, installation package (IPA), and post-installation size (introduction)

Recently, the project encountered some problems, because the project has more color picture material, size is also relatively large, the producer does not accept the compression of the image quality is obviously reduced. This led to unity exporting to iOS devices on several issues.

1, running memory is too large, in the lower version of the iphone4s,ipad2 and other 512m old machine machines, when loading too many resources, easy to cause memory overflow, resulting in application flash.

2, Unity export of iOS project is too large, Xcode compiled IPA package is OK, but installed to iOS devices on the big outrageous. For example, 60m IPA, installed on the device is actually 700M.

3, is the IPA export package is large. The requirement is to minimize the left and right size of the resource +unity (seven or eight trillion).

The above questions, 1, 2 belong to more serious problem. 3 belong to further optimization problems.

We have adopted a series of solutions to the above problems, the following is a brief description of the solution, please correct me.

One, reduce the program running memory, better compatible with low memory machine

Program memory consumption is too large, resulting in memory overflow, most of the resources because of a one-time load too much, or not in time to clean up, the source is too large resources.

1, first of all, the problem of too much resources:

Audio: We can use OGG format as far as possible, low sampling rate of audio instead of WAV, MP3 and other high sampling rate audio. Low sampling rate also represents low audio quality, you can use audio conversion software to adjust the audio to acceptable quality.

Picture: If you need higher quality, you can use JPG format, if the quality is not too many requirements, you can save the web format. If there is a transparent color, then only PNG.

Here recommend a picture compression site, basically processing, his compression rate will reach more than 50%, and can not see too much distortion.

https://tinypng.com/


2, secondly, when we import resources into unity, unity will do some special processing of resources, such as pictures in the Web platform, the default will use texture, compressed compression. At this point, almost all of the PNG images in JPG format, or roughly 2 of the N-time side, can be compressed.


Before, we for the picture effect perfect, has been using: GUI, truecolor format picture, this really on the equipment screen performance is very good.

But this leads to a problem, a picture that originally had only 87k of size, which is rendered 4m size when used with this setting.


When you run a program, it occupies 4m of memory, not 87k. Especially in our project, an interface has many of these high-quality images, plus a lot of sequence frame animation, and the animation leaflet is larger, the number of frames is still more. That memory occupy is very terrible. Our low configuration machine is just 512 RAM, if the resource manager is not properly written. The odds of that collapse are really great.

So we experimented with several different picture formats, and on iOS devices, PVRTC 4bit images in this format are relatively low in memory footprint and not very distorted. Do not recommend the pursuit of the ultimate image quality, but consumes a lot of memory.


3, then we use dynamic resource loading.

Package a series of resources (the preset of the diagram, Atlas) into Assetbundle and place them under the read-only directory Streamingassets folder.

When this resource is used, it is loaded into memory using WWW to read local resources.

Then immediately uninstall the mirror.

This object is destroyed when the resource is no longer in use.

However, the actual test on the real iOS device memory monitoring is not immediately reduced, so this scenario if the resource needs more, can not all add in. Instead, it needs to be loaded in batches according to need.

In addition, it is necessary to call the system function resources.unloadunusedassets () frequently in the scene switching process, to clean up the free unused resources. To ensure memory recovery.

4, resource packaging no longer described in detail here. The following details can be consulted:

http://www.xuanyusong.com/archives/2405

Note that when writing scripts individually, note the last package parameters. Resources from different platforms are not common.

On Android:

Buildpipeline.buildassetbundle (obj, null, targetpath,buildassetbundleoptions.collectdependencies, buildtarget.android)

On iOS:

Buildpipeline.buildassetbundle (obj, null, targetpath,buildassetbundleoptions.collectdependencies, Buildtarget.iphone)

In addition, the computer and mobile phone on the assetbundle can not be mixed, different platforms can only use their own.

5, in fact, the impact of resource packaging for memory optimization is not very large. The most influential is the format and amount of resources used. and the management of resource usage.

However, there are many benefits to packaging resources. is: 1, the resources of the encryption is better; 2, can greatly reduce the amount of installed to the phone. 3, loading, destruction more clear, controllable better. 4, the load is not completed can be used loading interface to cover, to prevent the interface to flash black screen conversion.

Second, the IPA package after the export installed to the real machine occupy huge space

1, our project at the beginning, and not how many resource division to play into the form of assetbundle. At least the scene, sequence frame animation did not play at the beginning.

Then came the question:

1, we compile the Xcode project in Windows, we found that there are more than 700 m, feel very strange, check, there is a data folder is relatively large.

2, the entire project into a ZIP compression package is only 100m

3, and then on the Mac compiled the project incredibly again reach 700m

4, produced the IPA document is not too big, 60m or so

5, but installed to the real machine, the amount of software is very large, about 700 m


2, in response to this problem we found that the main resource folder under the Resourcedata, and then after the investigation, because of the picture inside the problem.

3, in order to ensure high-quality pictures, whether JPG or PNG, we have adopted the GUI, truecolor settings.

In the above experiment, 87k size of the file, is rendered into 4m around the size of resources.

We found through decompression, after compiling the installation, the iOS did not do very good compression and support, but the image directly converted to the TGA format storage. This leads to a huge amount of consumption.

4, that is to say: The runtime he occupies 4m memory

He also occupies 4m of hard disk usage during installation

5, for this, we first convert the picture format to the above iOS support better PVRTC 4bit form.

But this format also has its drawbacks, that is, you need to look at what can be compressed, those cannot be compressed. By experiment, nearly 2 of the n-th square of the approximate square picture or Atlas can be compressed, but not the image deformation. After this treatment, we initially reduced the dosage to 300m.

6, then we found that only the resource packaging is not enough, the rest of the interface, scenes and other presets above also associated with a lot of pictures and Atlas. If the scene is not packaged, then there will be a lot of dosage. So we packed the scene further. In addition to the camera preset, pack all. In this way our dosage has been completely lowered down, about 80m more.

7, this approach does not apply to initial development, because each time you modify the preset or adjust the interface, to repackage. and modify the Resource directory. Really laborious.

8, in the experiment, also found. The preset, picture package, can not still be placed in the resource directory, or even if you no longer quote, he can still be compiled into the project, so that will not reduce the final output of the project.

 

Related Article

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.