using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace UnityEditor.AddressableAssets.Build.Layout
{
///
/// A storage class used to gather data about an Addressable build.
///
[Serializable]
public class BuildLayout
{
///
/// Information about the AssetBundleObject
///
[Serializable]
public class AssetBundleObjectInfo
{
///
/// The size, in bytes, of the AssetBundleObject
///
public ulong Size;
}
///
/// Data about the AddressableAssetGroup that gets processed during a build.
///
[Serializable]
public class Group
{
///
/// The Name of the AdressableAssetGroup
///
public string Name;
///
/// The Guid of the AddressableAssetGroup
///
public string Guid;
///
/// The packing mode as defined by the BundledAssetGroupSchema on the AddressableAssetGroup
///
public string PackingMode;
///
/// A list of the AssetBundles associated with the Group
///
[SerializeReference]
public List Bundles = new List();
///
/// Data about the AddressableAssetGroupSchemas associated with the Group
///
[SerializeReference]
public List Schemas = new List();
}
///
/// Data container for AddressableAssetGroupSchemas
///
[Serializable]
public class SchemaData
{
///
/// The Guid of the AddressableAssetGroupSchema
///
public string Guid;
///
/// The class type of the AddressableAssetGroupSchema
///
public string Type;
///
/// These key-value-pairs include data about the AddressableAssetGroupSchema, such as PackingMode and Compression.
///
[SerializeReference]
public List> KvpDetails = new List>();
}
///
/// Data store for AssetBundle information.
///
[Serializable]
public class Bundle
{
///
/// The name of the AssetBundle
///
public string Name;
///
/// The file size of the AssetBundle on disk, in bytes
///
public ulong FileSize;
///
/// The Compression method used for the AssetBundle.
///
public string Compression;
///
/// A reference to the Group data that this AssetBundle was generated from
///
[SerializeReference]
public Group Group;
///
/// List of the Files referenced by the AssetBundle
///
[SerializeReference]
public List Files = new List();
///
/// A list of the direct dependencies of the AssetBundle
///
[SerializeReference]
public List Dependencies;
///
/// The full dependency list, flattened into a list
///
[SerializeReference]
public List ExpandedDependencies;
}
///
/// Data store for resource files generated by the build pipeline and referenced by a main File
///
[Serializable]
public class SubFile
{
///
/// The name of the sub-file
///
public string Name;
///
/// If the main File is a serialized file, this will be true.
///
public bool IsSerializedFile;
///
/// The size of the sub-file, in bytes
///
public ulong Size;
}
///
/// Data store for the main File created for the AssetBundle
///
[Serializable]
public class File
{
///
/// The name of the File.
///
public string Name;
///
/// The AssetBundle data that relates to a built file.
///
[SerializeReference]
public Bundle Bundle;
///
/// List of the resource files created by the build pipeline that a File references
///
[SerializeReference]
public List SubFiles = new List();
///
/// A list of the explicit asset defined in the AssetBundle
///
[SerializeReference]
public List Assets = new List();
///
/// A list of implicit assets built into the AssetBundle, typically through references by Assets that are explicitly defined.
///
[SerializeReference]
public List OtherAssets = new List();
///
/// The final filename of the AssetBundle file
///
public string WriteResultFilename;
///
/// Data about the AssetBundleObject
///
public AssetBundleObjectInfo BundleObjectInfo;
///
/// The size of the data that needs to be preloaded for this File.
///
public int PreloadInfoSize;
///
/// The number of Mono scripts referenced by the File
///
public int MonoScriptCount;
///
/// The size of the Mono scripts referenced by the File
///
public ulong MonoScriptSize;
}
///
/// Data store for Assets explicitly defined in an AssetBundle
///
[Serializable]
public class ExplicitAsset
{
///
/// The Asset Guid.
///
public string Guid;
///
/// The Asset path on disk
///
public string AssetPath;
///
/// The Addressable address defined in the Addressable Group window for an Asset.
///
public string AddressableName;
///
/// The size of the file on disk.
///
public ulong SerializedSize;
///
/// The size of the streamed Asset.
///
public ulong StreamedSize;
///
/// The file that the Asset was added to
///
[SerializeReference]
public File File;
///
/// List of data from other Assets referenced by an Asset in the File
///
[SerializeReference]
public List InternalReferencedOtherAssets = new List();
///
/// List of explicit Assets in the File
///
[SerializeReference]
public List InternalReferencedExplicitAssets = new List();
///
/// List of Assets referenced by the File, but not included in the File.
///
[SerializeReference]
public List ExternallyReferencedAssets = new List();
}
///
/// Data store for implicit Asset references
///
[Serializable]
public class DataFromOtherAsset
{
///
/// The Guid of the Asset
///
public string AssetGuid;
///
/// The Asset path on disk
///
public string AssetPath;
///
/// A list of Assets that reference this data
///
[SerializeReference]
public List ReferencingAssets = new List();
///
/// The number of Objects in the data
///
public int ObjectCount;
///
/// The size of the data on disk
///
public ulong SerializedSize;
///
/// The size of the streamed data
///
public ulong StreamedSize;
}
///
/// The Addressable Groups that reference this data
///
[SerializeReference]
public List Groups = new List();
///
/// List of AssetBundles this data was built into
///
[SerializeReference]
public List BuiltInBundles = new List();
}
///
/// Utility used to quickly reference data built with the build pipeline
///
public class LayoutLookupTables
{
///
/// The AssetBundle name to the Bundle data map.
///
public Dictionary Bundles = new Dictionary();
///
/// File name to File data map.
///
public Dictionary Files = new Dictionary();
///
/// Guid to ExplicitAsset data map.
///
public Dictionary GuidToExplicitAsset = new Dictionary();
///
/// Group name to Group data map.
///
public Dictionary GroupLookup = new Dictionary();
}
///
/// Helper methods for gathering data about a build layout.
///
public class BuildLayoutHelpers
{
///
/// Gather a list of Explicit Assets defined in a BuildLayout
///
/// The BuildLayout generated during a build
/// A list of ExplicitAsset data.
public static IEnumerable EnumerateAssets(BuildLayout layout)
{
return EnumerateBundles(layout).SelectMany(b => b.Files).SelectMany(f => f.Assets);
}
///
/// Gather a list of Explicit Assets defined in a Bundle
///
/// The Bundle data generated during a build
/// A list of ExplicitAssets defined in the Bundle
public static IEnumerable EnumerateAssets(BuildLayout.Bundle bundle)
{
return bundle.Files.SelectMany(f => f.Assets);
}
///
/// Gather a list of Bundle data defined in a BuildLayout
///
/// The BuildLayout generated during a build
/// A list of the Bundle data defined in a BuildLayout
public static IEnumerable EnumerateBundles(BuildLayout layout)
{
foreach (BuildLayout.Bundle b in layout.BuiltInBundles)
yield return b;
foreach (BuildLayout.Bundle b in layout.Groups.SelectMany(g => g.Bundles))
yield return b;
}
///
/// Gather a list of File data defined in a BuildLayout
///
/// The BuildLayout generated during a build
/// A list of File data
public static IEnumerable EnumerateFiles(BuildLayout layout)
{
return EnumerateBundles(layout).SelectMany(b => b.Files);
}
}
}