public static AssetBundleBuildSettings GenerateAssetBundleBuildSettings() { var settings = new AssetBundleBuildSettings(); settings.target = EditorUserBuildSettings.activeBuildTarget; settings.outputFolder = "AssetBundles/" + settings.target; settings.streamingResources = true; settings.editorBundles = false; return(settings); }
public static AssetBundleBuildInput GenerateAssetBundleBuildInput(AssetBundleBuildSettings settings) { var input = new AssetBundleBuildInput(); input.settings = settings; var bundleNames = AssetDatabase.GetAllAssetBundleNames(); input.bundles = new AssetBundleBuildInput.Definition[bundleNames.Length]; for (int i = 0; i < bundleNames.Length; i++) { int dot = bundleNames[i].LastIndexOf('.'); input.bundles[i].name = dot < 0 ? bundleNames[i] : bundleNames[i].Substring(0, dot); input.bundles[i].variant = dot < 0 ? string.Empty : bundleNames[i].Substring(dot + 1); var assets = AssetDatabase.GetAssetPathsFromAssetBundle(bundleNames[i]); input.bundles[i].assets = new GUID[assets.Length]; for (int a = 0; a < assets.Length; a++) { input.bundles[i].assets[a] = new GUID(AssetDatabase.AssetPathToGUID(assets[a])); } } return(input); }
public static void CacheAssetBundleBuildOutput(AssetBundleBuildOutput output, AssetBundleBuildSettings settings) { // TODO: Cache data about this build result for future patching, incremental build, etc }
public static AssetBundleBuildCommandSet GenerateAssetBundleBuildCommandSet(AssetBundleBuildInput input, AssetBundleBuildSettings settings) { // Create commands array matching the size of the input var commandSet = new AssetBundleBuildCommandSet(); commandSet.commands = new AssetBundleBuildCommandSet.Command[input.definitions.Length]; for (var i = 0; i < input.definitions.Length; ++i) { var definition = input.definitions[i]; // Populate each command from asset bundle definition var command = new AssetBundleBuildCommandSet.Command(); command.assetBundleName = definition.assetBundleName; command.explicitAssets = new AssetBundleBuildCommandSet.AssetLoadInfo[definition.explicitAssets.Length]; // Fill out asset load info and references for each asset in the definition var allObjects = new HashSet <ObjectIdentifier>(); for (var j = 0; j < definition.explicitAssets.Length; ++j) { var explicitAsset = new AssetBundleBuildCommandSet.AssetLoadInfo(); explicitAsset.asset = definition.explicitAssets[j]; explicitAsset.includedObjects = AssetBundleBuildInterface.GetObjectIdentifiersInAsset(definition.explicitAssets[j]); explicitAsset.referencedObjects = AssetBundleBuildInterface.GetPlayerDependenciesForObjects(explicitAsset.includedObjects); command.explicitAssets[j] = explicitAsset; allObjects.UnionWith(explicitAsset.includedObjects); allObjects.UnionWith(explicitAsset.referencedObjects); } command.assetBundleObjects = allObjects.ToArray(); commandSet.commands[i] = command; } // TODO: Debug printing //DebugPrintCommandSet(ref commandSet); // At this point, We have generated fully self contained asset bundles with 0 dependencies. // Default implementation is to reduce duplication of objects by declaring dependencies to other asset // bundles if that other asset bundle has an explicit asset declared that contains the objects needed // We also remove any built in unity objects as they are built with the player (We may want to change this part in the future) CalculateAssetBundleBuildDependencies(ref commandSet); // Note: I may, or may not feel dirty doing mutable things to what otherwise should be immutable struct // TODO: Debug printing //DebugPrintCommandSet(ref commandSet); return(commandSet); }
static void BuildAssetBundlesMenuItem() { var settings = new AssetBundleBuildSettings(); SaveAssetBundleOutput(ExecuteAssetBuildCommandSet(GenerateAssetBuildInstructionSet(GenerateAssetBundleBuildInput(settings)))); }