I'm trying to use the new 5.x way of doing things in creating assetbundles, as per [http://docs.unity3d.com/Manual/BuildingAssetBundles5x.html][1]
and
[http://docs.unity3d.com/Manual/scriptsinassetbundles.html][2]
I'm running into difficulties with including script dll assemblies in these bundles. The assemblies themselves work fine. I'm only having a problem including them in assetbundles.
If I simply use the editor to set an AssetBundle name, then call BuildPipeline.BuildAssetBundles("path"), I get an error saying that DLL files are "unrecognized", and cannot be included.
To deal with this problem, I've created logic to rename the DLL files as BYTES files (using [System.IO.File.Move()][3]). This is where the unresolved problem comes in... when I rename the file via script, the AssetBundle that I'd previously designated in the editor is reset to 'None', so when I subsequently call BuildAssetBundles(), these DLLs (now renamed as BYTES files) are not getting included in any of the bundles that are being created.
How can I use C# scripting to get/set/preserve the AssetBundle assignment as set in the editor? I didn't see any API functions that I'd hoped for such as maybe AssetDatabase.AddFileToAssetBundle(), or some such. Did I miss something?
Thanks in advance!
----------
PS - In case it helps, here is the code I'm using to rename the DLLs and (trying unsuccessfully to) create the bundles:
using UnityEngine;
using UnityEditor;
using System.IO;
public class CreateAssetBundles
{
[MenuItem("Assets/Build AssetBundles")]
static void BuildAllAssetBundles()
{
RenameAllPluginsDllToBytes();
Debug.Log("Exporting all assetbundles...");
BuildPipeline.BuildAssetBundles("AssetBundles");
RenameAllPluginsBytesToDll();
}
[MenuItem("Assets/Rename all Plugins DLLs to 'bytes'")]
static void RenameAllPluginsDllToBytes()
{
Debug.Log("Renaming all '*.dll' files in Assets/Plugins to '.bytes' extension.");
string pluginsFolderName = Application.dataPath + "/Plugins";
var dirInfo = new DirectoryInfo(pluginsFolderName);
var allFileInfos = dirInfo.GetFiles("*.dll", SearchOption.AllDirectories);
foreach (var fileInfo in allFileInfos)
{
if (Path.GetExtension(@fileInfo.FullName) != ".dll")
{
Debug.LogWarning("Ignoring: '" + @fileInfo.FullName + "'");
continue;
}
string newfilename = Path.ChangeExtension(@fileInfo.FullName, ".bytes");
//Debug.Log("Renaming '" + @fileInfo.FullName + "' to '" + @newfilename + "'");
File.Move(@fileInfo.FullName, @newfilename);
AssetDatabase.Refresh();
}
}
[MenuItem("Assets/Rename all Plugins BYTES to 'dll'")]
static void RenameAllPluginsBytesToDll()
{
Debug.Log("Renaming all '*.bytes' files in Assets/Plugins to '.dll' extension.");
string pluginsFolderName = Application.dataPath + "/Plugins";
var dirInfo = new DirectoryInfo(pluginsFolderName);
var allFileInfos = dirInfo.GetFiles("*.bytes", SearchOption.AllDirectories);
foreach (var fileInfo in allFileInfos)
{
string newfilename = Path.ChangeExtension(@fileInfo.FullName, ".dll");
//Debug.Log("Renaming '" + @fileInfo.FullName + "' to '" + @newfilename + "'");
File.Move(@fileInfo.FullName, @newfilename);
AssetDatabase.Refresh();
}
}
}
[1]: http://docs.unity3d.com/Manual/BuildingAssetBundles5x.html
[2]: http://docs.unity3d.com/Manual/scriptsinassetbundles.html
[3]: https://msdn.microsoft.com/en-us/library/system.io.file.move%28v=vs.90%29.aspx
↧