public static void Build()
    {
        ReadCommandLine();

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

        Directory.CreateDirectory(folderPath);
        Directory.CreateDirectory(k_TmpPath);

        IBundleBuildParameters buildParams = new BundleBuildParameters(EditorUserBuildSettings.activeBuildTarget, BuildTargetGroup.Unknown, folderPath);

        buildParams.TempOutputFolder = k_TmpPath;

        IBundleBuildContent buildContent = new BundleBuildContent(ContentBuildInterface.GenerateAssetBundleBuilds());
        IBundleBuildResults results;

        List <IBuildTask> taskList = DefaultBuildTasks.Create(DefaultBuildTasks.Preset.AssetBundleBuiltInShaderExtraction) as List <IBuildTask>;

        taskList.Add(new RefreshAssetDatabase());

        // we add a callback after generating information about how to build each bundle
        ContentPipeline.BuildCallbacks.PostPackingCallback += PostPackingCallback;

        ReturnCode exitCode = ContentPipeline.BuildAssetBundles(buildParams, buildContent, out results, taskList);

        Debug.Log("Building completed with " + exitCode);
    }
Esempio n. 2
0
    public static void Build()
    {
        if (Directory.Exists(folderPath))
        {
            Directory.Delete(folderPath, true);
        }
        if (Directory.Exists(k_TmpPath))
        {
            Directory.Delete(k_TmpPath, true);
        }

        Directory.CreateDirectory(folderPath);
        Directory.CreateDirectory(k_TmpPath);

        IBundleBuildParameters buildParams = new BundleBuildParameters(EditorUserBuildSettings.activeBuildTarget, BuildTargetGroup.Unknown, folderPath);

        buildParams.TempOutputFolder = k_TmpPath;

        IBundleBuildContent buildContent = new BundleBuildContent(ContentBuildInterface.GenerateAssetBundleBuilds());
        IBundleBuildResults results;

        List <IBuildTask> taskList = DefaultBuildTasks.Create(DefaultBuildTasks.Preset.AssetBundleBuiltInShaderExtraction) as List <IBuildTask>;

        taskList.Add(new RefreshAssetDatabase());
        taskList.Add(new CreateBuiltTimeReport());

        ReturnCode exitCode = ContentPipelineProfiled.BuildAssetBundles(buildParams, buildContent, out results, taskList, new Profiler("Total"));

        Debug.Log("Building completed with " + exitCode);
    }
Esempio n. 3
0
        public static void Build(Setting setting)
        {
            if (setting == null)
            {
                return;
            }

            var path = setting.BuildInfo.OutputPath;

            if (!Path.IsPathRooted(path))
            {
                path = Path.GetFullPath(Path.Combine(Application.dataPath, "..", path));
            }

            var buildContent = new BundleBuildContent(ContentBuildInterface.GenerateAssetBundleBuilds());
            var buildParam   = new BundleBuildParameters(setting.BuildInfo.Target, setting.BuildInfo.TargetGroup, path);

            buildParam.ScriptOptions     = ScriptCompilationOptions.None;
            buildParam.BundleCompression = UnityEngine.BuildCompression.LZ4;

            var settingContext = new LibCraftopiaSetting(setting);

            var tasks = BuildPipeline.CreatPipeline();

            var code = ContentPipeline.BuildAssetBundles(buildParam, buildContent, out var result, tasks, settingContext);

            if (code < 0)
            {
                UnityEngine.Debug.LogError("Build failed");
            }
        }
    /// <summary>
    /// The BundleBuildContent class contains information about all of the Assets you want to build into the BuildMap
    /// Assets are referenced to by a GUID object, and the Addresses can be obtained and modified by using a GUID to
    /// refer to each asset and identify its Address
    /// </summary>
    /// <param name="outputPath"></param>
    /// <param name="compressionMode"></param>
    /// <param name="buildTarget"></param>
    /// <param name="buildGroup"></param>
    /// <param name="results"></param>
    /// <returns></returns>
    public static ReturnCode BuildAssetBundles(string outputPath, CompressionType compressionMode, BuildTarget buildTarget, BuildTargetGroup buildGroup, out IBundleBuildResults results)
    {
        BundleBuildContent buildContent = new BundleBuildContent(ContentBuildInterface.GenerateAssetBundleBuilds());

        // Go through assets content and set their address to its filename
        for (int i = 0; i < buildContent.Assets.Count; ++i)
        {
            GUID g = buildContent.Assets[i];
            // Get the current address as the full filepath and change it to just be the filename
            buildContent.Addresses[g] = Path.GetFileNameWithoutExtension(buildContent.Addresses[g]);
        }

        BundleBuildParameters buildParams = new BundleBuildParameters(buildTarget, buildGroup, outputPath);

        switch (compressionMode)
        {
        case CompressionType.None:
            buildParams.BundleCompression = BuildCompression.Uncompressed;
            break;

        case CompressionType.Lz4:
            buildParams.BundleCompression = BuildCompression.LZ4;
            break;

        default:
            buildParams.BundleCompression = BuildCompression.LZMA;
            break;
        }

        return(ContentPipeline.BuildAssetBundles(buildParams, buildContent, out results));
    }
    /// <summary>
    /// Using the Compatible code path, this setup is limited to be the same as legacy pipeline.
    /// With this setup an array of content for each AssetBundle is passed into the pipeline.
    /// ContentBuildInterface.GeneratAssetBundleBuilds can be used to get an array for the bundleNames
    /// set in the AssetImporters in your project (as seen at the bottom of the inspector when selecting an asset)
    /// There are two arrays,
    /// .assetNames which contains the fullpath to the Asset to be included
    /// .addressableNames which is the string used when loading the Asset.
    /// These are connected by index, so assigning .addressableNames[8] = "Robo" is assigning the asset at .assetNames[8]
    /// to load via AssetBundle.LoadAsset<T>( "Robo" );
    /// </summary>
    /// <param name="outputPath"></param>
    /// <param name="forceRebuild"></param>
    /// <param name="compression"></param>
    /// <param name="buildTarget"></param>
    /// <returns></returns>
    public static bool BuildCompatibilityAssetBundles(string outputPath, bool forceRebuild, CompressionType compression, BuildTarget buildTarget)
    {
        var options = BuildAssetBundleOptions.None;

        switch (compression)
        {
        case CompressionType.None:
            options |= BuildAssetBundleOptions.UncompressedAssetBundle;
            break;

        case CompressionType.Lz4:
            options |= BuildAssetBundleOptions.ChunkBasedCompression;
            break;
        }

        if (forceRebuild)
        {
            options |= BuildAssetBundleOptions.ForceRebuildAssetBundle;
        }

        AssetBundleBuild[] bundles = ContentBuildInterface.GenerateAssetBundleBuilds();

        // go through each asset in the bundle and assign the addressable name to filename
        for (int i = 0; i < bundles.Length; i++)
        {
            bundles[i].addressableNames = bundles[i].assetNames.Select(Path.GetFileNameWithoutExtension).ToArray();
        }

        var manifest = CompatibilityBuildPipeline.BuildAssetBundles(outputPath, bundles, options, buildTarget);

        return(manifest != null);
    }
    public static void Build()
    {
        var buildContent = new BundleBuildContent(ContentBuildInterface.GenerateAssetBundleBuilds());
        var buildParams  = new CustomBuildParameters(EditorUserBuildSettings.activeBuildTarget, EditorUserBuildSettings.selectedBuildTargetGroup, "Assets/StreamingAssets");

        // set three different Assetbundles to be the different compression options available
        buildParams.m_PerBundleCompression.Add("textures", BuildCompression.LZMA);
        buildParams.m_PerBundleCompression.Add("objects", BuildCompression.LZ4);
        buildParams.m_PerBundleCompression.Add("prefabs", BuildCompression.Uncompressed);

        buildParams.BundleCompression = BuildCompression.LZMA;

        IBundleBuildResults results;
        ReturnCode          exitCode = ContentPipeline.BuildAssetBundles(buildParams, buildContent, out results);

        Debug.Log("Building per bundle completed with " + exitCode);
    }
        static void Build(string folder, BuildTarget target)
        {
            var bundles = ContentBuildInterface.GenerateAssetBundleBuilds();

            for (var i = 0; i < bundles.Length; i++)
            {
                bundles[i].addressableNames = bundles[i].assetNames.Select(Path.GetFileNameWithoutExtension).ToArray();
            }

            var result = CompatibilityBuildPipeline.BuildAssetBundles($"{Application.streamingAssetsPath}", BuildAssetBundleOptions.None,
                                                                      target);
            var manifest = new HybirdResManifest();

            var createdBundeNames = result.GetAllAssetBundles();

            foreach (var bunde in createdBundeNames)
            {
                HybirdRes res = new HybirdRes();

                res.Name = bunde;

                res.Crc        = result.GetAssetBundleCrc(bunde);
                res.Dependence = result.GetAllDependencies(bunde);

                manifest.Res[bunde] = res;
            }

            var resPath  = Application.streamingAssetsPath;
            var infoPath = Path.Combine(resPath, "res.manifest");
            var json     = LitJson.JsonMapper.ToJson(manifest);

            File.WriteAllText(infoPath, json);

            if (File.Exists($"{resPath}/StreamingAssets.manifest"))
            {
                File.Delete($"{resPath}/StreamingAssets.manifest");
            }

            AssetDatabase.Refresh();
        }
    static AssetBundleBuild[] SetupBundles()
    {
        var content = ContentBuildInterface.GenerateAssetBundleBuilds();

        // Add another AssetBundle with the URP shaders
        Array.Resize(ref content, content.Length + 1);
        content[content.Length - 1].assetBundleName = k_UrpBundleName;

        // Only include the Lit shader for faster builds
        content[content.Length - 1].assetNames = new string[] { "Packages/com.unity.render-pipelines.universal/Shaders/Lit.shader" };

        // Uncomment these lines to include all shaders from URP
        //var urpShaders = AssetDatabase.FindAssets("t:shader", new string[] { "Packages/com.unity.render-pipelines.universal/Shaders" });
        //var shaderAssetNames = new List<String>();
        //foreach (var guid in urpShaders)
        //{
        //    shaderAssetNames.Add(AssetDatabase.GUIDToAssetPath(guid));
        //}
        //content[content.Length - 1].assetNames = shaderAssetNames.ToArray();

        return(content);
    }
Esempio n. 9
0
    public static void Build()
    {
        var buildContent = new BundleBuildContent(ContentBuildInterface.GenerateAssetBundleBuilds());
        var buildParams  = new CustomBuildParameters(EditorUserBuildSettings.activeBuildTarget, EditorUserBuildSettings.selectedBuildTargetGroup, "Assets/StreamingAssets");

        // This is a part of the CustomBuildParameters class that override the outputFolder on a per AssetBundle basic
        buildParams.m_PerBundleBuildFolder.Add("textures", "Assets/StreamingAssets/OtherFolder");

        // This is a part of the CustomBuildParameters class that ignores the outputFolder, and gives a direct location, including the filename. On a per AssetBundle basic
        buildParams.m_PerBundleAbsolutePath.Add("prefabs", Application.dataPath.Substring(0, Application.dataPath.Length - 6) + "myPrefabObjects.ab");

        buildParams.BundleCompression = BuildCompression.LZMA;

        List <IBuildTask> taskList = DefaultBuildTasks.Create(DefaultBuildTasks.Preset.AssetBundleBuiltInShaderExtraction) as List <IBuildTask>;

        //taskList.Add( new MoveAssetBundles() ); // no longer needed from "1.2.3-preview" as can use
        taskList.Add(new RefreshAssetDatabase());

        IBundleBuildResults results;
        ReturnCode          exitCode = ContentPipeline.BuildAssetBundles(buildParams, buildContent, out results, taskList);

        Debug.Log("Building per bundle completed with " + exitCode);
    }
    public static ReturnCode BuildAssetBundles(string outputPath, CompressionType compressionMode, BuildTarget buildTarget, BuildTargetGroup buildGroup, out IBundleBuildResults results)
    {
        BundleBuildContent    buildContent = new BundleBuildContent(ContentBuildInterface.GenerateAssetBundleBuilds());
        BundleBuildParameters buildParams  = new BundleBuildParameters(buildTarget, buildGroup, outputPath);

        SetupBuildCacheServer(buildParams);

        switch (compressionMode)
        {
        case CompressionType.None:
            buildParams.BundleCompression = BuildCompression.Uncompressed;
            break;

        case CompressionType.Lz4:
            buildParams.BundleCompression = BuildCompression.LZ4;
            break;

        default:
            buildParams.BundleCompression = BuildCompression.LZMA;
            break;
        }

        return(ContentPipeline.BuildAssetBundles(buildParams, buildContent, out results));
    }
Esempio n. 11
0
        //----- method -----

        /// <summary> 全アセットバンドルをビルド </summary>
        public BuildResult Build(string outputPath)
        {
            var buildMap = ContentBuildInterface.GenerateAssetBundleBuilds();

            return(Build(outputPath, buildMap));
        }
Esempio n. 12
0
        static void BuildAssetBundles(BuildTarget target, BuildTargetGroup group, DirectoryInfo outputDirectory)
        {
            var buildInput = ContentBuildInterface.GenerateAssetBundleBuilds().ToList();

            if (Data.WeaverCoreOnly)
            {
                buildInput.RemoveAll(i => i.assetBundleName != "weavercore_bundle");
            }

            foreach (var bundleInput in buildInput)
            {
                Debug.Log("Found Asset Bundle -> " + bundleInput.assetBundleName);
            }

            Assembly scriptBuildAssembly = null;

            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                if (assembly.GetName().Name == "Unity.ScriptableBuildPipeline.Editor")
                {
                    scriptBuildAssembly = assembly;
                    break;
                }
            }

            if (scriptBuildAssembly == null)
            {
                throw new Exception("The Scriptable Build Pipeline is currently not installed. This is required to build WeaverCore AssetBundles");
            }

            var contentPipelineT = scriptBuildAssembly.GetType("UnityEditor.Build.Pipeline.ContentPipeline");

            var buildAssetBundlesF = contentPipelineT.GetMethods().FirstOrDefault(m => m.GetParameters().Length == 3);

            var bundleBuildParametersT = scriptBuildAssembly.GetType("UnityEditor.Build.Pipeline.BundleBuildParameters");

            var buildParameters = Activator.CreateInstance(bundleBuildParametersT, new object[] { target, group, outputDirectory.FullName });

            bundleBuildParametersT.GetProperty("BundleCompression").SetValue(buildParameters, UnityEngine.BuildCompression.LZ4);

            var bundleBuildContentT = scriptBuildAssembly.GetType("UnityEditor.Build.Pipeline.BundleBuildContent");

            var bundleBuildContent = Activator.CreateInstance(bundleBuildContentT, new object[] { buildInput });

            var parameters = new object[] { buildParameters, bundleBuildContent, null };

            var code = buildAssetBundlesF.Invoke(null, parameters);

            var codeType = code.GetType();

            var codeName = Enum.GetName(codeType, code);

            //Debug.Log("Code Name = " + codeName);
            switch (codeName)
            {
            case "Success":
                break;

            case "SuccessCached":
                break;

            case "SuccessNotRun":
                break;

            case "Error":
                throw new BundleException("An error occured when creating an asset bundle");

            case "Exception":
                throw new BundleException("An exception occured when creating an asset bundle");

            case "Canceled":
                throw new BundleException("The asset bundle build was cancelled");

            case "UnsavedChanges":
                throw new BundleException("There are unsaved changes, be sure to save them and try again");

            case "MissingRequiredObjects":
                throw new BundleException("Some required objects are missing");

            default:
                break;
            }



            /*var code = ContentPipeline.BuildAssetBundles(new BundleBuildParameters(target, BuildTargetGroup.Standalone, targetFolder.FullName)
             * {
             *      BundleCompression = UnityEngine.BuildCompression.LZ4,
             * }, new BundleBuildContent(buildInput), out var results);*/

            /*switch (code)
             * {
             *      case ReturnCode.Success:
             *              break;
             *      case ReturnCode.SuccessCached:
             *              break;
             *      case ReturnCode.SuccessNotRun:
             *              break;
             *      case ReturnCode.Error:
             *              throw new BundleException("An error occured when creating an asset bundle");
             *      case ReturnCode.Exception:
             *              throw new BundleException("An exception occured when creating an asset bundle");
             *      case ReturnCode.Canceled:
             *              throw new BundleException("The asset bundle build was cancelled");
             *      case ReturnCode.UnsavedChanges:
             *              throw new BundleException("There are unsaved changes, be sure to save them and try again");
             *      case ReturnCode.MissingRequiredObjects:
             *              throw new BundleException("Some required objects are missing");
             *      default:
             *              break;
             * }*/
        }
        /// <summary>
        /// Wrapper API to match BuildPipeline API but use the Scriptable Build Pipeline to build Asset Bundles.
        /// <seealso cref="BuildPipeline.BuildAssetBundles(string, BuildAssetBundleOptions, BuildTarget)"/>
        /// </summary>
        /// <remarks>
        /// Not all BuildAssetBundleOptions are supported in the Scriptable Build Pipeline initial release.
        /// Supported options are: ChunkBasedCompression, UncompressedAssetBundle, DisableWriteTypeTree, and DisableWriteTypeTree.
        /// In addition, existing BuildPipeline callbacks are not yet supported. Est: 2018.3 release for support.
        /// </remarks>
        /// <param name="outputPath">Output path for the AssetBundles.</param>
        /// <param name="assetBundleOptions">AssetBundle building options.</param>
        /// <param name="targetPlatform">Chosen target build platform.</param>
        /// <returns>null - Generating and returning an AssetBundleManifest is not yet supported by the Scriptable Build Pipeline. Est: 2018.3 support.</returns>
        public static CompatibilityAssetBundleManifest BuildAssetBundles(string outputPath, BuildAssetBundleOptions assetBundleOptions, BuildTarget targetPlatform)
        {
            var buildInput = ContentBuildInterface.GenerateAssetBundleBuilds();

            return(BuildAssetBundles_Internal(outputPath, new BundleBuildContent(buildInput), assetBundleOptions, targetPlatform));
        }