Quantcast
Channel: Questions in topic: "dll"
Viewing all articles
Browse latest Browse all 706

Importing scripts through Asset bundles

$
0
0
I am trying to load new scripts through asset bundles. By reading the manual on this topic this is what i did: I created a .dll file for test purposes(pre-compiled assembly means .dll file, right?) This is the content of that .dll file using System; namespace TestLibrary{ public class MyClass{ public string str = "If u see me, DLL thing works"; public MyClass (){} } } I copied this file in my unity assets folder and tried to export this as an asset bundle but this warning came up > Unrecognized assets cannot be included in AssetBundle: "Assets/TestLibrary.dll". I changed the file extension from .dll to .txt and built it again(Could this mess things up?) Here is my code for building the assetbundle (I kind of copied this from a source I am not exactly sure how each of this parts work): static void ExportResource2(){ string path = "AssetBundles/scriptbundle01.unity3d"; Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets); BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets); } I loaded the asset bundle and tried to load a class from it (even though the class does nothing right now) I followed the code from the manual: IEnumerator Start () { // Start a download of the given URL Caching.CleanCache(); WWW www = WWW.LoadFromCacheOrDownload (url, 0); while(!www.isDone){ yield return null; } // Wait for download to complete Debug.Log("asda"); // Load and retrieve the AssetBundle AssetBundle bundle = www.assetBundle; // Load the TextAsset object TextAsset txt = bundle.LoadAsset("TestLibrary.txt", typeof(TextAsset)) as TextAsset; // Load the assembly and get a type (class) from it var assembly = System.Reflection.Assembly.Load(txt.bytes); Type type = assembly.GetType("MyClass"); Activator.CreateInstance(type); Debug.Log(type.Name); } I have replaced bundle.Load() with bundle.LoadAsset() as the prior is deprecated. It generates the following error: > BadImageFormatException I am not sure whet exactly are the mistakes i am making. Any kind of help will be very much appreciated. Also, How am I supposed to get the reference to that string in the "MyClass" dll from my unity code if the class would ever instantiate... One last thing if i want to include Monobehaviour classes in my dll should reference to UnityEngine be enough?

Viewing all articles
Browse latest Browse all 706

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>