Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Arcanor · Jun 20, 2015 at 03:19 PM · unity 5assetbundledllassemblyrename

in Unity 5, how can I get/set an asset's AssetBundle assignment via scripting?

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 and http://docs.unity3d.com/Manual/scriptsinassetbundles.html

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()). 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();
         }
     }
 }


Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
9
Best Answer

Answer by Arcanor · Jun 21, 2015 at 12:51 AM

I've discovered the answer to my own question. I did miss some things in the API, so it is possible to get/set the assetbundle information from script.

Here is some example code, if anyone else is interested.

         foreach (var assetGuid in AssetDatabase.FindAssets(""))
         {
             string assetPath = AssetDatabase.GUIDToAssetPath(assetGuid);
             string bundleName = AssetImporter.GetAtPath(assetPath).assetBundleName;
             if (string.IsNullOrEmpty(bundleName))
             {
                 continue;
             }
             Debug.Log("Found asset: (GUID:<color=#00ffffff>" + assetGuid + "</color>) " + assetPath + ", AssetBundle: " + bundleName);
         }
 

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image twobob · Dec 15, 2015 at 03:50 PM 0
Share
 using UnityEngine;
 using UnityEditor;
 using System.Collections;
 
 public class ListBundles : $$anonymous$$onoBehaviour
 {
     [$$anonymous$$enuItem("Assets/AssetBundles/List AssetBundles %#l")]
     static void List()
     {
 
         Debug.Log("<color=#ffff00ff>Search Initialising</color>, Please be patient");
         string assetPath = string.Empty;
         string bundleName = string.Empty;
         foreach (var assetGuid in AssetDatabase.FindAssets(""))
         {
             assetPath = AssetDatabase.GUIDToAssetPath(assetGuid);
             bundleName = AssetImporter.GetAtPath(assetPath).assetBundleName;
             if (string.IsNullOrEmpty(bundleName))
             {
                 continue;
             }
             Debug.Log("Found asset: (GUID:<color=#00ffffff>" + assetGuid + "</color>) " + assetPath + ", AssetBundle: " + bundleName);
         }
     }
 }


Thanks for this.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to auto find a component inside an assembly (dll)? 0 Answers

Unity android application custom dll problem 1 Answer

Script Import AssetBundle: ClassDerivedFromMonoBehaviour? 2 Answers

MonoBehaviour from DLL in AssetBundle Reflection problem 3 Answers

Why does Assembly-CSharp reference UnityEditor.dll 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges