/Unity5-AssetBundleSetting

AssetBundle setting for Unity5.x

Primary LanguageC#MIT LicenseMIT

AssetBundleSetting Tool for Unity 5.x

A tool which provides a simple editor setting to build assetbundles especially on Unity5.x.

 setting

It provides a simple editor tool to set various assetbundle options regardless of Unity's minor version so it works on any version of Unity5.x. and makes it easy to build assetbundles. If the version of Unity is 5.3.x, it provides ChunkBasedCompression option which is newly added on Unity 5.3.x.

Usage

  • Select 'Tools/AssetBundles/Create Build Setting' menu item.
  • Select the created 'AssetBundleBuildSetting.asset' setting file which is found under the 'Assets/AssetBundleManager/Editor' directory.
  • Set assetbundle options.
  • Set output directory where the created bundles are placed.
  • Build it!

Use 'OnPreBuildProcessor' and 'OnPostBuildProcessor' delegates if you have something to do befor or after building assetbundles. See 'ExternalProcessor' sample under the 'Samples' folder for more details.

    // Set the delegate if there is anything to do before building assetbundles.
    public delegate void OnPreBuildProcessorHandler(BundleBuilder builder);
    public static OnPreBuildProcessorHandler OnPreBuildProcessor;

    // Set the delegate if there is anything to do after building assetbundles.
    public delegate void OnPostBuildProcessorHandler(BundleBuilder builder);
    public static OnPostBuildProcessorHandler OnPostBuildProcessor;

You can also build assetbundle via commandline options with the following .bat file on windows:

@echo off
SET UNITY_BIN="C:\Program Files (x86)\Unity\Editor\Unity.exe"
SET PROJECT_PATH="PATH_YOUR_UNITY_PROJECT_WITHOUT_ASSETS_FOLDER"
%UNITY_BIN% -quit -batchmode -nographics -projectPath %PROJECT_PATH% -logFile bundlebuild_log.txt -executeMethod Commandline.BuildAssetbundles

See the Command line arguments page for more details.

Known Issues

  • Highly recommended to use on Unity 5.x. (may work on Unity 4.x but not recommended)
  • It does not contain any script to load assetbundles, See an asset bundle demo for Unity5 on bitbucket site or other stuff for that.
  • Duplicate a setting asset file if you need multiple settings for each of target platform.

Additional Notes

It is also available to mark an asset as an assetbunle by setting its name with AssetImporter.assetBundleName. Consider it to use spreadsheet or xml file for those configuration to do it as batching job instead of doing tedious thing like mouse click on every assets which are needed to be assetbundles.

The following codesnip shows to do that:

    [MenuItem("Tools/AssetBundles/Set AssetBundles from Spreadsheet", false, 0)]
    static void SetAssetBundlesFromSpreadsheet()
    {
        // Assume that each cells of the worksheet has path of an asset and a name of assetbundle
        foreach (string path in sheet.cells)
        {
            ...
            // Retrieve assetimporter for the given path
            AssetImporter assetImporter = AssetImporter.GetAtPath(path);

            // Specify bundle name for the asset.
            assetImporter.assetBundleName = asset.name;

            // Save the changes.
            assetImporter.SaveAndReimport();
            ...
        }
    }

See Unity-QuickSheet to get spreadsheet work with Unity.

References

Other Stuffs

  • AssetGraph - A visual toolset lets you configure and create Unity's AssetBundles. A toolset which uses different approach on handling AssetBundles.
  • BundleVersionChecker - Smart workaround to get Unity's bundle version information from PlayerSettings.bundleVersion in your source code by automatic code generation from a Unity editor class.

License

This code is distributed under the terms and conditions of the MIT license.

  • 'SerializableDictionary' code is borrowed from @vexe at here.
  • *'Utility.cs' code is borrowed from an asset bundle demo.

The license of the that follow those.

Copyright (c) 2016 Kim, Hyoun Woo