public void SetupSupportedBuildTargets() { if (supportedBuildTargets == null) { supportedBuildTargets = new List <BuildTarget>(); supportedBuildTargetGroups = new List <BuildTargetGroup>(); try { foreach (BuildTarget target in Enum.GetValues(typeof(BuildTarget))) { if (BuildTargetUtility.IsBuildTargetSupported(target)) { if (!supportedBuildTargets.Contains(target)) { supportedBuildTargets.Add(target); } BuildTargetGroup g = BuildTargetUtility.TargetToGroup(target); if (g == BuildTargetGroup.Unknown) { // skip unknown platform continue; } if (!supportedBuildTargetGroups.Contains(g)) { supportedBuildTargetGroups.Add(g); } } } supportedBuildTargetNames = new string[supportedBuildTargets.Count]; for (int i = 0; i < supportedBuildTargets.Count; ++i) { supportedBuildTargetNames[i] = BuildTargetUtility.TargetToHumaneString(supportedBuildTargets[i]); } } catch (Exception e) { Debug.LogError(e.ToString()); } } }
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."); } }
/** * Build from commandline - entrypoint. */ 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]; 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."); } }