1、构建ClassLibrary工程,生成:ABTestImport.dll。将dll放到web项目目录下。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ABTest : MonoBehaviour
{
// Use this for initialization
void Start ()
{
Debug.Log("Run to ABTest.");
}
}
2、将脚本挂到摄像机。
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Reflection;
public class Load : MonoBehaviour
{
// Use this for initialization
IEnumerator Start()
{
yield return StartCoroutine(StartLoad());
LoadScript();
}
Assembly assembly = null;
private IEnumerator StartLoad()
{
//string url = "file://" + Application.streamingAssetsPath + "/ABTestImport.dll";
string url = "http://localhost:8080/examples/servlets/StreamingAssets/ABTestImport.dll";
WWW www = new WWW(url);
yield return www;
if (www.error != null)
{
Debug.Log("www error = " + www.error);
yield return null;
}
else
{
assembly = Assembly.Load(www.bytes);
}
}
private void LoadScript()
{
Debug.Log("LoadScript");
if (assembly != null)
{
Type t = assembly.GetType("ABTest");
GameObject go = new GameObject("ABTest");
go.AddComponent(t);
}
}
}