- Home /
How can I tell the COMPRESSED size of assets in my streaming web player build?
I'm optimizing my project. The Editor Log shows the compressed size of each scene, but only the uncompressed size of each asset. I want to identify the biggest COMPRESSED assets and optimize THEM!
Answer by Lucas Meijer 1 · Jun 26, 2010 at 12:36 AM
Right now, only manually. as in, make a build with something, then make a build without that something, and then count the difference.
The uncompressed sizes are a decent first step though. usually scripts and dll's compress quite a bit better than textures/models/animations.
Answer by jonas-echterhoff · Jun 28, 2010 at 02:12 PM
Lucas is correct. Also, note that there is technically no way to reliably report compressed sizes of assets so that the sum of those is the total size of the compressed data.
The reason is that all data compression algorithms work by removing redundancy in the data. So, for example, if you had two assets, which are exactly the same, the compressor would be able to compress those better then compressing each individually, because it could basically just store the data once. But then, what would you report as the compressed size of each of them?
Does it really identify identical assets? Do you have any evidence for this?
Answer by Tommynator · Apr 24, 2012 at 09:32 AM
I just had the same problem and fixed it with this little snippet:
private static void GetCompressedFileSize()
{
string path = AssetDatabase.GetAssetPath(Selection.activeObject);
if (!string.IsNullOrEmpty(path))
{
string guid = AssetDatabase.AssetPathToGUID(path);
string p = Path.GetFullPath(Application.dataPath + "../../Library/cache/" + guid.Substring(0, 2) + "/" + guid);
if (File.Exists(p))
{
var file = new FileInfo(p);
Debug.Log("Compressed file size of " + path + ": " + file.Length + " bytes");
}
else
{
Debug.Log("No file found at: " + p);
}
}
}
In Unity 4 change the "cache" section of string p to "metadata"
I don't think that really does it, I got a size LARGER than the original for $$anonymous$$e.
I had some luck with using the metadata folder, and not just the guid, but guid.resource. For audio files, the size of the .resource file seemed to match what is reported in the inspector as the compressed size. e.g.
public static long GetCompressedFileSize(string guid) {
string assetPath = AssetDatabase.GUIDToAssetPath(guid);
if (!string.IsNullOrEmpty(assetPath)) {
string p = Path.GetFullPath(string.Format("{0}../../Library/metadata/{1}/{2}.resource", Application.dataPath, guid.Substring(0, 2), guid));
if (File.Exists(p)) {
return new FileInfo(p).Length;
}
}
return 0;
}