The simplest case code, which needs to be used after preparation
Using System.Collections;
Using System.Collections.Generic;
Using System.Xml;
Using Unityengine;
Using System.Reflection;
Using System.IO;
Using System;
<summary>
Load Web Code
</summary>
public class Loadwebscript:monobehaviour {
Static Loadwebscript _instance;
public static Loadwebscript Instance {
Get
{
if (_instance! = null)
{
return _instance;
}
else {
Gameobject g = new Gameobject ("Loadweb");
return g.addcomponent<loadwebscript> ();
}
}
}
<summary>
Code Network Address
</summary>
public string NetPath {
get {
XmlDocument doc = new XmlDocument ();
Doc. Load (application.streamingassetspath+ "/webconfig/webconfig.xml");
XmlElement list= Doc. DocumentElement;
XmlElement ele = (XmlElement) list. selectSingleNode ("remote");
String path = Ele. GetAttribute ("path");
if (string. IsNullOrEmpty (Scriptspacename)) {
Scriptspacename = Ele. GetAttribute ("script");
}
return path;
}
}
private string Scriptspacename;
private string ScriptFullName {
get {
return Scriptspacename + ". dll";
}
}
private string Outscriptpath {
get {
return Application.streamingassetspath + "/outscript/";
}
}
private void Awake ()
{
Startcoroutine (Updatescript ());
}
IEnumerator Updatescript () {
Print (NetPath);
www www = new www (netpath+ "/" +scriptfullname);
yield return www;
if (www.error! = null)
{
Debug.logwarning (Www.error);
Load ();
}
Else
{
Startcoroutine (Savescript (www.bytes,Load));
}
}
IEnumerator savescript (byte[] B,action Act) {
FileStream fs = File.Open (Outscriptpath+scriptfullname, FileMode.Create);
Fs. Write (b, 0, b.length);
Yield return FS;
Fs. Close ();
Act. Invoke ();
}
private void Load ()
{
if (file.exists (Outscriptpath + scriptfullname))
{
Print (Outscriptpath + scriptfullname);
byte[] _byte = file.readallbytes (Outscriptpath + scriptfullname);
Print (_byte. Length);
Assembly-Assembly.Load (_byte);
Type t = ass.gettype (Scriptspacename + ". Outmanager ");
Print (Scriptspacename + ". Outmanager ");
Print (t);
MethodInfo m = T.getmethod ("Main");
M.invoke (null, NULL);
}
}
}
Unity DLL Hot update