/// <summary> /// Export received array of packages. /// </summary> /// <exception cref="ArgumentNullException"/> /// <exception cref="ArgumentException"/> public static void ExportPackages([NotNull] string directory, [NotNull] JEMAssetBuilderPackage[] packages) { if (directory == null) { throw new ArgumentNullException(nameof(directory)); } if (packages == null) { throw new ArgumentNullException(nameof(packages)); } if (packages.Length == 0) { throw new ArgumentException("Value cannot be an empty collection.", nameof(packages)); } EditorUtility.DisplayProgressBar("JEM Asset Builder", "Starting up.", 0); try { var bundleBuildDirectory = JEMAssetsBuilderConfiguration.GetDirectory(); var bundleBuildList = new List <AssetBundleBuild>(); for (var index = 0; index < packages.Length; index++) { var package = packages[index]; EditorUtility.DisplayProgressBar("JEM Asset Builder", "Preparing to export: " + package.Name, (float)index / packages.Length * 100f); var filePath = package.GetFile(); var fileName = Path.GetFileName(filePath); var bundleBuildData = new AssetBundleBuild { assetBundleName = fileName, assetNames = package.GetPathToAssets() }; bundleBuildList.Add(bundleBuildData); } EditorUtility.DisplayProgressBar("JEM Asset Builder", "Starting Unity's AssetBundles building.", 0f); var manifest = BuildPipeline.BuildAssetBundles(bundleBuildDirectory, bundleBuildList.ToArray(), BundleOptions, BundleBuildTarget); if (manifest != null && manifest.GetAllAssetBundles().Length != 0) { Debug.Log($"JEM Asset Builder successfully build {bundleBuildList.Count} packages!"); // Show target directory in File Explorer Process.Start(bundleBuildDirectory); } else { Debug.LogError($"JEM Asset Builder failed to build {bundleBuildList.Count} packages of Asset Bundles."); } } catch (Exception e) { Debug.LogException(e); } EditorUtility.ClearProgressBar(); }
private void OnGUI() { GUILayout.FlexibleSpace(); EditorGUILayout.BeginHorizontal(); _packageName = EditorGUILayout.TextField("Package Name", _packageName); GUILayout.Label(JEMAssetsBuilderConfiguration.GetExtension()); EditorGUILayout.EndHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Add", GUILayout.Height(22))) { AddPackage(); } }
// ERROR: EndLayoutGroup: BeginLayoutGroup must be called first. private void Update() { if (_wantToExportAll) { _exportTimeout = 2; // Skip two frames after export... _wantToExportAll = false; JEMAssetBuilderExporter.ExportPackages(JEMAssetsBuilderConfiguration.GetDirectory(), Packages.ToArray()); } if (_exportPackageOnce) { _exportTimeout = 2; // Skip two frames after export... _exportPackageOnce = false; ExportAssets(_exportPackage); _exportPackage = null; } }
private void OnEnable() { // Load JEM editor resources JEMEditorResources.Load(); // Apply title titleContent = new GUIContent("JEM Asset Builder", JEMEditorResources.JEMIconTexture); // Try to load configuration. JEMAssetsBuilderConfiguration.TryLoadConfiguration(); // Load Saved vars. _assetsScroll = new SavedVector2($"{nameof(JEMAssetBuilderWindow)}.AssetsScroll", Vector2.zero); _packagesScroll = new SavedVector2($"{nameof(JEMAssetBuilderWindow)}.PackagesScroll", Vector2.zero); // Load packages! LoadPackages(); }
/// <summary> /// Exports assets of target package. /// </summary> /// <exception cref="ArgumentNullException"/> private static void ExportAssets([NotNull] JEMAssetBuilderPackage package) { if (package == null) { throw new ArgumentNullException(nameof(package)); } if (package.Assets.Count == 0) { EditorUtility.DisplayDialog("Oops.", "Can't export empty package..", "Ok"); } else { // Before export make sure that all packages are saved, we do not want to lose any data... SavePackages(); // Export! JEMAssetBuilderExporter.ExportPackages(JEMAssetsBuilderConfiguration.GetDirectory(), new[] { package }); } }
public static void ExportSelectedDirectly(MenuCommand menuCommand) { if (Selection.objects.Length == 0) { EditorUtility.DisplayDialog("Oops.", "No assets selected to build.", "Ok"); } else { // Try to load configuration first JEMAssetsBuilderConfiguration.TryLoadConfiguration(); // Get save file path var path = EditorUtility.SaveFilePanel("Export Assets", Environment.CurrentDirectory, "myAssetBundle", JEMAssetsBuilderConfiguration.GetExtension().Remove(0, 1)); if (string.IsNullOrEmpty(path)) { return; } // Export directly. ExportDirectly(path, Selection.objects); } }
/// <summary> /// Exports directly target array of objects. /// </summary> /// <exception cref="ArgumentNullException"/> /// <exception cref="InvalidOperationException"/> public static void ExportDirectly([NotNull] string filePath, [NotNull] Object[] objects) { if (filePath == null) { throw new ArgumentNullException(nameof(filePath)); } if (objects == null) { throw new ArgumentNullException(nameof(objects)); } if (objects.Length == 0) { return; } if (string.IsNullOrEmpty(filePath)) { return; } // Try to load configuration first JEMAssetsBuilderConfiguration.Load(); // Create package from received data var package = new JEMAssetBuilderPackage { Name = Path.GetFileName(filePath).Remove(Path.GetFileName(filePath).Length - JEMAssetsBuilderConfiguration.GetExtension().Length, JEMAssetsBuilderConfiguration.GetExtension().Length) }; // Write objects to new package foreach (var obj in objects) { package.AddAsset(obj); } // Export package. ExportPackages(Path.GetDirectoryName(filePath) ?? throw new InvalidOperationException(), new[] { package }); }
private void OnEnable() { // Try to load configuration! JEMAssetsBuilderConfiguration.TryLoadConfiguration(); }
/// <summary> /// Gets full path to file of this package. /// </summary> public string GetFile() => $"{JEMAssetsBuilderConfiguration.GetDirectory()}\\{Name}{JEMAssetsBuilderConfiguration.GetExtension()}";