using System.Collections.Generic;
namespace UnityEditor.AddressableAssets.Build.Layout
{
///
/// Data store for summary data about build content
///
public struct AssetSummary
{
///
/// Type of Asset
///
public AssetType AssetType;
///
/// Number of Objects build of the defined AssetType
///
public int Count;
///
/// Total size of combined Objects
///
public ulong SizeInBytes;
internal void Append(AssetSummary other)
{
Count += other.Count;
SizeInBytes += other.SizeInBytes;
}
}
///
/// Data store for summary data about Bundle content
///
public struct BundleSummary
{
///
/// Number of bundles built
///
public int Count;
///
/// Size in bytes of bundles uncompressed
///
public ulong TotalUncompressedSize;
///
/// Size in bytes of bundled compressed
///
public ulong TotalCompressedSize;
}
///
/// Data store for Addressables build
///
public class BuildLayoutSummary
{
///
/// Summary of bundles
///
public BundleSummary BundleSummary = new BundleSummary();
///
/// Summary for AssetTypes used
///
public List AssetSummaries = new List();
///
/// The total number of assets in a build, including implicit assets
///
internal int TotalAssetCount = 0;
///
/// The total number of explicitly added Addressable assets that were included in a build
///
internal int ExplicitAssetCount = 0;
///
/// The total number of implicitly added assets that were included in a build
///
internal int ImplicitAssetCount = 0;
///
/// Generates a summary of the content used in a BuildLayout
///
/// BuildLayout to get a summary for
/// Summary of the BuildLayout layout
public static BuildLayoutSummary GetSummary(BuildLayout layout)
{
BuildLayoutSummary summary = new BuildLayoutSummary();
Dictionary sizes = new Dictionary();
foreach (var group in layout.Groups)
{
foreach (var bundle in group.Bundles)
{
summary.BundleSummary.TotalCompressedSize += bundle.FileSize;
summary.BundleSummary.TotalUncompressedSize += bundle.UncompressedFileSize;
summary.BundleSummary.Count++;
foreach (var file in bundle.Files)
{
summary.TotalAssetCount += file.Assets.Count + file.OtherAssets.Count;
summary.ExplicitAssetCount += file.Assets.Count;
summary.ImplicitAssetCount += file.OtherAssets.Count;
foreach (var asset in file.Assets)
AppendObjectsToSummary(asset.MainAssetType, asset.SerializedSize + asset.StreamedSize, asset.Objects, summary.AssetSummaries);
foreach (var asset in file.OtherAssets)
AppendObjectsToSummary(asset.MainAssetType, asset.SerializedSize + asset.StreamedSize, asset.Objects, summary.AssetSummaries);
}
}
}
return summary;
}
///
/// Generates a summary of the content used in a BuildLayout, minus the asset type data.
///
///
///
internal static BuildLayoutSummary GetSummaryWithoutAssetTypes(BuildLayout layout)
{
BuildLayoutSummary summary = new BuildLayoutSummary();
foreach (var group in layout.Groups)
{
foreach (var bundle in group.Bundles)
{
summary.BundleSummary.TotalCompressedSize += bundle.FileSize;
summary.BundleSummary.TotalUncompressedSize += bundle.UncompressedFileSize;
summary.BundleSummary.Count++;
foreach (var file in bundle.Files)
{
summary.TotalAssetCount += file.Assets.Count + file.OtherAssets.Count;
summary.ExplicitAssetCount += file.Assets.Count;
summary.ImplicitAssetCount += file.OtherAssets.Count;
}
}
}
return summary;
}
private static void AppendObjectsToSummary(AssetType mainAssetType, ulong overallSize, List subObjects, List assetSummariesOut)
{
// for Scene Assets take the accumulation of Objects for overall Scene size
if (mainAssetType == AssetType.Scene)
AddObjectToSummary(AssetType.Scene, overallSize, assetSummariesOut);
// for prefabs accumulate general objects like GameObject and Transform as Prefab
else if (mainAssetType == AssetType.Prefab || mainAssetType == AssetType.Model)
{
ulong serializedSize = 0;
ulong streamedSize = 0;
ulong size = 0;
foreach (var objectData in subObjects)
{
if (objectData.AssetType == AssetType.Other ||
objectData.AssetType == AssetType.GameObject ||
objectData.AssetType == AssetType.Component ||
objectData.AssetType == AssetType.MonoBehaviour )
{
serializedSize += objectData.SerializedSize;
streamedSize += objectData.StreamedSize;
}
else
{
AddObjectToSummary(objectData.AssetType, objectData.SerializedSize + objectData.StreamedSize, assetSummariesOut);
}
}
size = serializedSize + streamedSize;
if (size > 0)
AddObjectToSummary(AssetType.Prefab, size, assetSummariesOut);
}
else
{
foreach (BuildLayout.ObjectData objectData in subObjects)
{
AddObjectToSummary(objectData.AssetType, objectData.SerializedSize + objectData.StreamedSize, assetSummariesOut);
}
}
}
private static void AddObjectToSummary(AssetType assetType, ulong size, List assetSummaries)
{
AssetSummary summary = new AssetSummary()
{
AssetType = assetType,
Count = 1,
SizeInBytes = size
};
for(int i=0; i