AssetBundleGraph.AssetBundleGraphController.Perform C# (CSharp) Method

Perform() public static method

public static Perform ( SaveData saveData, BuildTarget target, bool isRun, Action errorHandler, float>.Action updateHandler ) : Dictionary>>
saveData SaveData
target BuildTarget
isRun bool
errorHandler Action
updateHandler float>.Action
return Dictionary>>
        public static Dictionary<ConnectionData, Dictionary<string, List<Asset>>> Perform(
			SaveData saveData, 
			BuildTarget target,
			bool isRun,
			Action<NodeException> errorHandler,
			Action<NodeData, float> updateHandler)
        {
            bool validateFailed = false;
            try {
                ValidateNameCollision(saveData);
                ValidateLoopConnection(saveData);
            } catch (NodeException e) {
                errorHandler(e);
                validateFailed = true;
            }

            var resultDict = new Dictionary<ConnectionData, Dictionary<string, List<Asset>>>();
            var performedIds = new List<string>();
            var cacheDict  = new Dictionary<NodeData, List<string>>();

            // if validation failed, node may contain looped connections, so we are not going to
            // go into each operations.
            if(!validateFailed) {
                var leaf = saveData.CollectAllLeafNodes();

                foreach (var leafNode in leaf) {
                    if( leafNode.InputPoints.Count == 0 ) {
                        DoNodeOperation(target, leafNode, null, null, saveData, resultDict, cacheDict, performedIds, isRun, errorHandler, updateHandler);
                    } else {
                        foreach(var inputPoint in leafNode.InputPoints) {
                            DoNodeOperation(target, leafNode, inputPoint, null, saveData, resultDict, cacheDict, performedIds, isRun, errorHandler, updateHandler);
                        }
                    }
                }
            }
            return resultDict;
        }

Usage Example

Example #1
0
        public static void BuildFromCommandline()
        {
            try {
                var arguments = new List <string>(System.Environment.GetCommandLineArgs());

                Application.SetStackTraceLogType(LogType.Log, StackTraceLogType.None);
                Application.SetStackTraceLogType(LogType.Error, StackTraceLogType.None);
                Application.SetStackTraceLogType(LogType.Warning, StackTraceLogType.None);

                BuildTarget target = EditorUserBuildSettings.activeBuildTarget;

                int targetIndex = arguments.FindIndex(a => a == "-target");

                if (targetIndex >= 0)
                {
                    var targetStr = arguments[targetIndex + 1];
                    Debug.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)
                    {
                        EditorUserBuildSettings.SwitchActiveBuildTarget(newTarget);
                        target = newTarget;
                    }
                }

                Debug.Log("Asset bundle building for:" + BuildTargetUtility.TargetToHumaneString(target));

                if (!SaveData.IsSaveDataAvailableAtDisk())
                {
                    Debug.Log("AssetBundleGraph save data not found. Aborting...");
                    return;
                }

                // load data from file.
                SaveData             saveData = SaveData.LoadFromDisk();
                List <NodeException> errors   = new List <NodeException>();
                Dictionary <ConnectionData, Dictionary <string, List <Asset> > > result = null;

                Action <NodeException> errorHandler = (NodeException e) => {
                    errors.Add(e);
                };

                // perform setup. Fails if any exception raises.
                AssetBundleGraphController.Perform(saveData, target, false, errorHandler, null);

                // if there is error reported, then run
                if (errors.Count > 0)
                {
                    Debug.Log("Build terminated because following error found during Setup phase. Please fix issues by opening editor before building.");
                    errors.ForEach(e => Debug.LogError(e));

                    return;
                }

                NodeData lastNodeData = null;
                float    lastProgress = 0.0f;
                Action <NodeData, float> updateHandler = (NodeData node, float progress) => {
                    if (node != null && lastNodeData != node)
                    {
                        lastNodeData = node;
                        lastProgress = progress;

                        Debug.LogFormat("Processing {0}...", node.Name);
                    }
                    if (progress > lastProgress)
                    {
                        if (progress <= 1.0f)
                        {
                            Debug.LogFormat("{0} Complete.", node.Name);
                        }
                        else if ((progress - lastProgress) > 0.2f)
                        {
                            Debug.LogFormat("{0}: {1} %", node.Name, (int)progress * 100f);
                        }
                        lastProgress = progress;
                    }
                };

                // run datas.
                result = AssetBundleGraphController.Perform(saveData, target, true, errorHandler, updateHandler);

                AssetDatabase.Refresh();
                AssetBundleGraphController.Postprocess(saveData, result, true);
            } catch (Exception e) {
                Debug.LogError(e);
                Debug.LogError("Building asset bundles terminated due to unexpected error.");
            } finally {
                Debug.Log("End of build.");
            }
        }
All Usage Examples Of AssetBundleGraph.AssetBundleGraphController::Perform