public static TargetToAssetBundlePlatformName ( BuildTarget t ) : string | ||
t | BuildTarget | |
return | string |
public void Setup(BuildTarget target, NodeData node, ConnectionPointData inputPoint, ConnectionData connectionToOutput, Dictionary <string, List <Asset> > inputGroupAssets, List <string> alreadyCached, Action <ConnectionData, Dictionary <string, List <Asset> >, List <string> > Output) { var outputDict = new Dictionary <string, List <Asset> >(); outputDict[key] = new List <Asset>(); var bundleNames = inputGroupAssets.Keys.ToList(); var bundleVariants = new Dictionary <string, List <string> >(); // get all variant name for bundles foreach (var name in bundleNames) { bundleVariants[name] = new List <string>(); var assets = inputGroupAssets[name]; foreach (var a in assets) { var variantName = a.variantName; if (!bundleVariants[name].Contains(variantName)) { bundleVariants[name].Add(variantName); } } } // add manifest file var manifestName = BuildTargetUtility.TargetToAssetBundlePlatformName(target); bundleNames.Add(manifestName); bundleVariants[manifestName] = new List <string>() { "" }; var bundleOutputDir = FileUtility.EnsureAssetBundleCacheDirExists(target, node); foreach (var name in bundleNames) { foreach (var v in bundleVariants[name]) { string bundleName = (string.IsNullOrEmpty(v))? name : name + "." + v; Asset bundle = Asset.CreateAssetWithImportPath(FileUtility.PathCombine(bundleOutputDir, bundleName)); Asset manifest = Asset.CreateAssetWithImportPath(FileUtility.PathCombine(bundleOutputDir, bundleName + AssetBundleGraphSettings.MANIFEST_FOOTER)); outputDict[key].Add(bundle); outputDict[key].Add(manifest); } } Output(connectionToOutput, outputDict, new List <string>()); }
public static string EnsureAssetBundleCacheDirExists(BuildTarget t, NodeData node, bool remake = false) { var cacheDir = FileUtility.PathCombine(AssetBundleGraphSettings.BUNDLEBUILDER_CACHE_PLACE, node.Id, BuildTargetUtility.TargetToAssetBundlePlatformName(t)); if (!Directory.Exists(cacheDir)) { Directory.CreateDirectory(cacheDir); } else { if (remake) { RemakeDirectory(cacheDir); } } return(cacheDir); }
public void Run(BuildTarget target, NodeData node, ConnectionPointData inputPoint, ConnectionData connectionToOutput, Dictionary <string, List <Asset> > inputGroupAssets, List <string> alreadyCached, Action <ConnectionData, Dictionary <string, List <Asset> >, List <string> > Output) { var bundleOutputDir = FileUtility.EnsureAssetBundleCacheDirExists(target, node); var bundleNames = inputGroupAssets.Keys.ToList(); var bundleVariants = new Dictionary <string, List <string> >(); // get all variant name for bundles foreach (var name in bundleNames) { bundleVariants[name] = new List <string>(); var assets = inputGroupAssets[name]; foreach (var a in assets) { var variantName = a.variantName; if (!bundleVariants[name].Contains(variantName)) { bundleVariants[name].Add(variantName); } } } int validNames = 0; foreach (var name in bundleNames) { var assets = inputGroupAssets[name]; // we do not build bundle without any asset if (assets.Count > 0) { validNames += bundleVariants[name].Count; } } AssetBundleBuild[] bundleBuild = new AssetBundleBuild[validNames]; int bbIndex = 0; foreach (var name in bundleNames) { foreach (var v in bundleVariants[name]) { var bundleName = name; var assets = inputGroupAssets[name]; if (assets.Count <= 0) { continue; } bundleBuild[bbIndex].assetBundleName = bundleName; bundleBuild[bbIndex].assetBundleVariant = v; bundleBuild[bbIndex].assetNames = assets.Where(x => x.variantName == v).Select(x => x.importFrom).ToArray(); ++bbIndex; } } BuildPipeline.BuildAssetBundles(bundleOutputDir, bundleBuild, (BuildAssetBundleOptions)node.BundleBuilderBundleOptions[target], target); var output = new Dictionary <string, List <Asset> >(); output[key] = new List <Asset>(); var generatedFiles = FileUtility.GetAllFilePathsInFolder(bundleOutputDir); // add manifest file bundleNames.Add(BuildTargetUtility.TargetToAssetBundlePlatformName(target)); foreach (var path in generatedFiles) { var fileName = Path.GetFileName(path); if (IsFileIntendedItem(fileName, bundleNames)) { output[key].Add(Asset.CreateAssetWithImportPath(path)); } else { Debug.LogWarning(node.Name + ":Irrelevant file found in assetbundle cache folder:" + fileName); } } Output(connectionToOutput, output, alreadyCached); }
public void Run(BuildTarget target, NodeData node, IEnumerable <PerformGraph.AssetGroups> incoming, IEnumerable <ConnectionData> connectionsToOutput, PerformGraph.Output Output, Action <NodeData, string, float> progressFunc) { if (incoming == null) { return; } var aggregatedGroups = new Dictionary <string, List <AssetReference> >(); aggregatedGroups[key] = new List <AssetReference>(); if (progressFunc != null) { progressFunc(node, "Collecting all inputs...", 0f); } foreach (var ag in incoming) { foreach (var name in ag.assetGroups.Keys) { if (!aggregatedGroups.ContainsKey(name)) { aggregatedGroups[name] = new List <AssetReference>(); } aggregatedGroups[name].AddRange(ag.assetGroups[name].AsEnumerable()); } } var bundleOutputDir = FileUtility.EnsureAssetBundleCacheDirExists(target, node); var bundleNames = aggregatedGroups.Keys.ToList(); var bundleVariants = new Dictionary <string, List <string> >(); if (progressFunc != null) { progressFunc(node, "Building bundle variants map...", 0.2f); } // get all variant name for bundles foreach (var name in aggregatedGroups.Keys) { if (!bundleVariants.ContainsKey(name)) { bundleVariants[name] = new List <string>(); } var assets = aggregatedGroups[name]; foreach (var a in assets) { var variantName = a.variantName; if (!bundleVariants[name].Contains(variantName)) { bundleVariants[name].Add(variantName); } } } int validNames = 0; foreach (var name in bundleNames) { var assets = aggregatedGroups[name]; // we do not build bundle without any asset if (assets.Count > 0) { validNames += bundleVariants[name].Count; } } AssetBundleBuild[] bundleBuild = new AssetBundleBuild[validNames]; int bbIndex = 0; foreach (var name in bundleNames) { foreach (var v in bundleVariants[name]) { var assets = aggregatedGroups[name]; if (assets.Count <= 0) { continue; } bundleBuild[bbIndex].assetBundleName = name; bundleBuild[bbIndex].assetBundleVariant = v; bundleBuild[bbIndex].assetNames = assets.Where(x => x.variantName == v).Select(x => x.importFrom).ToArray(); ++bbIndex; } } if (progressFunc != null) { progressFunc(node, "Building Asset Bundles...", 0.7f); } AssetBundleManifest m = BuildPipeline.BuildAssetBundles(bundleOutputDir, bundleBuild, (BuildAssetBundleOptions)node.BundleBuilderBundleOptions[target], target); var output = new Dictionary <string, List <AssetReference> >(); output[key] = new List <AssetReference>(); var generatedFiles = FileUtility.GetAllFilePathsInFolder(bundleOutputDir); // add manifest file bundleVariants.Add(BuildTargetUtility.TargetToAssetBundlePlatformName(target).ToLower(), new List <string> { null }); foreach (var path in generatedFiles) { var fileName = path.Substring(bundleOutputDir.Length + 1); if (IsFileIntendedItem(fileName, bundleVariants)) { output[key].Add(AssetReferenceDatabase.GetAssetBundleReference(path)); } } if (Output != null) { var dst = (connectionsToOutput == null || !connectionsToOutput.Any())? null : connectionsToOutput.First(); Output(dst, output); } AssetBundleBuildReport.AddBuildReport(new AssetBundleBuildReport(node, m, bundleBuild, output[key], aggregatedGroups, bundleVariants)); }
public void Setup(BuildTarget target, NodeData node, IEnumerable <PerformGraph.AssetGroups> incoming, IEnumerable <ConnectionData> connectionsToOutput, PerformGraph.Output Output) { // BundleBuilder do nothing without incoming connections if (incoming == null) { return; } var bundleNames = incoming.SelectMany(v => v.assetGroups.Keys).Distinct().ToList(); var bundleVariants = new Dictionary <string, List <string> >(); // get all variant name for bundles foreach (var ag in incoming) { foreach (var name in ag.assetGroups.Keys) { if (!bundleVariants.ContainsKey(name)) { bundleVariants[name] = new List <string>(); } var assets = ag.assetGroups[name]; foreach (var a in assets) { var variantName = a.variantName; if (!bundleVariants[name].Contains(variantName)) { bundleVariants[name].Add(variantName); } } } } // add manifest file var manifestName = BuildTargetUtility.TargetToAssetBundlePlatformName(target); bundleNames.Add(manifestName); bundleVariants[manifestName] = new List <string>() { "" }; if (connectionsToOutput != null && Output != null) { UnityEngine.Assertions.Assert.IsTrue(connectionsToOutput.Any()); var outputDict = new Dictionary <string, List <AssetReference> >(); outputDict[key] = new List <AssetReference>(); var bundleOutputDir = FileUtility.EnsureAssetBundleCacheDirExists(target, node); foreach (var name in bundleNames) { foreach (var v in bundleVariants[name]) { string bundleName = (string.IsNullOrEmpty(v))? name : name + "." + v; AssetReference bundle = AssetReferenceDatabase.GetAssetBundleReference(FileUtility.PathCombine(bundleOutputDir, bundleName)); AssetReference manifest = AssetReferenceDatabase.GetAssetBundleReference(FileUtility.PathCombine(bundleOutputDir, bundleName + AssetBundleGraphSettings.MANIFEST_FOOTER)); outputDict[key].Add(bundle); outputDict[key].Add(manifest); } } var dst = (connectionsToOutput == null || !connectionsToOutput.Any())? null : connectionsToOutput.First(); Output(dst, outputDict); } }