/Unity-Assetbundles-CLI-Example

A sweet demonstration of using assetbundles in unity via command line

Primary LanguageC#

Unity-Assetbundles-CLI-Example

A sweet example of using assetbundles in unity

Purpose: Using Command line construct different Assetbundles after copying different assets into project folder


How to Use

Before you clone project and start, you may need to change:

  1. Create An folder to store assetbundles, named what ever you like

  2. Open Unity Project "Instantiate Assetbundles", Click "Main Camera", you'll find a component called "test(Script)" in Inspector, change the paramter to the path of the folder you just create. However leave /testbundle at bottom.

  3. Open "buildAssetbundle.bat" and modified parameters above

SET UNITYPATH= Where you installed Unity
SET CREATEPROJECTPATH= Path of project "Create Asset bundles"
SET BUILDPATH= Path of builds of project "Create Asset bundles"
SET UNITYUSER= you Unity Account
  1. Done

Demo

  1. Click "buildAssetbundle.bat", wait for console disappear (it may last for seconds)

  2. open the build path, you shall see a folder "StreamingAssets", copy the file "testbundle" and "testbundle.manifest" into the folder you created in Step 1 in "Before you clone..."
    (Or you may change the parameter in Step2 in "Before you clone..." to your_build_path/StreamingAssets/testbundle, though I don't recommend it)

  3. Build Unity Project "Instantiate Assetbundles" (this step only need to be done once), Open executable build, you will see a big white covered model in the scene.

  4. (Optional) Usage :
    4-1. copy you model into path_of_"Create Asset bundles"/Assets/Pinocchio.fbx
    4-2. click "buildAssetbundle.bat", copy path_of_build_of_"Create Asset bundles"/StreamingAssets/testbundle to parameters you've set in Step2 in "Before you clone..."
    4-3. open "Instantiate Assetbundles" executables, you will see another model

How it's Done

Well, it it no big deal but using unity command line parameter : -executeMethod, this parameter allows you executing Editor class function when compiling.

Special Thanks

Mr. 秉宜