Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
CloseアセットバンドルはTextAssetをスクリプトにTextAssetとしてスクリプトを含めることができますが,その場合実際に実行できるコードになりません。もしアプリケーションで実行できるコードをアセットバンドルに含めたい場合は,アセンブリにプリコンパイルする必要があり,またMono Reflectionクラスとしてロードする必要があります(注意:ReflectionはiOSでは利用できません)。アセンブリを普通のC# IDE(例えば MonoDevelop,Visual Studio)またはMono/.NET コンパイラを使用して任意のテキストエディタで作成することが出来ます。
string url = "http://www.mywebsite.com/mygame/assetbundles/assetbundle1.unity3d";
IEnumerator Start () {
// Start a download of the given URL
WWW www = WWW.LoadFromCacheOrDownload (url, 1);
// Wait for download to complete
yield return www;
// Load and retrieve the AssetBundle
AssetBundle bundle = www.assetBundle;
// Load the TextAsset object
TextAsset txt = bundle.Load("myBinaryAsText", typeof(TextAsset)) as TextAsset;
// Load the assembly and get a type (class) from it
var assembly = System.Reflection.Assembly.Load(txt.bytes);
var type = assembly.GetType("MyClassDerivedFromMonoBehaviour");
// Instantiate a GameObject and add a component with the loaded class
GameObject go = new GameObject();
go.AddComponent(type);
}