3

I am developing an application in Unity where users can upload their own 3d-models. I have been searching for ways to implement this and the best way to load models from all types seems to be asset bundles. To create these bundles on a server i want to run Unity in batch mode and create the bundles from a static method.

The problem I'm facing is that it seems to be impossible to include objects in a asset bundle from script. In the editor you just select the asset bundle name but to automate this, that won't be possible.

4

1 回答 1

1

Found the answer using the AssetImporter as i intended in the first place. For some reason I tought I had to instantiate the object in order to bundle it. That was a false assumption and by just adding the project path you can assign a bundlename to a asset.

    foreach (string file in filesInFolder)
    {
        if (!file.Contains(".meta"))
        {
            AssetImporter importer = AssetImporter.GetAtPath("Assets/models/" + file);
            if (importer != null)
            {
                importer.assetBundleName = BundleName;
                Debug.Log("assetBundlesAssigned");

            }
            else
            {
                Debug.Log("No asset selected");
                complete = false;
            }
        }
    }

When all the assets are assigned you can build them as usual like so.

public static void ExecBuildAssetBundles()
{
    Debug.Log("Building bundle");
    BuildPipeline.BuildAssetBundles("Assets/AssetBundles", BuildAssetBundleOptions.None, BuildTarget.Android);
}
于 2017-09-19T14:09:20.043 回答