我正在做一个游戏,玩家执行Python代码来移动角色。我的方法是使用UnityPython,它基本上就是集成在Unity中的IronPython。其工作方式是将播放器输入的代码包装在Python脚本中。然后在另一个线程上运行这个脚本(这是从包装器运行的,使用Python的threading
类),它与Unity通信以移动播放器。这个系统在编辑器上运行良好,但在构建上却不行。你知道吗
首先,我已经指出问题来自脚本引擎使用的搜索路径,没有找到正确的库文件夹(因为UnityPython本身就在assets文件夹中)。我需要的特殊类是threading
和Queue
。你知道吗
引擎初始值设定项如下所示:
var engine = UnityPython.CreateEngine();
var paths = engine.GetSearchPaths();
paths.Add(Application.dataPath + "/Python/Lib");
engine.SetSearchPaths(paths);
我想到的一种解决方法是将Python文件夹复制到StreamingAssets文件夹,然后在第三行使用Application.streamingAssetsPath
。但是dev build调试器给了我一个奇怪的错误:
System.TypeInitializationException: The type initializer for 'CodecsInfo' threw an exception. ---> System.NotSupportedException: Encoding 37 data could not be found. Make sure you have correct international codeset assembly installed and enabled.
这就是我现在所处的困境。你有没有想过这个错误意味着什么以及如何克服它?你知道吗
编辑:当引擎使用脚本时,问题似乎正在发生。这里的代码是这样的:
try
{
var source = engine.CreateScriptSourceFromFile(scriptPath);
source.Compile();
// script here is a dynamic variable
script = engine.Runtime.UseFile(scriptPath); // this is where the error is thrown
script.GameManager = this;
script.start();
}
catch (Exception e)
{
Debug.Log("Error: " + e);
}
这个问题似乎是由于缺少dll而导致的,没有从编辑器中复制到构建中。积分到exodrifter的解决方案(找到here)。你知道吗
简单地说,这些DLL是项目的Plugins文件夹所必需的。你知道吗
它们可以从Unity编辑器的安装位置复制过来。dll位于
Unity\Editor\Data\Mono\lib\mono\2.0
。具体位置取决于安装Unity的位置。在我的例子中,是在C:\Program Files\Unity\Hub\Editor\2018.4.7f1\Editor\Data\Mono\lib\mono\2.0
相关问题 更多 >
编程相关推荐