Example #1
0
        private static ReturnCode BuildInternal(
            OwlcatModificationManifest manifest,
            Modification.SettingsData settings,
            string sourceFolder,
            string targetFolder,
            params IContextObject[] contextObjects)
        {
            if (!Path.IsPathRooted(targetFolder))
            {
                targetFolder = Path.Combine(Path.Combine(Application.dataPath, ".."), targetFolder);
            }

            string intermediateBuildFolder = Path.Combine(targetFolder, BuilderConsts.Intermediate);

            if (Directory.Exists(targetFolder))
            {
                Directory.Delete(targetFolder, true);
            }

            Directory.CreateDirectory(intermediateBuildFolder);

            string logFilepath             = Path.Combine(targetFolder, "build.log");
            var    defaultBuildTarget      = EditorUserBuildSettings.activeBuildTarget;
            var    defaultBuildTargetGroup = BuildTargetGroup.Standalone;
            var    defaultBuildOptions     = EditorUserBuildSettings.development
                                ? ScriptCompilationOptions.DevelopmentBuild
                                : ScriptCompilationOptions.None;

            UglySBPHacks.ThreadingManager_WaitForOutstandingTasks();
            AssetDatabase.SaveAssets();

            var buildContext    = new BuildContext(contextObjects);
            var buildParameters = buildContext.EnsureContextObject <IBundleBuildParameters>(
                () => new BundleBuildParameters(defaultBuildTarget, defaultBuildTargetGroup, intermediateBuildFolder)
            {
                BundleCompression = BuildCompression.LZ4,
                ScriptOptions     = defaultBuildOptions,
                UseCache          = false,
            });

            contextObjects = (contextObjects ?? new IContextObject[0]).Concat(new IContextObject[]
            {
                buildParameters,
                buildContext.EnsureContextObject <IBundleLayoutManager>(() => new DefaultBundleLayoutManager()),
                buildContext.EnsureContextObject <IModificationRuntimeSettings>(() => new DefaultModificationRuntimeSettings()),
                buildContext.EnsureContextObject(() => new BuildInterfacesWrapper()),
                buildContext.EnsureContextObject <IBuildLogger>(() => new BuildLoggerFile(logFilepath)),
                buildContext.EnsureContextObject <IProgressTracker>(() => new ProgressLoggingTracker()),
                buildContext.EnsureContextObject <IDependencyData>(() => new BuildDependencyData()),
                buildContext.EnsureContextObject <IBundleWriteData>(() => new BundleWriteData()),
                buildContext.EnsureContextObject <IBundleBuildResults>(() => new BundleBuildResults()),
                buildContext.EnsureContextObject <IDeterministicIdentifiers>(() => new Unity5PackedIdentifiers()),
                buildContext.EnsureContextObject <IBundleBuildContent>(()
                                                                       => new BundleBuildContent(Enumerable.Empty <AssetBundleBuild>())),
                buildContext.EnsureContextObject <IBuildCache>(
                    () => new BuildCache(buildParameters.CacheServerHost, buildParameters.CacheServerPort)),
                buildContext.EnsureContextObject <IModificationParameters>(
                    () => new DefaultModificationParameters(manifest, settings, sourceFolder)),
            }).ToArray();

            var tasksList = GetTasks().ToArray();

            try
            {
                return(RunTasks(tasksList, buildContext));
            }
            finally
            {
                Dispose(contextObjects, tasksList);
            }
        }