/** * Prepare is called whenever graph needs update. */ public override void Prepare(BuildTarget target, Model.NodeData node, IEnumerable <PerformGraph.AssetGroups> incoming, IEnumerable <Model.ConnectionData> connectionsToOutput, PerformGraph.Output Output) { if (string.IsNullOrEmpty(m_bundleNameTemplate)) { throw new NodeException("Bundle Name Template is empty.", "Set valid bundle name template.", node); } if (m_groupExtractedAssets [target] != 0) { if (m_groupSizeByte[target] < 0) { throw new NodeException("Invalid size. Size property must be a positive number.", "Set valid size.", node); } } // Pass incoming assets straight to Output if (Output != null) { var destination = (connectionsToOutput == null || !connectionsToOutput.Any())? null : connectionsToOutput.First(); if (incoming != null) { var buildMap = AssetBundleBuildMap.GetBuildMap(); buildMap.ClearFromId(node.Id); var dependencyCollector = new Dictionary <string, List <string> >(); // [asset path:group name] var sharedDependency = new Dictionary <string, List <AssetReference> >(); var groupNameMap = new Dictionary <string, string>(); // build dependency map foreach (var ag in incoming) { foreach (var key in ag.assetGroups.Keys) { var assets = ag.assetGroups[key]; foreach (var a in assets) { CollectDependencies(key, new string[] { a.importFrom }, ref dependencyCollector); } } } foreach (var entry in dependencyCollector) { if (entry.Value != null && entry.Value.Count > 1) { var joinedName = string.Join("-", entry.Value.ToArray()); if (!groupNameMap.ContainsKey(joinedName)) { var count = groupNameMap.Count; var newName = m_bundleNameTemplate.Replace("*", count.ToString()); if (newName == m_bundleNameTemplate) { newName = m_bundleNameTemplate + count.ToString(); } groupNameMap.Add(joinedName, newName); } var groupName = groupNameMap[joinedName]; if (!sharedDependency.ContainsKey(groupName)) { sharedDependency[groupName] = new List <AssetReference>(); } sharedDependency[groupName].Add(AssetReference.CreateReference(entry.Key)); } } if (sharedDependency.Keys.Count > 0) { // subgroup shared dependency bundles by size if (m_groupExtractedAssets [target] != 0) { List <string> devidingBundleNames = new List <string> (sharedDependency.Keys); long szGroup = m_groupSizeByte[target] * 1000; foreach (var bundleName in devidingBundleNames) { var assets = sharedDependency[bundleName]; int groupCount = 0; long szGroupCount = 0; foreach (var a in assets) { var subGroupName = string.Format("{0}_{1}", bundleName, groupCount); if (!sharedDependency.ContainsKey(subGroupName)) { sharedDependency[subGroupName] = new List <AssetReference>(); } sharedDependency[subGroupName].Add(a); szGroupCount += GetSizeOfAsset(a, (GroupingType)m_groupingType[target]); if (szGroupCount >= szGroup) { szGroupCount = 0; ++groupCount; } } sharedDependency.Remove(bundleName); } } foreach (var bundleName in sharedDependency.Keys) { var bundleConfig = buildMap.GetAssetBundleWithNameAndVariant(node.Id, bundleName, string.Empty); bundleConfig.AddAssets(node.Id, sharedDependency[bundleName].Select(a => a.importFrom)); } foreach (var ag in incoming) { Output(destination, new Dictionary <string, List <AssetReference> >(ag.assetGroups)); } Output(destination, sharedDependency); } else { foreach (var ag in incoming) { Output(destination, ag.assetGroups); } } } else { // Overwrite output with empty Dictionary when no there is incoming asset Output(destination, new Dictionary <string, List <AssetReference> >()); } } }
public AssetReferenceTreeItem(AssetReference a) : base(a.path.GetHashCode(), 0, a.fileName) { m_asset = a; }
public override void Prepare(BuildTarget target, Model.NodeData node, IEnumerable <PerformGraph.AssetGroups> incoming, IEnumerable <Model.ConnectionData> connectionsToOutput, PerformGraph.Output Output) { // BundleBuilder do nothing without incoming connections if (incoming == null) { return; } var bundleOutputDir = PrepareOutputDirectory(target, node, false, true); 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 = GetManifestName(target, node, true); 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>(); 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 + Model.Settings.MANIFEST_FOOTER)); outputDict[key].Add(bundle); outputDict[key].Add(manifest); } } var dst = (connectionsToOutput == null || !connectionsToOutput.Any())? null : connectionsToOutput.First(); Output(dst, outputDict); } }
public Type GetAssetType(AssetReference asset) { return(typeof(TextureImporter)); }
static public bool DoesAssetNeedRegenerate(AssetGenerator.GeneratorEntry entry, Model.NodeData node, BuildTarget target, AssetReference asset) { var generateInfo = GetAssetGenerateInfo(entry, node, target, asset); // need rebuilding if no buildInfo found if (generateInfo == null) { return(true); } // need rebuilding if given builder is changed if (generateInfo.m_generatorClass != entry.m_instance.ClassName) { return(true); } // need rebuilding if given builder is changed if (generateInfo.m_instanceData != entry.m_instance[target]) { return(true); } var version = AssetGeneratorUtility.GetVersion(entry.m_instance.ClassName); // need rebuilding if given builder version is changed if (generateInfo.m_generatorVersion != version) { return(true); } if (generateInfo.m_usedAsset.importFrom != asset.importFrom) { return(true); } // If asset is modified from last time, then need rebuilding if (generateInfo.m_usedAsset.IsAssetModifiedFromLastTime) { return(true); } return(false); }
public void Initialize(string className, string instanceData, string version, AssetReference asset) { m_generatorClass = className; m_instanceData = instanceData; m_generatorVersion = version; m_usedAsset = new UsedAsset(asset.importFrom); }
static public void SaveAssetGenerateInfo(AssetGenerator.GeneratorEntry entry, Model.NodeData node, BuildTarget target, AssetReference asset) { var cacheDir = FileUtility.EnsureCacheDirExists(target, node, AssetGenerator.kCacheDirName); var generateInfoDir = FileUtility.PathCombine(cacheDir, entry.m_id); if (!Directory.Exists(generateInfoDir)) { Directory.CreateDirectory(generateInfoDir); } var generatorInfoPath = FileUtility.PathCombine(generateInfoDir, asset.fileNameAndExtension + ".asset"); var version = AssetGeneratorUtility.GetVersion(entry.m_instance.ClassName); var info = ScriptableObject.CreateInstance <AssetGenerateInfo>(); info.Initialize(entry.m_instance.ClassName, entry.m_instance[target], version, asset); AssetDatabase.CreateAsset(info, generatorInfoPath); }
static private AssetGenerateInfo GetAssetGenerateInfo(AssetGenerator.GeneratorEntry entry, Model.NodeData node, BuildTarget target, AssetReference asset) { var cacheDir = FileUtility.EnsureCacheDirExists(target, node, AssetGenerator.kCacheDirName); var generateInfoDir = FileUtility.PathCombine(cacheDir, entry.m_id); var generatorInfoPath = FileUtility.PathCombine(generateInfoDir, asset.fileNameAndExtension + ".asset"); return(AssetDatabase.LoadAssetAtPath <AssetGenerateInfo>(generatorInfoPath)); }
public void LogModify(AssetReference a) { LogModify(a.assetDatabaseId); }