using System; using System.Collections.Generic; using UnityEditor.Build.Pipeline.Interfaces; using UnityEditor.Build.Pipeline.Utilities; namespace UnityEditor.Build.Pipeline { /// /// Basic implementation of IBuildContent. Stores the list of Assets to feed the Scriptable Build Pipeline. /// /// [Serializable] public class BuildContent : IBuildContent { /// public List Assets { get; private set; } /// public List Scenes { get; private set; } internal BuildContent() { } /// /// Default constructor, takes a set of Assets and converts them to the appropriate properties. /// /// The set of Assets identified by GUID to ensure are packaged with the build public BuildContent(IEnumerable assets) { if (assets == null) throw new ArgumentNullException("assets"); Assets = new List(); Scenes = new List(); foreach (var asset in assets) { ValidationMethods.Status assetType = ValidationMethods.ValidAsset(asset); if (assetType == ValidationMethods.Status.Asset) Assets.Add(asset); else if (assetType == ValidationMethods.Status.Scene) Scenes.Add(asset); else throw new ArgumentException(string.Format("Asset '{0}' is not a valid Asset or Scene.", asset.ToString())); } } } /// /// Basic implementation of IBundleBuildContent. Stores the list of Assets with explicit Asset Bundle layout to feed the Scriptable Build Pipeline. /// /// [Serializable] public class BundleBuildContent : IBundleBuildContent { /// public List Assets { get; private set; } /// public List Scenes { get; private set; } /// public Dictionary Addresses { get; private set; } /// public Dictionary> BundleLayout { get; private set; } internal BundleBuildContent() { } /// /// Default constructor, takes a set of AssetBundleBuild and converts them to the appropriate properties. /// /// The set of AssetbundleBuild to be built. public BundleBuildContent(IEnumerable bundleBuilds) { if (bundleBuilds == null) throw new ArgumentNullException("bundleBuilds"); Assets = new List(); Scenes = new List(); Addresses = new Dictionary(); BundleLayout = new Dictionary>(); foreach (var bundleBuild in bundleBuilds) { List guids; BundleLayout.GetOrAdd(bundleBuild.assetBundleName, out guids); ValidationMethods.Status bundleType = ValidationMethods.Status.Invalid; for (int i = 0; i < bundleBuild.assetNames.Length; i++) { string assetPath = bundleBuild.assetNames[i]; GUID asset = new GUID(AssetDatabase.AssetPathToGUID(assetPath)); // Ensure the path is valid ValidationMethods.Status status = ValidationMethods.ValidAsset(asset); if (status == ValidationMethods.Status.Invalid) throw new ArgumentException(string.Format("Asset '{0}' is not a valid Asset or Scene.", assetPath)); // Ensure we do not have a mixed bundle if (bundleType == ValidationMethods.Status.Invalid) bundleType = status; else if (bundleType != status) throw new ArgumentException(string.Format("Asset Bundle '{0}' is invalid because it contains mixed Asset and Scene types.", bundleBuild.assetBundleName)); string address = bundleBuild.addressableNames != null && i < bundleBuild.addressableNames.Length && !string.IsNullOrEmpty(bundleBuild.addressableNames[i]) ? bundleBuild.addressableNames[i] : AssetDatabase.GUIDToAssetPath(asset.ToString()); // Add the guid to the bundle map guids.Add(asset); // Add the guid & address Addresses.Add(asset, address); // Add the asset to the correct collection if (status == ValidationMethods.Status.Asset) Assets.Add(asset); else if (status == ValidationMethods.Status.Scene) Scenes.Add(asset); } } } } }