//private BuildArtifactsInfo(SizePair totalSize, long streamingAssetsSize, List<SizePair> scenes, Dictionary<string, SizePair> modules) //{ //} public static BuildArtifactsInfo Create(BuildTarget buildTarget, string buildPath, string standaloneWinDataDirectoryOverride = null) { switch (buildTarget) { case BuildTarget.StandaloneWindows: case BuildTarget.StandaloneWindows64: return(CreateForStandaloneWin(buildPath, standaloneWinDataDirectoryOverride)); case BuildTarget.Android: return(CreateForAndroid(buildPath, PlayerSettings.Android.useAPKExpansionFiles)); case UnityVersionAgnostic.iOSBuildTarget: return(CreateForIOS(buildPath)); #if !UNITY_4_7 case BuildTarget.WebGL: return(CreateForWebGL(buildPath)); #endif default: if (UnityVersionAgnostic.IsOSXBuildTarget(buildTarget)) { return(CreateForStandaloneMac(buildPath)); } throw new NotSupportedException(); } }
public bool BeginWaitIfBusy(UnityEngine.Object asset, Action <long> onCompleted) { if (asset is Texture2D) { if (!UnityVersionAgnostic.IsGetRawTextureDataSupported) { return(false); } var textureData = UnityVersionAgnostic.GetRawTextureData((Texture2D)asset); if (textureData != null && textureData.Length > 0) { return(RunInBackground(() => { using (var ms = new MemoryStream()) { using (var ds = new DeflateStream(ms, CompressionMode.Compress, true)) { ds.Write(textureData, 0, textureData.Length); } onCompleted(ms.Length); } })); } } return(false); }
private static IEnumerable<AssetInfo> GetAtlasAssetPages(AssetInfo atlasInfo, BuildInfoAssetDetailsCollector collector) { // add dependencies to atlas textures manually var atlas = AssetDatabase.LoadMainAssetAtPath(atlasInfo.path); if (atlas) { var tag = UnityVersionAgnostic.GetSpriteAtlasTag(atlas); var previewTextures = UnityVersionAgnostic.LoadSpriteAtlasTextues(atlas); if (previewTextures != null && tag != null) { int pageNo = 0; foreach (var texture in previewTextures) { var textureInfo = new AssetInfo() { path = "Sprite Atlas " + tag + " [" + (pageNo + 1) + " of " + previewTextures.Length + "]", spritePackerPage = pageNo, spritePackerTag = tag, size = GetStorageMemorySize(texture), scenes = atlasInfo.scenes.ToList(), }; if (collector != null) { Log.Debug("Collecting details for asset: {0}", textureInfo.path); List<AssetProperty> details = new List<AssetProperty>(); collector.CollectForAsset(details, texture, textureInfo.path); textureInfo.details = details.ToArray(); } yield return textureInfo; ++pageNo; } } else { Log.Warning("No textures found for atlas {0}", atlas); } } }
private static BuildArtifactsInfo CreateForWebGL(string buildPath) { var compressedSize = GetDirectorySizeNoThrow(buildPath); var totalSize = compressedSize; var streamingAssetsSize = GetDirectorySizeNoThrow(ReliablePath.Combine(buildPath, "StreamingAssets")); var latestReport = UnityVersionAgnostic.GetLatestBuildReport(); if (latestReport == null) { throw new System.InvalidOperationException("Unable to retreive native Unity report"); } var prop = new SerializedObject(latestReport).FindPropertyOrThrow("m_Files"); var scenes = new List <SizePair>(); var modules = new Dictionary <string, SizePair>(); for (int propIdx = 0; propIdx < prop.arraySize; ++propIdx) { var elem = prop.GetArrayElementAtIndex(propIdx); var role = elem.FindPropertyRelativeOrThrow("role").stringValue; if (role == "Scene") { var path = elem.FindPropertyRelativeOrThrow("path").stringValue; var prefix = "level"; var lastIndex = path.LastIndexOf(prefix); if (lastIndex < 0) { Log.Warning("Unexpected level path: " + path); continue; } var levelNumberStr = path.Substring(lastIndex + prefix.Length); var levelNumber = int.Parse(levelNumberStr); // pad with zeros for (int i = scenes.Count; i <= levelNumber; ++i) { scenes.Add(0); } var s = elem.FindPropertyRelative("totalSize").longValue; scenes[levelNumber] = new SizePair(s, s); } else if (role == "DependentManagedLibrary" || role == "ManagedLibrary") { var path = elem.FindPropertyRelativeOrThrow("path").stringValue; var prefix = "/Managed/"; var lastIndex = path.LastIndexOf(prefix); if (lastIndex < 0) { Log.Warning("Unexpected module path: " + path); continue; } var moduleName = path.Substring(lastIndex + prefix.Length); var s = elem.FindPropertyRelative("totalSize").longValue; modules.Add(moduleName, new SizePair(0, s)); } } // try to run 7z to get actual data size var releaseDir = ReliablePath.Combine(buildPath, "Release"); if (Directory.Exists(releaseDir)) { var buildName = buildPath.Split(new[] { "/", "\\" }, StringSplitOptions.RemoveEmptyEntries).Last(); var zipPath = ReliablePath.Combine(releaseDir, buildName + ".datagz"); var uncompressedSize = Get7ZipArchiveUncompressedSize(zipPath); if (uncompressedSize >= 0) { totalSize += uncompressedSize; totalSize -= GetFileSizeNoThrow(zipPath); } } else { var buildDir = ReliablePath.Combine(buildPath, "Build"); if (Directory.Exists(buildDir)) { foreach (var compressedFile in Directory.GetFiles(buildDir, "*.unityweb")) { var uncompressedSize = Get7ZipArchiveUncompressedSize(compressedFile); if (uncompressedSize >= 0) { totalSize += uncompressedSize; totalSize -= GetFileSizeNoThrow(compressedFile); } } } } return(new BuildArtifactsInfo() { totalSize = new SizePair(compressedSize, totalSize), streamingAssetsSize = streamingAssetsSize, sceneSizes = scenes, managedModules = modules, }); }