Example #1
0
        /// <summary>
        /// Asynchronously builds an AAB at the specified path.
        /// </summary>
        /// <param name="aabFilePath">The AAB output file path.</param>
        /// <param name="assetPackConfig">Asset packs to include in the AAB.</param>
        /// <param name="onSuccess">
        /// Callback that fires with the final aab file location, when the bundle creation succeeds.
        /// </param>
        public void CreateBundleAsync(string aabFilePath, AssetPackConfig assetPackConfig, PostBuildCallback onSuccess)
        {
            // Copy the AssetPackConfig before leaving the main thread in case the original is modified later.
            var copiedAssetPackConfig = SerializationHelper.DeepCopy(assetPackConfig);

            _createBundleAsyncOnSuccess = onSuccess;
            StartCreateBundleAsync(() =>
            {
                try
                {
                    CreateBundle(aabFilePath, copiedAssetPackConfig);
                }
                catch (ThreadAbortException ex)
                {
                    if (!_canceled)
                    {
                        // Unexpected ThreadAbortException.
                        DisplayBuildError("Exception", ex.ToString());
                    }
                }
                catch (Exception ex)
                {
                    // Catch and display exceptions since they may otherwise be undetected on a background thread.
                    DisplayBuildError("Exception", ex.ToString());
                }
            });
        }
Example #2
0
        /// <summary>
        /// Synchronously builds an Android Player and then produces a final AAB synchronously or asynchronously,
        /// as specified.
        /// </summary>
        /// <param name="androidBuildOptions">Options indicating how to build the AAB, including asset packs.</param>
        /// <returns>An async task that provides an AndroidBuildReport.</returns>
        public async Task <AndroidBuildReport> CreateBundleWithTask(AndroidBuildOptions androidBuildOptions)
        {
            var taskCompletionSource = new TaskCompletionSource <AndroidBuildReport>();
            var androidBuildResult   = BuildAndroidPlayer(androidBuildOptions.BuildPlayerOptions);

            if (androidBuildResult.Cancelled)
            {
                taskCompletionSource.SetCanceled();
                return(await taskCompletionSource.Task);
            }

            var androidBuildReport = new AndroidBuildReport(androidBuildResult.Report);

            if (androidBuildResult.ErrorMessage != null)
            {
                taskCompletionSource.SetException(
                    new AndroidBuildException(androidBuildResult.ErrorMessage, androidBuildReport));
                return(await taskCompletionSource.Task);
            }

            var createBundleOptions = new CreateBundleOptions
            {
                AabFilePath        = androidBuildOptions.BuildPlayerOptions.locationPathName,
                AssetPackConfig    = androidBuildOptions.AssetPackConfig ?? new AssetPackConfig(),
                CompressionOptions = androidBuildOptions.CompressionOptions
            };

            if (androidBuildOptions.ForceSingleThreadedBuild || Application.isBatchMode)
            {
                CreateBundleInternal(
                    taskCompletionSource,
                    () => CreateBundle(createBundleOptions),
                    androidBuildReport,
                    androidBuildReport);
            }
            else
            {
                // Copy the AssetPackConfig while still on the main thread in case the original is modified later.
                createBundleOptions.AssetPackConfig = SerializationHelper.DeepCopy(createBundleOptions.AssetPackConfig);
                StartCreateBundleAsync(() =>
                {
                    CreateBundleInternal(
                        taskCompletionSource,
                        () => CreateBundle(createBundleOptions),
                        androidBuildReport,
                        androidBuildReport);
                });
            }

            return(await taskCompletionSource.Task);
        }
Example #3
0
        /// <summary>
        /// Synchronously builds an Android Player and then produces a final AAB synchronously or asynchronously,
        /// as specified.
        /// </summary>
        /// <param name="androidBuildOptions">Options indicating how to build the AAB, including asset packs.</param>
        /// <param name="buildSynchronously">
        /// Indicates whether to perform the build only on the main thread or to execute some steps asynchronously.
        /// </param>
        /// <returns>An async task that provides an AndroidBuildReport.</returns>
        public async Task <AndroidBuildReport> CreateBundleWithTask(
            AndroidBuildOptions androidBuildOptions, bool buildSynchronously)
        {
            var taskCompletionSource = new TaskCompletionSource <AndroidBuildReport>();
            var androidBuildResult   = BuildAndroidPlayer(androidBuildOptions.BuildPlayerOptions);

            if (androidBuildResult.Cancelled)
            {
                taskCompletionSource.SetCanceled();
                return(await taskCompletionSource.Task);
            }

            var androidBuildReport = new AndroidBuildReport(androidBuildResult.Report);

            if (androidBuildResult.ErrorMessage != null)
            {
                taskCompletionSource.SetException(
                    new AndroidBuildException(androidBuildResult.ErrorMessage, androidBuildReport));
                return(await taskCompletionSource.Task);
            }

            var aabFilePath     = androidBuildOptions.BuildPlayerOptions.locationPathName;
            var assetPackConfig = androidBuildOptions.AssetPackConfig ?? new AssetPackConfig();

            if (buildSynchronously)
            {
                CreateBundleInternal(taskCompletionSource, aabFilePath, assetPackConfig, androidBuildReport);
            }
            else
            {
                // Copy the AssetPackConfig while still on the main thread in case the original is modified later.
                var copiedAssetPackConfig = SerializationHelper.DeepCopy(assetPackConfig);
                StartCreateBundleAsync(() =>
                {
                    CreateBundleInternal(
                        taskCompletionSource, aabFilePath, copiedAssetPackConfig, androidBuildReport);
                });
            }

            return(await taskCompletionSource.Task);
        }