在 Unity 中使用 SharpScript

Using SharpScript with Unity

在为我的 Unity 应用程序寻找脚本语言时,我遇到了 SharpScript 和运行良好的示例项目 (https://github.com/ServiceStack/script-unity)。然而,示例项目已有 2 年多的历史,因此语言及其实现从那时起已经走了很长一段路。

所以我已经将所有与 SharpScript 相关的 dll 更新到它们的最新版本以获得最新版本,现在我的项目仍然可以在编辑器中工作,但是当使用 IL2CPP + .Net4.x Unity 设置构建时它停止工作。我一开始遇到的错误是:

NotSupportedException: System.Configuration.ConfigurationManager::get_AppSettings
  at System.Configuration.ConfigurationManager.get_AppSettings () [0x00000] in <00000000000000000000000000000000>:0 
  at ServiceStack.Net45PclExport.RegisterLicenseFromConfig () [0x00000] in <00000000000000000000000000000000>:0 
  at ServiceStack.Text.JsConfig..cctor () [0x00000] in <00000000000000000000000000000000>:0 
  at ServiceStack.DynamicNumber.TryParse (System.String strValue, System.Object& result) [0x00000] in <00000000000000000000000000000000>:0 
  at ServiceStack.Script.Lisp+Reader.AddToken (System.Collections.Generic.List`1[T] tokens, System.String s) [0x00000] in <00000000000000000000000000000000>:0 
  at ServiceStack.Script.Lisp+Reader.ReadToken () [0x00000] in <00000000000000000000000000000000>:0 
  at ServiceStack.Script.Lisp+Reader.Read () [0x00000] in <00000000000000000000000000000000>:0 
  at ServiceStack.Script.Lisp..cctor () [0x00000] in <00000000000000000000000000000000>:0 
  at ServiceStack.Script.ScriptLisp.Configure (ServiceStack.Script.ScriptContext context) [0x00000] in <00000000000000000000000000000000>:0 
  at ServiceStack.Script.ScriptContext.Init () [0x00000] in <00000000000000000000000000000000>:0 
  at ScriptExample.Start () [0x00000] in <00000000000000000000000000000000>:0 
Rethrow as TypeInitializationException: The type initializer for 'ServiceStack.LicenseUtils' threw an exception.
  at ServiceStack.Text.JsConfig..cctor () [0x00000] in <00000000000000000000000000000000>:0 
  at ServiceStack.DynamicNumber.TryParse (System.String strValue, System.Object& result) [0x00000] in <00000000000000000000000000000000>:0 
  at ServiceStack.Script.Lisp+Reader.AddToken (System.Collections.Generic.List`1[T] tokens, System.String s) [0x00000] in <00000000000000000000000000000000>:0 
  at ServiceStack.Script.Lisp+Reader.ReadToken () [0x00000] in <00000000000000000000000000000000>:0 
  at ServiceStack.Script.Lisp+Reader.Read () [0x00000] in <00000000000000000000000000000000>:0 
  at ServiceStack.Script.Lisp..cctor () [0x00000] in <00000000000000000000000000000000>:0 
  at ServiceStack.Script.ScriptLisp.Configure (ServiceStack.Script.ScriptContext context) [0x00000] in <00000000000000000000000000000000>:0 
  at ServiceStack.Script.ScriptContext.Init () [0x00000] in <00000000000000000000000000000000>:0 
  at ScriptExample.Start () [0x00000] in <00000000000000000000000000000000>:0 
Rethrow as TypeInitializationException: The type initializer for 'ServiceStack.Text.JsConfig' threw an exception.
  at ServiceStack.DynamicNumber.TryParse (System.String strValue, System.Object& result) [0x00000] in <00000000000000000000000000000000>:0 
  at ServiceStack.Script.Lisp+Reader.AddToken (System.Collections.Generic.List`1[T] tokens, System.String s) [0x00000] in <00000000000000000000000000000000>:0 
  at ServiceStack.Script.Lisp+Reader.ReadToken () [0x00000] in <00000000000000000000000000000000>:0 
  at ServiceStack.Script.Lisp+Reader.Read () [0x00000] in <00000000000000000000000000000000>:0 
  at ServiceStack.Script.Lisp..cctor () [0x00000] in <00000000000000000000000000000000>:0 
  at ServiceStack.Script.ScriptLisp.Configure (ServiceStack.Script.ScriptContext context) [0x00000] in <00000000000000000000000000000000>:0 
  at ServiceStack.Script.ScriptContext.Init () [0x00000] in <00000000000000000000000000000000>:0 
  at ScriptExample.Start () [0x00000] in <00000000000000000000000000000000>:0 
Rethrow as TypeInitializationException: The type initializer for 'ServiceStack.Script.Lisp' threw an exception.
  at ServiceStack.Script.ScriptLisp.Configure (ServiceStack.Script.ScriptContext context) [0x00000] in <00000000000000000000000000000000>:0 
  at ServiceStack.Script.ScriptContext.Init () [0x00000] in <00000000000000000000000000000000>:0 
  at ScriptExample.Start () [0x00000] in <00000000000000000000000000000000>:0 

我在网上找到的关于这个错误的所有信息都说也许添加 System.Configuration.ConfigurationManager 程序集会修复它,但它在我的情况下不起作用:ConfigurationManager class正在被 IDE 看到,也没有添加

 <assembly fullname="System.Configuration.ConfigurationManager" preserve="all"/>

行进入links.xml有什么影响。

总而言之,我不能在项目中使用 SharpScript,因为这个原因 -- 了解最新的开发是非常重要的一点,但在这里不适用。

我用过的程序集版本如下:

servicestack.common.5.11
servicestack.interfaces.5.11
servicestack.text.5.11
system.buffers.4.5.1
system.configuration.configurationmanager.5.0.0
system.memory.4.5.4
system.numerics.vectors.4.5.0
system.runtime.compilerservices.unsafe.5.0.0
system.threading.tasks.extensions.4.5.4

所以根据我的理解,这里发生的事情是 SharpScript 配置与配置提供程序结合在一起,现在它对 ConfigurationManger 有很强的依赖性,这在某种程度上不可能在现代 Unity 应用程序构建中工作。 similar problems with an AWS SDK 从未找到真正的解决方案。

所以问题是:

如何在 Unity 应用程序构建中使用最新版本的 SharpScript?如果不可能做到,那么 SharpScript 就不能用作 Unity 游戏的脚本语言,这真的很可悲,因为它看起来非常有前途并且很好地放在了它的替代品中。

PS: 我尝试在官方论坛上寻求帮助,但我的帐户没有获得批准。我没有收到任何通知,但据我所知——这是因为我没有商业许可证。我只是在制作游戏,所以除了 SharpScript,我不会使用 ServiceStack 的任何其他东西,据说它的许可证可以免费用于任何商业和闭源应用程序。然而,目前的情况实际上阻止了我或任何制作 Unity 游戏的人这样做。

尝试访问 .NET ConfigurationManager class 时发生此运行时异常,现在正从 this commit.

中捕获

此更改适用于最新的 v5.11.1+,即现在 available on MyGet