Here is some tips to reduce your Unity build for any platform. Be smart, and adapted these advices to your project.
Graphics
Textures are what usually takes up the most space and performance. Take good care with your artist, like with your smart cats.
Any platform
- Absolutely having textures under 2^n resolution. Otherwise, no compression and performance will be impacted
- Set in Unity Inspector the adapted maximum size for each texture.
- Be smart, If your texture is applied to a small surface, having a 56*56 is probably enough
- Be careful when using Atlas. Unmanaged, they are often half empty and take lots of space and performance for nothing
- Avoid Alpha, prefer the GrayScale option from Unity
- Choose Sprite rather than textures (for performance)
- Avoid sprite sheets or multiple similar sprite and replace them by code/animations. (keep one sprite button and add text animated “3”, “2”, “1”, “BOOM!”)
- Disable the Generate Mipmaps if not used (UI, objects that are not moving far away from your screen, …)
- Enable crunch compression. This will add lots of time to load your project afterward. Think of doing it just before you build or even in a build script
Android
- Select ETC1 compression mode during the build
General
Any platform
- Filter your Resources and Plugins directories. Unity will include everything from these folders when building, even unused assets
- Enable compression on Meshes and Audio files. Be careful though, compressed mesh can greatly change the appearance of the model
- Cut audio tracks (empty parts, loops,…)
- More complicated, but nevertheless useful: use Proguard to strip the library and obfuscate the code at the same time (http://forum.unity3d.com/threads/use-proguard-with-unity.318660/#post-2076904)
Android
- Limit the compilation within the Player Settings to ARMv7 architecture and drop the x86. Few Android Smartphone runs on x86 processors and it adds about +6MB to the project
- Unpack and repack the APK with a good compression tool (like 7-zip ultra mode). Don’t forget to perform a zipalign after compression
iOS
- Adjust the stripping maximum level (mscore lib) within the Player settings
Tools
More over the Unity forum post
To know what is taking the most of your package space, and more information, check the Unity post here: https://docs.unity3d.com/Manual/ReducingFilesize.html
Sample code to add a menu item that reimport all textures with a default settings
using UnityEngine;
using UnityEditor;
public class ImportSettings : MonoBehaviour
{
[MenuItem("Reimport/Reimport Textures with Defaults")]
static void ReimportTexture()
{
foreach(var p in AssetDatabase.GetAllAssetPaths())
{
TextureImporter i = AssetImporter.GetAtPath(p) as TextureImporter;
if (i == null)
continue;
i.maxTextureSize = 64;
i.compressionQuality = (int)TextureCompressionQuality.Normal;
i.crunchedCompression = false;
i.npotScale = TextureImporterNPOTScale.ToSmaller;
i.SaveAndReimport();
}
}
}
Laisser un commentaire