public static ConfigGraph CreateNewGraphFromImport(string pathToSave) { // try load from v1. try { V1.SaveData v1 = V1.SaveData.Data; ConfigGraph newGraph = CreateNewGraph(pathToSave); newGraph.Import(v1); return(newGraph); } catch (Exception e) { LogUtility.Logger.LogError(LogUtility.kTag, "Failed to import graph from previous version." + e); } return(null); }
private void Import(V1.SaveData v1) { m_lastModified = GetFileTimeUtcString(); m_version = ABG_FILE_VERSION; foreach (var n in v1.Nodes) { m_allNodes.Add(new NodeData(n)); } foreach (var c in v1.Connections) { m_allConnections.Add(new ConnectionData(c)); } EditorUtility.SetDirty(this); }
public static INodeOperation CreateOperation(SaveData saveData, NodeData currentNodeData, Action <NodeException> errorHandler) { INodeOperation executor = null; try { switch (currentNodeData.Kind) { case NodeKind.LOADER_GUI: { executor = new IntegratedGUILoader(); break; } case NodeKind.FILTER_GUI: { // Filter requires multiple output connections var connectionsToChild = saveData.Connections.FindAll(c => c.FromNodeId == currentNodeData.Id); executor = new IntegratedGUIFilter(connectionsToChild); break; } case NodeKind.IMPORTSETTING_GUI: { executor = new IntegratedGUIImportSetting(); break; } case NodeKind.MODIFIER_GUI: { executor = new IntegratedGUIModifier(); break; } case NodeKind.GROUPING_GUI: { executor = new IntegratedGUIGrouping(); break; } case NodeKind.PREFABBUILDER_GUI: { executor = new IntegratedPrefabBuilder(); break; } case NodeKind.BUNDLECONFIG_GUI: { executor = new IntegratedGUIBundleConfigurator(); break; } case NodeKind.BUNDLEBUILDER_GUI: { executor = new IntegratedGUIBundleBuilder(); break; } case NodeKind.EXPORTER_GUI: { executor = new IntegratedGUIExporter(); break; } default: { Debug.LogError(currentNodeData.Name + " is defined as unknown kind of node. value:" + currentNodeData.Kind); break; } } } catch (NodeException e) { errorHandler(e); } return(executor); }
/** * Perform Run or Setup from parent of given terminal node recursively. */ private static void DoNodeOperation( BuildTarget target, NodeData currentNodeData, ConnectionPointData currentInputPoint, ConnectionData connectionToOutput, SaveData saveData, Dictionary <ConnectionData, Dictionary <string, List <Asset> > > resultDict, Dictionary <NodeData, List <string> > cachedDict, List <string> performedIds, bool isActualRun, Action <NodeException> errorHandler, Action <NodeData, float> updateHandler ) { if (performedIds.Contains(currentNodeData.Id) || (currentInputPoint != null && performedIds.Contains(currentInputPoint.Id))) { return; } /* * Find connections coming into this node from parent node, and traverse recursively */ var connectionsToParents = saveData.Connections.FindAll(con => con.ToNodeId == currentNodeData.Id); foreach (var c in connectionsToParents) { var parentNode = saveData.Nodes.Find(node => node.Id == c.FromNodeId); UnityEngine.Assertions.Assert.IsNotNull(parentNode); // check if nodes can connect together ConnectionData.ValidateConnection(parentNode, currentNodeData); if (parentNode.InputPoints.Count > 0) { // if node has multiple input, node is operated per input foreach (var parentInputPoint in parentNode.InputPoints) { DoNodeOperation(target, parentNode, parentInputPoint, c, saveData, resultDict, cachedDict, performedIds, isActualRun, errorHandler, updateHandler); } } // if parent does not have input point, call with inputPoint==null else { DoNodeOperation(target, parentNode, null, c, saveData, resultDict, cachedDict, performedIds, isActualRun, errorHandler, updateHandler); } } // mark this point as performed if (currentInputPoint != null) { performedIds.Add(currentInputPoint.Id); } // Root node does not have input point, so we are storing node id instead. else { performedIds.Add(currentNodeData.Id); } /* * Perform node operation for this node */ if (updateHandler != null) { updateHandler(currentNodeData, 0f); } /* * has next node, run first time. */ var alreadyCachedPaths = new List <string>(); if (cachedDict.ContainsKey(currentNodeData)) { alreadyCachedPaths.AddRange(cachedDict[currentNodeData]); } // load already exist cache from node. alreadyCachedPaths.AddRange(GetCachedDataByNode(target, currentNodeData)); // Grab incoming assets from result by refering connections to parents var inputGroupAssets = new Dictionary <string, List <Asset> >(); if (currentInputPoint != null) { // aggregates all input assets coming from current inputPoint var connToParentsFromCurrentInput = saveData.Connections.FindAll(con => con.ToNodeConnectionPointId == currentInputPoint.Id); foreach (var rCon in connToParentsFromCurrentInput) { if (!resultDict.ContainsKey(rCon)) { continue; } var result = resultDict[rCon]; foreach (var groupKey in result.Keys) { if (!inputGroupAssets.ContainsKey(groupKey)) { inputGroupAssets[groupKey] = new List <Asset>(); } inputGroupAssets[groupKey].AddRange(result[groupKey]); } } } /* * the Action passes to NodeOperaitons. * It stores result to resultDict. */ Action <ConnectionData, Dictionary <string, List <Asset> >, List <string> > Output = (ConnectionData destinationConnection, Dictionary <string, List <Asset> > outputGroupAsset, List <string> cachedItems) => { if (destinationConnection != null) { if (!resultDict.ContainsKey(destinationConnection)) { resultDict[destinationConnection] = new Dictionary <string, List <Asset> >(); } /* * merge connection result by group key. */ foreach (var groupKey in outputGroupAsset.Keys) { if (!resultDict[destinationConnection].ContainsKey(groupKey)) { resultDict[destinationConnection][groupKey] = new List <Asset>(); } resultDict[destinationConnection][groupKey].AddRange(outputGroupAsset[groupKey]); } } if (isActualRun) { if (!cachedDict.ContainsKey(currentNodeData)) { cachedDict[currentNodeData] = new List <string>(); } if (cachedItems != null) { cachedDict[currentNodeData].AddRange(cachedItems); } } }; try { INodeOperation executor = CreateOperation(saveData, currentNodeData, errorHandler); if (executor != null) { if (isActualRun) { executor.Run(target, currentNodeData, currentInputPoint, connectionToOutput, inputGroupAssets, alreadyCachedPaths, Output); } else { executor.Setup(target, currentNodeData, currentInputPoint, connectionToOutput, inputGroupAssets, alreadyCachedPaths, Output); } } } catch (NodeException e) { errorHandler(e); // since error occured, this node should stop running for other inputpoints. Adding node id to stop. if (!performedIds.Contains(currentNodeData.Id)) { performedIds.Add(currentNodeData.Id); } } if (updateHandler != null) { updateHandler(currentNodeData, 1f); } }
/** * Build from commandline - entrypoint. */ public static void BuildFromCommandline() { try { var arguments = new List <string>(System.Environment.GetCommandLineArgs()); Application.stackTraceLogType = StackTraceLogType.None; BuildTarget target = EditorUserBuildSettings.activeBuildTarget; int targetIndex = arguments.FindIndex(a => a == "-target"); if (targetIndex >= 0) { var targetStr = arguments[targetIndex + 1]; LogUtility.Logger.Log("Target specified:" + targetStr); var newTarget = BuildTargetUtility.BuildTargetFromString(arguments[targetIndex + 1]); if (!BuildTargetUtility.IsBuildTargetSupported(newTarget)) { throw new AssetBundleGraphException(newTarget + " is not supported to build with this Unity. Please install platform support with installer(s)."); } if (newTarget != target) { #if UNITY_5_6 EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetUtility.TargetToGroup(newTarget), newTarget); #else EditorUserBuildSettings.SwitchActiveBuildTarget(newTarget); #endif target = newTarget; } } LogUtility.Logger.Log("AssetReference bundle building for:" + BuildTargetUtility.TargetToHumaneString(target)); if (!SaveData.IsSaveDataAvailableAtDisk()) { LogUtility.Logger.Log("AssetBundleGraph save data not found. Aborting..."); return; } // load data from file. AssetBundleGraphController c = new AssetBundleGraphController(); // perform setup. Fails if any exception raises. c.Perform(target, false, true, null); // if there is error reported, then run if (c.IsAnyIssueFound) { LogUtility.Logger.Log("Build terminated because following error found during Setup phase. Please fix issues by opening editor before building."); c.Issues.ForEach(e => LogUtility.Logger.LogError(LogUtility.kTag, e)); return; } NodeData lastNodeData = null; float lastProgress = 0.0f; Action <NodeData, string, float> updateHandler = (NodeData node, string message, float progress) => { if (node != null && lastNodeData != node) { lastNodeData = node; lastProgress = progress; LogUtility.Logger.LogFormat(LogType.Log, "Processing {0}", node.Name); } if (progress > lastProgress) { if (progress <= 1.0f) { LogUtility.Logger.LogFormat(LogType.Log, "{0} Complete.", node.Name); } else if ((progress - lastProgress) > 0.2f) { LogUtility.Logger.LogFormat(LogType.Log, "{0}: {1} % : {2}", node.Name, (int)progress * 100f, message); } lastProgress = progress; } }; // run datas. c.Perform(target, true, true, updateHandler); AssetDatabase.Refresh(); } catch (Exception e) { LogUtility.Logger.LogError(LogUtility.kTag, e); LogUtility.Logger.LogError(LogUtility.kTag, "Building asset bundles terminated due to unexpected error."); } finally { LogUtility.Logger.Log("End of build."); } }
public static SaveData Reload() { s_saveData = null; return(Data); }