public static AssetReference GetReferenceWithType(string relativePath, Type t) { return(GetReference(relativePath, () => { return AssetReference.CreateReference(relativePath, t); })); }
/** * 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) { // Overwrite output with empty Dictionary when no there is incoming asset Output(destination, new Dictionary <string, System.Collections.Generic.List <AssetReference> >()); return; } var buildMap = AssetBundleBuildMap.GetBuildMap(); buildMap.ClearFromId(node.Id); var dependencyCollector = new Dictionary <string, System.Collections.Generic.List <string> >(); // [asset path:group name] var sharedDependency = new Dictionary <string, System.Collections.Generic.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 System.Collections.Generic.List <AssetReference>(); } sharedDependency[groupName].Add(AssetReference.CreateReference(entry.Key)); } } if (sharedDependency.Keys.Count == 0) { foreach (var ag in incoming) { Output(destination, ag.assetGroups); } } // subgroup shared dependency bundles by size if (m_groupExtractedAssets[target] != 0) { System.Collections.Generic.List <string> devidingBundleNames = new System.Collections.Generic.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 System.Collections.Generic.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)); } //remove doubles foreach (var shDep in sharedDependency) { foreach (var assetReference in shDep.Value) { foreach (var ag in incoming) { foreach (var agAssetGroup in ag.assetGroups) { List <AssetReference> toDel = new List <AssetReference>(); foreach (var incomingAssetReference in agAssetGroup.Value) { if (incomingAssetReference.path == assetReference.path && incomingAssetReference.fileNameAndExtension == assetReference.fileNameAndExtension) { toDel.Add(incomingAssetReference); Debug.LogWarning("Found duplicate " + incomingAssetReference.fileNameAndExtension); } } foreach (var reference in toDel) { agAssetGroup.Value.Remove(reference); Debug.LogWarning("Removed duplicate " + reference.fileNameAndExtension); } } } } } foreach (var ag in incoming) { Output(destination, new Dictionary <string, System.Collections.Generic.List <AssetReference> >(ag.assetGroups)); } Output(destination, sharedDependency); } }
public static AssetReference GetReference(string relativePath) { return(GetReference(relativePath, () => { return AssetReference.CreateReference(relativePath); })); }