Unity 5 在运行时从构建目录加载脚本
Unity 5 loading scripts at runtime from build directory
我想使用 addComponent
将脚本附加到 runtime
处的空 gameObject
。
但是,我不想将脚本直接拖到项目中,我想先构建项目,然后进入构建文件夹并将其拖到那里。
游戏开始后,我想从那里加载它并将其附加到空 gameObject
.
如果我没有误会你的话,是有可能的。
- 使用以下命令从文本文件中读取 C# 代码
System.IO.File.ReadAllText(...)
或 Resources.Load(...) as TextAsset
.
- 使用
CSharpCodeProvider
动态生成dll。
- 将
Component
类型从 dll 加载到 AppDomain。
- 创建一个类型的对象。
- 将其附加到游戏对象。
这里有更多相关信息:
How to load a class from a .cs file
我想使用 addComponent
将脚本附加到 runtime
处的空 gameObject
。
但是,我不想将脚本直接拖到项目中,我想先构建项目,然后进入构建文件夹并将其拖到那里。
游戏开始后,我想从那里加载它并将其附加到空 gameObject
.
如果我没有误会你的话,是有可能的。
- 使用以下命令从文本文件中读取 C# 代码
System.IO.File.ReadAllText(...)
或Resources.Load(...) as TextAsset
. - 使用
CSharpCodeProvider
动态生成dll。 - 将
Component
类型从 dll 加载到 AppDomain。 - 创建一个类型的对象。
- 将其附加到游戏对象。
这里有更多相关信息: How to load a class from a .cs file