public void Setup(BuildTarget target,
NodeData node,
IEnumerable <PerformGraph.AssetGroups> incoming,
IEnumerable <ConnectionData> connectionsToOutput,
PerformGraph.Output Output)
{
ValidatePrefabBuilder(node, target, incoming,
() => {
throw new NodeException(node.Name + " :PrefabBuilder is not configured. Please configure from Inspector.", node.Id);
},
() => {
throw new NodeException(node.Name + " :Failed to create PrefabBuilder from settings. Please fix settings from Inspector.", node.Id);
},
(string groupKey) => {
throw new NodeException(string.Format("{0} :Can not create prefab with incoming assets for group {1}.", node.Name, groupKey), node.Id);
},
(AssetReference badAsset) => {
throw new NodeException(string.Format("{0} :Can not import incoming asset {1}.", node.Name, badAsset.fileNameAndExtension), node.Id);
}
);
if (incoming == null)
{
return;
}
var builder = PrefabBuilderUtility.CreatePrefabBuilder(node, target);
UnityEngine.Assertions.Assert.IsNotNull(builder);
var prefabOutputDir = FileUtility.EnsurePrefabBuilderCacheDirExists(target, node);
Dictionary <string, List <AssetReference> > output = null;
if (Output != null)
{
output = new Dictionary <string, List <AssetReference> >();
}
var aggregatedGroups = new Dictionary <string, List <AssetReference> >();
foreach (var ag in incoming)
{
foreach (var key in ag.assetGroups.Keys)
{
if (!aggregatedGroups.ContainsKey(key))
{
aggregatedGroups[key] = new List <AssetReference>();
}
aggregatedGroups[key].AddRange(ag.assetGroups[key].AsEnumerable());
}
}
foreach (var key in aggregatedGroups.Keys)
{
var assets = aggregatedGroups[key];
var thresold = PrefabBuilderUtility.GetPrefabBuilderAssetThreshold(node.ScriptClassName);
if (thresold < assets.Count)
{
var guiName = PrefabBuilderUtility.GetPrefabBuilderGUIName(node.ScriptClassName);
throw new NodeException(string.Format("{0} :Too many assets passed to {1} for group:{2}. {3}'s threshold is set to {4}",
node.Name, guiName, key, guiName, thresold), node.Id);
}
List <UnityEngine.Object> allAssets = LoadAllAssets(aggregatedGroups[key]);
var prefabFileName = builder.CanCreatePrefab(key, allAssets);
if (output != null && prefabFileName != null)
{
output[key] = new List <AssetReference> ()
{
AssetReferenceDatabase.GetPrefabReference(FileUtility.PathCombine(prefabOutputDir, prefabFileName + ".prefab"))
};
}
allAssets.ForEach(o => Resources.UnloadAsset(o));
}
if (Output != null)
{
var dst = (connectionsToOutput == null || !connectionsToOutput.Any())?
null : connectionsToOutput.First();
Output(dst, output);
}
}