Exemplo n.º 1
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);
        }
Exemplo n.º 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>
        /// <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);
        }
Exemplo n.º 3
0
 private void CreateBundleInternal(
     TaskCompletionSource <AndroidBuildReport> taskCompletionSource,
     string aabFilePath,
     AssetPackConfig assetPackConfig,
     CompressionOptions compressionOptions,
     AndroidBuildReport androidBuildReport)
 {
     try
     {
         var errorMessage = CreateBundle(aabFilePath, assetPackConfig, compressionOptions);
         if (errorMessage == null)
         {
             taskCompletionSource.SetResult(androidBuildReport);
         }
         else
         {
             // Already logged.
             taskCompletionSource.SetException(new AndroidBuildException(errorMessage, androidBuildReport));
         }
     }
     catch (ThreadAbortException ex)
     {
         if (_canceled)
         {
             taskCompletionSource.SetCanceled();
         }
         else
         {
             // Unexpected ThreadAbortException.
             taskCompletionSource.SetException(new AndroidBuildException(ex, androidBuildReport));
             DisplayBuildError("Exception", ex.ToString());
         }
     }
     catch (Exception ex)
     {
         taskCompletionSource.SetException(new AndroidBuildException(ex, androidBuildReport));
         DisplayBuildError("Exception", ex.ToString());
     }
 }
Exemplo n.º 4
0
 private void CreateBundleInternal <T>(
     TaskCompletionSource <T> taskCompletionSource,
     Func <string> createBundleFunc,
     T successResult,
     AndroidBuildReport androidBuildReport = null)
 {
     try
     {
         var errorMessage = createBundleFunc.Invoke();
         if (errorMessage == null)
         {
             taskCompletionSource.SetResult(successResult);
         }
         else
         {
             // Already logged.
             taskCompletionSource.SetException(new AndroidBuildException(errorMessage, androidBuildReport));
         }
     }
     catch (ThreadAbortException ex)
     {
         if (_canceled)
         {
             taskCompletionSource.SetCanceled();
         }
         else
         {
             // Unexpected ThreadAbortException.
             taskCompletionSource.SetException(new AndroidBuildException(ex, androidBuildReport));
             DisplayBuildError("Exception", ex.ToString());
         }
     }
     catch (Exception ex)
     {
         taskCompletionSource.SetException(new AndroidBuildException(ex, androidBuildReport));
         DisplayBuildError("Exception", ex.ToString());
     }
 }