Ejemplo n.º 1
0
        /// <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();
        }
        // 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;
            }
        }
        /// <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 });
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 ///     Gets full path to file of this package.
 /// </summary>
 public string GetFile() => $"{JEMAssetsBuilderConfiguration.GetDirectory()}\\{Name}{JEMAssetsBuilderConfiguration.GetExtension()}";