private void DoBuildPlatform(ResourcePlatform targetPlatform,
                                     bool cleanUpWorkingDirectoryAfterBuild,
                                     bool autoIncVersion,
                                     int overriddenResourceVersion,
                                     BuildAssetBundleOptions buildOptions,
                                     IAssetBundleBuilderHandler handler,
                                     Logger logger, AssetBundleBuild[] buildMaps,
                                     IDictionary <string, AssetBundleInfo> assetBundleInfos,
                                     IDictionary <string, AssetInfo> assetInfos
                                     )
        {
            int resourceVersion = overriddenResourceVersion > 0 ? overriddenResourceVersion : GetInternalResourceVersion(PlayerSettings.bundleVersion, targetPlatform);

            logger.Info("Internal resource version for bundle version '{0}' and target platform '{1}' is {2}.",
                        PlayerSettings.bundleVersion, targetPlatform, resourceVersion);
            CallHandlerOnPreBuildPlatform(handler, logger, targetPlatform, resourceVersion);

            logger.Info("Start building for '{0}' target.", targetPlatform);
            logger.Info("Start building asset bundles.");
            var manifest = BuildAssetBundles(buildMaps, targetPlatform, buildOptions);

            if (manifest == null)
            {
                logger.Error("Failed to build asset bundles for '{0}' target.", targetPlatform);
            }

            logger.Info("Finish building asset bundles.");

            if (cleanUpWorkingDirectoryAfterBuild)
            {
                logger.Info("Start cleaning up internal directory.");
                CleanUpInternalDirectory(targetPlatform, assetBundleInfos);
                logger.Info("Finish cleaning up internal directory.");
            }

            logger.Info("Start generating information used to build the index file.");
            IList <AssetBundleInfoForIndex> assetBundleInfosForIndex =
                GenerateAssetBundleInfosForIndex(assetBundleInfos, manifest, targetPlatform);

            logger.Info("Finish generating information used to build the index file.");

            logger.Info("Start generating output.");
            GenerateOutput(PlayerSettings.bundleVersion, targetPlatform, resourceVersion,
                           assetBundleInfosForIndex, assetInfos);
            logger.Info("Finish generating output.");

            var currentResourceVersion = resourceVersion;

            if (autoIncVersion && overriddenResourceVersion <= 0)
            {
                SetInternalResourceVersion(PlayerSettings.bundleVersion, targetPlatform, resourceVersion + 1);
                logger.Info("Increment internal resource version for next build.");
            }

            logger.Info("Finish building for '{0}' target.", targetPlatform);

            CallHandlerOnPostBuildPlatform(handler, logger, targetPlatform, currentResourceVersion, OutputDirectory);
        }
 private static void CallHandlerOnPostBeforeBuild(IAssetBundleBuilderHandler handler, Logger logger, AssetBundleBuild[] assetBundleBuilds)
 {
     try
     {
         logger.Info("Trigger OnPostBeforeBuild in handler.");
         handler.OnPostBeforeBuild(assetBundleBuilds);
     }
     catch (Exception e)
     {
         logger.Error($"Exception from OnPreBeforeBuild: {e}");
     }
 }
 private static void CallHandlerOnBuildSuccess(IAssetBundleBuilderHandler handler, Logger logger)
 {
     try
     {
         logger.Info("Trigger OnBuildSuccess in handler.");
         handler.OnBuildSuccess();
     }
     catch (Exception e)
     {
         logger.Error($"Exception from OnBuildSuccess: {e}");
     }
 }
 private void CallHandlerOnPostBuildPlatform(IAssetBundleBuilderHandler handler, Logger logger, ResourcePlatform resourcePlatform,
                                             int internalResourceVersion, string outputDirectory)
 {
     try
     {
         logger.Info("Trigger OnPostBuildPlatform in handler.");
         handler.OnPostBuildPlatform(resourcePlatform, internalResourceVersion, outputDirectory);
     }
     catch (Exception e)
     {
         logger.Error($"Exception from OnPostBuildPlatform: {e}");
     }
 }
        private IDictionary <string, AssetBundleInfo> BeforeBuild(IAssetBundleBuilderHandler handler, Logger logger,
                                                                  out IDictionary <string, AssetInfo> assetInfos,
                                                                  out AssetBundleBuild[] buildMaps)
        {
            CallHandlerOnPreBeforeBuild(handler, logger);
            logger.Info("Start populating asset bundle infos.");
            var provider         = PopulateAssetBundleInfos();
            var assetBundleInfos = provider.AssetBundleInfos;

            assetInfos = provider.AssetInfos;
            logger.Info("Finish populating asset bundle infos.");

            logger.Info("Start generating unity build maps.");
            buildMaps = GenerateBuildMaps(assetBundleInfos);
            logger.Info("Finish generating unity build maps.");
            CallHandlerOnPostBeforeBuild(handler, logger, buildMaps);
            return(assetBundleInfos);
        }