This method is not allowed under iOS and can only be used under Android. It is also very convenient to use.
1, first create a C # project, the reference to the UnityEngine.dll in Unity's installation directory to find it
2, put the compiled DLL into Unity Project, and play into Assetbundle. (To change the prefix name to. Bytes, this type of unity is recognized before it can be called assetbundle)
Play Bundle code
#if Unity_editor[menuitem ("Gameobject/buildasset")]static void Buildasset () {var se = selection.getfiltered (typeof ( Object), Selectionmode.deepassets), foreach (Var o in se) {string sp = Assetdatabase.getassetpath (o); string tar = Applicati On.streamingassetspath + "/" + O.name + ". Unity3d"; Buildpipeline.buildassetbundle (o, null, tar, buildassetbundleoptions.collectdependencies,buildtarget.android)) { Debug.Log (TAR);}} Assetdatabase.refresh ();} #endif
Right-click Resources, there is buildasset
Bundles will generate streamingassets.
3. Write test code
usingSystem.Collections;usingSystem.Collections.Generic;#ifUnity_editorusingUnityeditor;#endifusingUnityengine; Public classtestgame:monobehaviour{//Use this for initialization voidStart () {}//Update is called once per frame voidUpdate () {} IEnumerator Load () {#ifUnity_editorvarPath ="file://"+ Application.streamingassetspath +"/"+"ReflectTest.dll.unity3d";#else#ifUnity_androidvarPath ="jar:file://"+ Application.datapath +"!/assets/"+"ReflectTest.dll.unity3d";#elifUnity_iosvarPath = Application.datapath +"/raw/"+"ReflectTest.dll.unity3d";#endif#endif //var path = "File://"+application.streamingassetspath +"/"+" Helipadescapegame.unity3d ";Debug.Log ("path="+path); using(WWW www =NewWWW (path)) { yield returnwww; varTex = www.assetbundle.loadasset<textasset> ("ReflectTest.dll"); //var tex = www.assetbundle.loadasset<textasset> ("Helipadescapegame"); varTheSystem.Reflection.Assembly.Load (tex.bytes); varType =. GetType ("Class1"); Gameobject.addcomponent (type); } }#ifUnity_editor[MenuItem ("Assets/buildasset")] Static voidBuildasset () {varSE = selection.getfiltered (typeof(Object), selectionmode.deepassets); foreach(varOinchse) { stringSP =Assetdatabase.getassetpath (o); stringtar = Application.streamingassetspath +"/"+ O.name +". Unity3d"; if(! Buildpipeline.buildassetbundle (O,NULL, Tar, buildassetbundleoptions.collectdependencies,buildtarget.android)) {Debug.Log (TAR); }} assetdatabase.refresh (); }#endif voidOngui () {if(GUI. Button (NewRect (0,0, $, $),"Load") {startcoroutine (Load ())); } }}
Unity3d Android Dynamic Reflection loading assemblies